Skip to content

Commit ae2a833

Browse files
koki-developclaude
andcommitted
feat(masker): add support for AWS temporary credentials and secret keys
Add masking patterns for: - AWS Access Key ID issued by STS/SSO (ASIA prefix) - AWS Secret Access Key (40-char base64-like string) The secret key pattern is placed last to avoid matching other secrets. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 45ff6ae commit ae2a833

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

CLAUDE.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,11 @@ When adding new API key patterns to `internal/masker/`:
114114
### Pattern Ordering
115115
- Place more specific patterns before general ones to avoid false matches
116116
- Example: `sk-ant-` must be before `sk-` to prevent Anthropic keys from matching OpenAI pattern
117+
- Example: AWS Secret Access Key (`[a-zA-Z0-9+/]{40}`) must be last due to its generic pattern
117118

118-
### Supported Patterns
119-
- AWS Access Key ID: `AKIA[0-9A-Z]{16}`
119+
### Supported Patterns (in order of application)
120+
- AWS Access Key ID (permanent): `AKIA[0-9A-Z]{16}`
121+
- AWS Access Key ID (temporary/SSO): `ASIA[0-9A-Z]{16}`
120122
- GitHub Tokens: `gh[pousr]_[a-zA-Z0-9]{36,}`
121123
- GitLab PAT: `glpat-[a-zA-Z0-9\-_]{20,}`
122124
- Slack Tokens: `xox[baprs]-[0-9a-zA-Z\-]+`
@@ -125,6 +127,7 @@ When adding new API key patterns to `internal/masker/`:
125127
- Supabase Secret Key: `sb_secret_[a-zA-Z0-9\-_]+`
126128
- JWT Tokens: `eyJ[a-zA-Z0-9_-]*\.eyJ[a-zA-Z0-9_-]*\.[a-zA-Z0-9_-]*`
127129
- Private Key Headers: `-----BEGIN\s+(RSA|DSA|EC|OPENSSH|PGP)\s+PRIVATE\s+KEY-----`
130+
- AWS Secret Access Key: `[a-zA-Z0-9+/]{40}` (must be last due to generic pattern)
128131

129132
### Pattern Update Workflow
130133
1. Add regex pattern to `internal/masker/masker.go`

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ AWS_ACCESS_KEY_ID=********************
109109

110110
Supported patterns:
111111
- AWS Access Key ID
112+
- AWS Secret Access Key
112113
- GitHub Tokens (`ghp_`, `gho_`, `ghs_`, `ghr_`)
113114
- GitLab Personal Access Tokens
114115
- Slack Tokens

internal/masker/masker.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import (
66
)
77

88
var patterns = []*regexp.Regexp{
9-
// AWS Access Key ID
9+
// AWS Access Key ID (permanent)
1010
regexp.MustCompile(`AKIA[0-9A-Z]{16}`),
11+
// AWS Access Key ID (temporary, STS/SSO)
12+
regexp.MustCompile(`ASIA[0-9A-Z]{16}`),
1113
// GitHub Tokens (ghp_, gho_, ghs_, ghr_)
1214
regexp.MustCompile(`gh[pousr]_[a-zA-Z0-9]{36,}`),
1315
// GitLab Personal Access Token
@@ -24,6 +26,8 @@ var patterns = []*regexp.Regexp{
2426
regexp.MustCompile(`eyJ[a-zA-Z0-9_-]*\.eyJ[a-zA-Z0-9_-]*\.[a-zA-Z0-9_-]*`),
2527
// Private Key Headers
2628
regexp.MustCompile(`-----BEGIN\s+(RSA|DSA|EC|OPENSSH|PGP)\s+PRIVATE\s+KEY-----`),
29+
// AWS Secret Access Key (must be last due to generic pattern that could match other secrets)
30+
regexp.MustCompile(`[a-zA-Z0-9+/]{40}`),
2731
}
2832

2933
// Mask replaces sensitive patterns in content with asterisks of the same length

internal/masker/masker_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ func TestMask(t *testing.T) {
1818
input: "aws_access_key_id = AKIAIOSFODNN7EXAMPLE",
1919
want: "aws_access_key_id = " + strings.Repeat("*", 20),
2020
},
21+
{
22+
name: "AWS Access Key (temporary/SSO)",
23+
input: "aws_access_key_id = ASIAISEXAMPLEKEY1234",
24+
want: "aws_access_key_id = " + strings.Repeat("*", 20),
25+
},
26+
{
27+
name: "AWS Secret Access Key",
28+
input: "aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
29+
want: "aws_secret_access_key = " + strings.Repeat("*", 40),
30+
},
2131
{
2232
name: "GitHub Personal Access Token",
2333
input: "token: ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",

0 commit comments

Comments
 (0)