Repository navigation
Description
Description
The aws-access-key-id rule (pkg/fanal/secret/builtin-rules.go) requires, after the key,
an optional quote, then an optional ./,, then a mandatory whitespace or end of
string:
Regex: MustCompileWithoutWordPrefix(fmt.Sprintf(
`(?P<secret>(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16})%s%s`,
quote, endSecret,
)),
// quote = `["']?`, endSecret = `[.,]?(\s+|$)`As a result, the key is missed whenever anything other than whitespace/end-of-line follows
the closing quote. That is not an edge case: a minified JS/TS bundle, a source map's
sourcesContent, and a plain const value = "AKIA..."; statement are the normal output of
any Vite/webpack/esbuild build.
Synthetic reproduction
The key below is not functional, it was generated at random:
AKIAQZXJLKFPWMVBNTYU
| Context | Line | Currently detected? |
|---|---|---|
| Next.js/webpack minified bundle | e.exports={apiKey:"AKIA...",region:"us-east-1"} |
no |
| Vite build output, single statement | const AWS_KEY="AKIA...";export{AWS_KEY}; |
no |
source map sourcesContent (escaped quotes) |
{"sourcesContent":["const k=\"AKIA...\"\n"],...} |
no |
| Compact Terraform plan JSON in a CI log | {"access_key":"AKIA...","secret_key":"x"} |
no |
| Lambda/serverless env block | {"Variables":{"ACCESS_KEY_ID":"AKIA..."}} |
no |
The discussion author's proposal
The author suggests replacing quote+endSecret with \b on both sides of the key:
Regex: MustCompile(`\b(?P<secret>(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16})\b`),This does fix every case above (verified). But \b means "any non-word character," so it
also starts matching things that were deliberately filtered out before: for example, the
signer's key ID in a SigV4 presigned URL / credential scope
(X-Amz-Credential=AKIA.../20261102/us-east-1/s3/aws4_request) is not a leak, it is a
regular part of a public link. The same widening happens on arbitrary punctuation (),
:, ;, |, &, etc.), not only on SigV4.
A direction worth validating (not a finished solution)
Instead of a generic \b, it may be worth narrowing the set of accepted terminators to the
ones the reproduction actually needs, rather than "any non-word character":
// Go raw strings can't contain a backtick, so this needs an interpreted string literal.
Regex: MustCompile("(?P<secret>(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16})(?:[\"'`\\\\.,]|\\s|$)"),That is: an explicit list of quote, apostrophe, backtick and backslash characters (covers
both JS template literals and escaped \" in source maps), plus ,/. as sufficient
terminators on their own (no mandatory \s+ after them, unlike the current endSecret),
plus whitespace/end of string as before.
No leading \b either: the odds of a random run of exactly 16 characters right after one
of these prefixes, immediately preceded by another word character, are low, and even then
the outcome is a false positive, not a missed secret.
On the synthetic reproduction above, and on the SigV4 case, this gives the same result as
the author's \b proposal, except that the SigV4 case simply does not match at all,
with no need for a dedicated allow-rule and no widening onto arbitrary punctuation.
This idea itself needs validation before it is implemented: it needs an explicit answer on
whether this terminator list covers every case that matters (an unquoted value before : in
YAML, or before ) in prose, is still missed, same as with current behavior), and the full
existing pkg/fanal/secret test suite needs to pass, before choosing between this variant
and the author's plain \b proposal.
Before implementation
Please discuss and agree on an approach in this issue before opening a PR.
Activity
[-]secret: aws-access-key-id misses keys in minified JS, source maps and SigV4 URLs[/-][+]bug(secret): aws-access-key-id misses keys in minified JS, source maps and SigV4 URLs[/+]fix(secret): detect AWS access key IDs followed by quotes or commas
nikpivkin commentedon Nov 13, 2026
@DmitriyLewen Thank you for creating this issue. I looked into the problem mentioned in the discussion a few days ago and opened a draft PR at #11602, but I forgot to create an issue.
The SigV4 problem with
\bcan be solved with anExcludeBlockon the rule, and the PR does this. Access key IDs in pre-signed URLs (SigV4 and SigV2) and inAuthorizationheaders are skipped, so they are still not reported.DmitriyLewen commentedon Nov 16, 2026
@nikpivkin thanks for taking care of this!
When I suggested my option, I was worried that we would have to keep adding exclusions to this rule to get rid of false positives.
But after checking everything again, I realized that my option creates false negatives in some cases: for example, when the key is followed by
;,&or<(export AWS_ACCESS_KEY_ID=AKIA...;,?key=AKIA...&,<AccessKeyId>AKIA...</AccessKeyId>).So it doesn't work, and let's go with your approach.