<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Omar Faruque</title>
    <description>The latest articles on DEV Community by Omar Faruque (@nsmomar).</description>
    <link>https://dev.to/nsmomar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4275860%2F48b2e1e2-6efb-4499-b871-3c569819e617.jpg</url>
      <title>DEV Community: Omar Faruque</title>
      <link>https://dev.to/nsmomar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nsmomar"/>
    <language>en</language>
    <item>
      <title>Spotting API keys in a paste, in the browser</title>
      <dc:creator>Omar Faruque</dc:creator>
      <pubDate>Tue, 01 Dec 2026 08:20:34 +0000</pubDate>
      <link>https://dev.to/nsmomar/spotting-api-keys-in-a-paste-in-the-browser-12f6</link>
      <guid>https://dev.to/nsmomar/spotting-api-keys-in-a-paste-in-the-browser-12f6</guid>
      <description>&lt;p&gt;Most of us paste things into online tools while debugging: a JSON response, a &lt;code&gt;.env&lt;/code&gt; file, a curl command copied from the browser, a JWT from a header. Often the paste holds a live credential.&lt;/p&gt;

&lt;p&gt;In November 2025, watchTowr Labs showed where that can end up. Two popular online code formatters listed what people had saved on a public "Recent Links" page, with links that followed a predictable pattern. The researchers stopped after more than 80,000 saved items, with Active Directory and database credentials, cloud keys and private keys among them. They saved fake AWS keys on both sites to see whether anyone was collecting; someone tried to use one 48 hours later.&lt;/p&gt;

&lt;p&gt;So a tool that handles pasted text should at least notice when the text holds a key, and tell you before you copy the result somewhere else. Here is how I built that check for my own tools: it runs in the browser, on every keystroke, and the text is not sent to a server to be checked.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two kinds of key
&lt;/h2&gt;

&lt;p&gt;Credentials come in two shapes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keys with a fixed format.&lt;/strong&gt; Many providers put a prefix on their keys so they can be spotted:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Kind&lt;/th&gt;
&lt;th&gt;Pattern&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;AWS access key id&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;AKIA&lt;/code&gt;, &lt;code&gt;ASIA&lt;/code&gt;, &lt;code&gt;ABIA&lt;/code&gt; or &lt;code&gt;ACCA&lt;/code&gt; + 16 uppercase letters or digits&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GitHub token&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;ghp_&lt;/code&gt;, &lt;code&gt;gho_&lt;/code&gt;, &lt;code&gt;ghu_&lt;/code&gt;, &lt;code&gt;ghs_&lt;/code&gt;, &lt;code&gt;ghr_&lt;/code&gt; + 36 or more characters, or &lt;code&gt;github_pat_&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GitLab token&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;glpat-&lt;/code&gt; + 20 or more characters&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Stripe key&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;sk_live_&lt;/code&gt;, &lt;code&gt;sk_test_&lt;/code&gt;, &lt;code&gt;rk_live_&lt;/code&gt;, &lt;code&gt;rk_test_&lt;/code&gt;, or a &lt;code&gt;whsec_&lt;/code&gt; webhook secret&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Google API key&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;AIza&lt;/code&gt; + 35 characters&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;npm token&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;npm_&lt;/code&gt; + 36 characters&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SendGrid key&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;SG.&lt;/code&gt; + 22 characters + &lt;code&gt;.&lt;/code&gt; + 43 characters&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JWT&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;eyJ…&lt;/code&gt; &lt;code&gt;.eyJ…&lt;/code&gt; &lt;code&gt;.…&lt;/code&gt;: three base64url parts, the first two being JSON&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PEM private key&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;-----BEGIN … PRIVATE KEY-----&lt;/code&gt; to the matching &lt;code&gt;END&lt;/code&gt; line&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Keys with no format.&lt;/strong&gt; An AWS secret access key is 40 random characters. A database password is anything. These you can only find by what surrounds them: the name of the field (&lt;code&gt;"db_password": "…"&lt;/code&gt;, &lt;code&gt;SECRET_KEY_BASE=…&lt;/code&gt;), the URL they sit in (&lt;code&gt;postgres://user:hunter22@db&lt;/code&gt;), or the header (&lt;code&gt;Authorization: Bearer …&lt;/code&gt;, &lt;code&gt;X-Api-Key: …&lt;/code&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  The rules are regexes, with care
&lt;/h2&gt;

&lt;p&gt;The fixed formats are plain regexes. The AWS access key id rule:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="nf"&gt;b&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt;&lt;span class="no"&gt;AKIA&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="no"&gt;ASIA&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="no"&gt;ABIA&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="no"&gt;ACCA&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9A&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Z&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;\&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The catch is speed. The check runs on the main thread as you type, on inputs that can be megabytes, so no rule may backtrack. Two examples of what went wrong first:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-----BEGIN[\s\S]*?END&lt;/code&gt; looks fine, but on a cut-off paste with no &lt;code&gt;END&lt;/code&gt; it scans to the end of the text from every &lt;code&gt;BEGIN&lt;/code&gt;. That is quadratic: 20,000 &lt;code&gt;BEGIN&lt;/code&gt; lines took 1.6 s. Now the code finds each &lt;code&gt;BEGIN&lt;/code&gt;, then searches for the next &lt;code&gt;END&lt;/code&gt; from there, and stops when there is none.&lt;/li&gt;
&lt;li&gt;A pattern like &lt;code&gt;[A-Z_]*PASSWORD[A-Z_]*&lt;/code&gt; to find &lt;code&gt;.env&lt;/code&gt; names backtracks badly on a long run of letters: 53 s on a 1 MB line. Now the regex only takes the name as one token, and plain code decides whether the name means "secret".&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Deciding whether a name means "secret"
&lt;/h2&gt;

&lt;p&gt;For &lt;code&gt;.env&lt;/code&gt; files, JSON and YAML, the name decides. The check splits it into words (&lt;code&gt;smtpPassword&lt;/code&gt; → &lt;code&gt;smtp password&lt;/code&gt;, &lt;code&gt;SECRET_KEY_BASE&lt;/code&gt; → &lt;code&gt;secret key base&lt;/code&gt;) and looks for words like &lt;code&gt;password&lt;/code&gt;, &lt;code&gt;secret&lt;/code&gt;, &lt;code&gt;passphrase&lt;/code&gt;, &lt;code&gt;apikey&lt;/code&gt;, or pairs like &lt;code&gt;api key&lt;/code&gt;, &lt;code&gt;access token&lt;/code&gt;, &lt;code&gt;client secret&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But the last word can turn it into a setting about a secret: &lt;code&gt;TOKEN_EXPIRY&lt;/code&gt;, &lt;code&gt;passwordHint&lt;/code&gt;, &lt;code&gt;JWT_SECRET_FILE&lt;/code&gt;, &lt;code&gt;password_min_length&lt;/code&gt;. If the last word is one of those (&lt;code&gt;expiry&lt;/code&gt;, &lt;code&gt;hint&lt;/code&gt;, &lt;code&gt;file&lt;/code&gt;, &lt;code&gt;length&lt;/code&gt;, &lt;code&gt;url&lt;/code&gt;, &lt;code&gt;name&lt;/code&gt;…), it is not a secret.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deciding whether a value is real
&lt;/h2&gt;

&lt;p&gt;A field named &lt;code&gt;password&lt;/code&gt; with the value &lt;code&gt;changeme&lt;/code&gt; is not a leak. The check skips placeholders: &lt;code&gt;***&lt;/code&gt;, &lt;code&gt;xxx&lt;/code&gt;, &lt;code&gt;...&lt;/code&gt;, &lt;code&gt;&amp;lt;token&amp;gt;&lt;/code&gt;, &lt;code&gt;${DB_PASS}&lt;/code&gt;, &lt;code&gt;{{ secret }}&lt;/code&gt;, &lt;code&gt;changeme&lt;/code&gt;, &lt;code&gt;your_api_key&lt;/code&gt;, &lt;code&gt;example&lt;/code&gt;, &lt;code&gt;redacted&lt;/code&gt;, &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Where a value could just be a word, it must look random: a digit, or both lower and upper case. Code is skipped too: &lt;code&gt;password = req.body.password&lt;/code&gt; and &lt;code&gt;SECRET = os.environ["SECRET"]&lt;/code&gt; name where a secret comes from, they don't hold one.&lt;/p&gt;

&lt;p&gt;One more look for one format: &lt;code&gt;Authorization: Basic dXNlcjpwYXNz&lt;/code&gt; is base64 for &lt;code&gt;user:pass&lt;/code&gt;, so the check decodes it and looks for the colon.&lt;/p&gt;

&lt;h2&gt;
  
  
  Redact without breaking the text
&lt;/h2&gt;

&lt;p&gt;Every match keeps its exact start and end (the regex &lt;code&gt;d&lt;/code&gt; flag gives each capture group's position), sorted and with no overlaps: when two rules match the same text, the earlier, more specific rule wins. Redact then rebuilds the text from the pieces between matches, with &lt;code&gt;[REDACTED]&lt;/code&gt; in place of each key. Everything else stays byte for byte the same, so the JSON still parses and the YAML keeps its indentation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s1"&gt;'[REDACTED]'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;last&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Where it runs
&lt;/h2&gt;

&lt;p&gt;The scanner is plain TypeScript with no dependencies, so the same code runs on the page and in a Web Worker. While you type, the page scans up to the first 2,000,000 characters on the main thread, which is why no rule may backtrack. A big file goes to the worker, and Redact scans everything. When the input holds a key, it is also left out of the tool's Recent work list: that list keeps only its name and time.&lt;/p&gt;

&lt;h2&gt;
  
  
  What still leaves the browser
&lt;/h2&gt;

&lt;p&gt;Running the tools in the tab doesn't mean the page sends nothing, so here is the full list for my site:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a usage counter: the tool's name, what happened (start, run, download or error) and how many items, not the text;&lt;/li&gt;
&lt;li&gt;error reports with fixed fields: the kind of error, where in the code, the page and the browser's name;&lt;/li&gt;
&lt;li&gt;Google Analytics page addresses and tool events with the input size in one of four bands, after consent in Europe (elsewhere it runs unless you press Decline, and Global Privacy Control turns it off);&lt;/li&gt;
&lt;li&gt;if you sign in and sync: your saved items, each locked with AES-GCM in the browser first, with a key made there. The server keeps the locked bytes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Check it yourself
&lt;/h2&gt;

&lt;p&gt;You don't have to take any site's word for this, mine included:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open your browser's developer tools and go to the &lt;strong&gt;Network&lt;/strong&gt; tab.&lt;/li&gt;
&lt;li&gt;Paste a fake key (AWS publishes &lt;code&gt;AKIAIOSFODNN7EXAMPLE&lt;/code&gt; for exactly this) and run the tool.&lt;/li&gt;
&lt;li&gt;Look at every request that has a body (filter by Fetch/XHR, open &lt;strong&gt;Payload&lt;/strong&gt;). If your text or the key shows up in one, it left your device.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Do the same with any formatter you use. A &lt;strong&gt;Save&lt;/strong&gt; or &lt;strong&gt;Share&lt;/strong&gt; button, or a public "recent" list, means your text is kept on a server.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it can't do
&lt;/h2&gt;

&lt;p&gt;It knows the formats it lists. A key in another format, or a password in a field called &lt;code&gt;x&lt;/code&gt;, passes unmarked. So a text with no warning can still hold a secret; the warning is a help, not a guarantee. The safest paste is still one where you replaced the key with a placeholder first: the structure is usually all the tool needs.&lt;/p&gt;

&lt;p&gt;If you already pasted a key into a site that saves: revoke or rotate it where it was issued, check that service's access logs, and delete the saved item if you can.&lt;/p&gt;




&lt;p&gt;I built this check into &lt;a href="https://sealpaste.com/is-it-safe-to-paste?utm_source=devto&amp;amp;utm_medium=post&amp;amp;utm_campaign=sealpaste-launch" rel="noopener noreferrer"&gt;Sealpaste&lt;/a&gt;, my set of 80 developer tools that run in the browser; that page lists the 16 kinds Sealpaste looks for. Which formats would you add?&lt;/p&gt;

&lt;p&gt;Sources: watchTowr Labs, "Stop Putting Your Passwords Into Random Websites", 25 November 2025; Help Net Security, "Popular code formatting sites are exposing credentials and other secrets", 25 November 2025.&lt;/p&gt;

</description>
      <category>security</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>devtools</category>
    </item>
  </channel>
</rss>
