@@ -42,6 +42,30 @@ MIIEpAIBAAKCAQEA7
4242 "See docs/authentication.md for how API keys are issued and rotated. No secrets in this paragraph." ;
4343 expect ( scrubSecretShapedContent ( text ) ) . toBe ( text ) ;
4444 } ) ;
45+
46+ test ( "redacts bare-KEY env assignments (CL-10756)" , ( ) => {
47+ for ( const key of [ "OPENAI_KEY" , "STRIPE_KEY" , "GITHUB_KEY" ] ) {
48+ const text = `./app/.env:7:${ key } =proj-live-value-9z` ;
49+ const out = scrubSecretShapedContent ( text ) ;
50+ expect ( out ) . toContain ( `${ key } =${ CREDENTIAL_REDACTION } ` ) ;
51+ expect ( out ) . not . toContain ( "proj-live-value-9z" ) ;
52+ }
53+ } ) ;
54+
55+ test ( "redacts credential-bearing DATABASE_URL connection strings (CL-10756)" , ( ) => {
56+ const text =
57+ "./app/.env:2:DATABASE_URL=postgres://admin:s3cret-pw@db.internal:5432/appdb" ;
58+ const out = scrubSecretShapedContent ( text ) ;
59+ expect ( out ) . toContain ( `DATABASE_URL=${ CREDENTIAL_REDACTION } ` ) ;
60+ expect ( out ) . not . toContain ( "s3cret-pw" ) ;
61+ } ) ;
62+
63+ test ( "leaves non-secret KEY words and credential-less URLs alone (CL-10756)" , ( ) => {
64+ expect ( scrubSecretShapedContent ( "MONKEY=banana" ) ) . toBe ( "MONKEY=banana" ) ;
65+ expect ( scrubSecretShapedContent ( "DATABASE_URL=sqlite:///local.db" ) ) . toBe (
66+ "DATABASE_URL=sqlite:///local.db" ,
67+ ) ;
68+ } ) ;
4569} ) ;
4670
4771describe ( "scrubSecretShapedValue" , ( ) => {
@@ -219,6 +243,24 @@ describe("toolResultSecretScrubPlugin", () => {
219243 expect ( result . content ) . toContain ( CREDENTIAL_REDACTION ) ;
220244 expect ( result . content ) . not . toContain ( "supersecretvalue" ) ;
221245 } ) ;
246+ test ( "scrubs bare-KEY and DATABASE_URL through the shared middleware path (CL-10756)" , async ( ) => {
247+ const plugin = toolResultSecretScrubPlugin ( ) ;
248+ if ( plugin . middleware === undefined )
249+ throw new Error ( "expected middleware plugin" ) ;
250+ const handler = plugin . middleware (
251+ next (
252+ "secrets/.env:7:OPENAI_KEY=proj-live-value-9z\nsecrets/.env:2:DATABASE_URL=postgres://admin:s3cret-pw@db.internal:5432/appdb" ,
253+ ) ,
254+ ) ;
255+ const result = await handler (
256+ { id : "c2" , name : "read_file" , arguments : { path : "secrets/.env" } } ,
257+ new AbortController ( ) . signal ,
258+ ) ;
259+ expect ( result . content ) . toContain ( `OPENAI_KEY=${ CREDENTIAL_REDACTION } ` ) ;
260+ expect ( result . content ) . toContain ( `DATABASE_URL=${ CREDENTIAL_REDACTION } ` ) ;
261+ expect ( result . content ) . not . toContain ( "proj-live-value-9z" ) ;
262+ expect ( result . content ) . not . toContain ( "s3cret-pw" ) ;
263+ } ) ;
222264 test ( "scrubs error results without stringifying object content" , async ( ) => {
223265 const plugin = toolResultSecretScrubPlugin ( ) ;
224266 if ( plugin . middleware === undefined )
0 commit comments