File tree Expand file tree Collapse file tree 3 files changed +14
-2
lines changed
src/plugins_core/secrets_scanning
tests/utils_secretscanning Expand file tree Collapse file tree 3 files changed +14
-2
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import { createInterface } from 'node:readline'
55import { fdir } from 'fdir'
66import { 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
1010export 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 ( {
Original file line number Diff line number Diff 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+
9399test ( 'findLikelySecrets - should match secrets with special characters' , async ( t ) => {
94100 const lines = [
95101 'aws_abc123!@#$%^&*()_+' , // Special chars
You can’t perform that action at this time.
0 commit comments