Skip to content

Commit 4fd7f7c

Browse files
authored
feat: safelist common string in react proptypes from secret detection (#6375)
1 parent 86dead5 commit 4fd7f7c

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ export const LIKELY_SECRET_PREFIXES = [
3434
...SQUARE_PREFIXES,
3535
...OTHER_COMMON_PREFIXES,
3636
]
37+
38+
/**
39+
* Known values that we do not want to trigger secret detection failures (e.g. common to framework build output)
40+
*/
41+
export const SAFE_LISTED_VALUES = ['SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'] // Common to code using React PropTypes

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createInterface } from 'node:readline'
55
import { fdir } from 'fdir'
66
import { minimatch } from 'minimatch'
77

8-
import { LIKELY_SECRET_PREFIXES } from './secret_prefixes.js'
8+
import { LIKELY_SECRET_PREFIXES, SAFE_LISTED_VALUES } from './secret_prefixes.js'
99

1010
export interface ScanResults {
1111
matches: MatchResult[]
@@ -181,11 +181,12 @@ export function findLikelySecrets({
181181

182182
const matches: MatchResult[] = []
183183
let match: RegExpExecArray | null
184+
const allOmittedValues = [...omitValuesFromEnhancedScan, ...SAFE_LISTED_VALUES]
184185

185186
while ((match = likelySecretRegex.exec(line)) !== null) {
186187
const token = match.groups?.token
187188
const prefix = match.groups?.prefix
188-
if (!token || !prefix || omitValuesFromEnhancedScan?.includes(token)) {
189+
if (!token || !prefix || allOmittedValues.includes(token)) {
189190
continue
190191
}
191192
matches.push({

packages/build/tests/utils_secretscanning/tests.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ test('findLikelySecrets - should match different prefixes from LIKELY_SECRET_PRE
9090
})
9191
})
9292

93+
test('findLikelySecrets - should skip safe-listed values', async (t) => {
94+
const line = 'const someString = "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"'
95+
const matches = findLikelySecrets({ line, file: testFile, lineNumber: 1 })
96+
t.is(matches.length, 0)
97+
})
98+
9399
test('findLikelySecrets - should match secrets with special characters', async (t) => {
94100
const lines = [
95101
'aws_abc123!@#$%^&*()_+', // Special chars

0 commit comments

Comments
 (0)