Skip to content

Commit f63e7c2

Browse files
authored
fix: make secret scanning omitvalue case insensitive (#6719)
1 parent 01a7441 commit f63e7c2

File tree

2 files changed

+40
-1
lines changed
  • packages/build

2 files changed

+40
-1
lines changed

packages/build/src/plugins_core/secrets_scanning/utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,13 @@ export function findLikelySecrets({
206206
while ((match = likelySecretRegex.exec(text)) !== null) {
207207
const token = match.groups?.token
208208
const prefix = match.groups?.prefix
209-
if (!token || !prefix || allOmittedValues.includes(token)) {
209+
if (
210+
!token ||
211+
!prefix ||
212+
allOmittedValues.some(
213+
(omittedValue) => typeof omittedValue === 'string' && omittedValue.toLowerCase() === token.toLowerCase(),
214+
)
215+
) {
210216
continue
211217
}
212218
// Despite the prefix, the string does not look random enough to be convinced it's a secret

packages/build/tests/utils_secretscanning/tests.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,36 @@ test('findLikelySecrets - should match full secret value against omitValues', as
112112
})
113113
t.is(fullMatch.length, 0)
114114
})
115+
116+
test('findLikelySecrets - should match omitValues case-insensitively', async (t) => {
117+
const testCases = [
118+
{
119+
text: 'key="AIzaSyBdVl-cTICSwYKrZ96snp88z"',
120+
omitValue: 'AIzaSyBdVl-cTICSwYKrZ96snp88z',
121+
description: 'exact case match',
122+
},
123+
{
124+
text: 'key="AIzaSyBdVl-cTICSwYKrZ96snp88z"',
125+
omitValue: 'aizaSyBdVl-cTICSwYKrZ96snp88z',
126+
description: 'lowercase prefix in omit value',
127+
},
128+
{
129+
text: 'key="aizaSyBdVl-cTICSwYKrZ96snp88z"',
130+
omitValue: 'AIzaSyBdVl-cTICSwYKrZ96snp88z',
131+
description: 'lowercase prefix in detected secret',
132+
},
133+
{
134+
text: 'key="AIZASYBD-VLTICTCSWYKRZ96SNP88Z"',
135+
omitValue: 'aizasybd-vltictcswykrz96snp88z',
136+
description: 'all uppercase secret with lowercase omit value',
137+
},
138+
]
139+
140+
testCases.forEach(({ text, omitValue, description }) => {
141+
const matches = findLikelySecrets({
142+
text,
143+
omitValuesFromEnhancedScan: [omitValue],
144+
})
145+
t.is(matches.length, 0, `Should omit secret for case: ${description}`)
146+
})
147+
})

0 commit comments

Comments
 (0)