@@ -234,21 +234,30 @@ describe("MEDIUM demoted credential-shaped patterns (TENSION-1)", () => {
234234 expect ( ids ( `authToken: ${ v } ` ) ) . toContain ( "env.kv" ) ; // (iv) credential camel
235235 expect ( ids ( `clientSecret: ${ v } ` ) ) . toContain ( "env.kv" ) ; // (iv) credential camel
236236 } ) ;
237- // #3048 — a TypeScript type or JSX expression names code, not a literal;
238- // credential literals in the same shapes must still fire.
239- test ( "env.kv skips TypeScript types and JSX expressions, keeps literals in those shapes (#3048)" , ( ) => {
237+ // #3048 — in a TS/JSX file an unquoted value after `:` is a type or an
238+ // expression, and a JSX brace of names is an expression. Decided by file
239+ // context: the same shapes in .env/YAML (or with no path) are literals.
240+ test ( "env.kv skips TS/JSX source syntax by file context, never by value shape (#3048)" , ( ) => {
241+ const kv = ( text : string , sourcePath ?: string ) =>
242+ scan ( text , { repoVisibility : "private" , ...( sourcePath ? { sourcePath } : { } ) } ) . findings . some ( ( f ) => f . id === "env.kv" ) ;
240243 const v = "8Fk2pQ9vXz4wL7mN3rT6yB1cD5eG0hJ" ;
241- for ( const code of [
242- "export async function issueServerCoachItem(\n db: Pool,\n session: SessionState,\n item: IssuedCoachItem,\n): Promise<void> {}" ,
243- "interface Props {\n session: SessionState;\n}" ,
244- "key={turn.requestId + turn.role + index}" ,
245- "apiKey={settings.apiKey}" ,
246- ] ) expect ( { code, ids : ids ( code ) } ) . toEqual ( { code, ids : ids ( code ) . filter ( id => id !== "env.kv" ) } ) ;
247- for ( const literal of [
248- `session: ${ v } ,` , `session: "${ v } ",` , `key={${ v } }` , `API_KEY={${ v } }` ,
249- `key={settings.apiKey + "${ v } "}` , `key="${ v } "` , `api_key: ${ v } ` ,
250- "token: QxZpLmNvTrKbWdHgJcFs," , "token: QxZpLmNvTrKbWdHgJcFs" ,
251- ] ) expect ( { literal, kv : ids ( literal ) . includes ( "env.kv" ) } ) . toEqual ( { literal, kv : true } ) ;
244+ const signature = "export async function issueServerCoachItem(\n db: Pool,\n session: SessionState,\n item: IssuedCoachItem,\n): Promise<void> {}" ;
245+ for ( const [ code , file ] of [
246+ [ signature , "src/coach.ts" ] ,
247+ [ "interface Props {\n session: SessionState;\n}" , "src/props.ts" ] ,
248+ [ "key={turn.requestId + turn.role + index}" , "src/Turn.tsx" ] ,
249+ [ "apiKey={settings.apiKey}" , "src/Settings.jsx" ] ,
250+ ] as const ) expect ( { code, kv : kv ( code , file ) } ) . toEqual ( { code, kv : false } ) ;
251+ for ( const [ literal , file ] of [
252+ [ "API_KEY=VelvetRiverOrbitSunset;" , ".env" ] ,
253+ [ "password: {RiverStoneAmberCedar}" , "config/app.yml" ] ,
254+ [ signature , undefined ] ,
255+ [ " session: SessionState," , "deploy/values.yaml" ] ,
256+ [ `session: "${ v } ",` , "src/a.ts" ] , [ `key={${ v } }` , "src/A.tsx" ] , [ `API_KEY={${ v } }` , "src/A.tsx" ] ,
257+ [ `key={settings.apiKey + "${ v } "}` , "src/A.tsx" ] , [ `key="${ v } "` , "src/A.tsx" ] , [ `api_key: ${ v } ` , ".env" ] ,
258+ ] as const ) expect ( { literal, file, kv : kv ( literal , file ) } ) . toEqual ( { literal, file, kv : true } ) ;
259+ const jwt = [ "eyJhbGciOiJIUzI1NiJ9" , "eyJzdWIiOiIxMjM0NTY3ODkwIn0" , "dozjgNryP4J3jVmNHl0w5N_XgL0n3I9PlFUP0THsR8U" ] . join ( "." ) ;
260+ expect ( scan ( `token: ${ jwt } ,` , { repoVisibility : "private" , sourcePath : "src/auth.ts" } ) . findings . map ( ( f ) => f . id ) ) . toContain ( "jwt" ) ;
252261 } ) ;
253262 // #2912 — a line that READS a secret from the environment holds no secret;
254263 // it must not fire (and so must not be masked or withhold a /cso source file).
@@ -683,3 +692,22 @@ describe("taxonomy integrity", () => {
683692 }
684693 } ) ;
685694} ) ;
695+
696+ describe ( "#3048: gstack-redact --from-file passes the file's path as scan context" , ( ) => {
697+ test ( "the same line is source syntax in a .ts file and a literal in YAML" , ( ) => {
698+ const fs = require ( "node:fs" ) as typeof import ( "node:fs" ) ;
699+ const os = require ( "node:os" ) as typeof import ( "node:os" ) ;
700+ const path = require ( "node:path" ) as typeof import ( "node:path" ) ;
701+ const { spawnSync } = require ( "node:child_process" ) as typeof import ( "node:child_process" ) ;
702+ const dir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "redact-from-file-" ) ) ;
703+ try {
704+ const kv = ( name : string ) => {
705+ fs . writeFileSync ( path . join ( dir , name ) , " session: SessionState,\n" ) ;
706+ const r = spawnSync ( "bun" , [ path . join ( import . meta. dir , ".." , "bin" , "gstack-redact" ) , "--from-file" , path . join ( dir , name ) , "--json" ] , { encoding : "utf8" , timeout : 30_000 } ) ;
707+ return ( JSON . parse ( r . stdout ) . findings as Array < { id : string } > ) . some ( ( f ) => f . id === "env.kv" ) ;
708+ } ;
709+ expect ( kv ( "coach.ts" ) ) . toBe ( false ) ;
710+ expect ( kv ( "values.yaml" ) ) . toBe ( true ) ;
711+ } finally { fs . rmSync ( dir , { recursive : true , force : true } ) ; }
712+ } ) ;
713+ } ) ;
0 commit comments