@@ -9,6 +9,7 @@ import { copyFileSync, existsSync, linkSync, mkdirSync, mkdtempSync, readFileSyn
99import { registerHooks } from "node:module" ;
1010import { tmpdir } from "node:os" ;
1111import { dirname , join , resolve } from "node:path" ;
12+ import { performance } from "node:perf_hooks" ;
1213import test from "node:test" ;
1314import { pathToFileURL } from "node:url" ;
1415
@@ -74,6 +75,37 @@ test("uses installed absolute executable and preserves scan arguments without ou
7475 assert . equal ( ctx . calls [ 0 ] . options . cwd , ctx . workspace ) ;
7576} ) ;
7677
78+ test ( "redacts long scanner output without retrying every word character" , { timeout : 5000 } , async ( t ) => {
79+ const ctx = await setup ( t , ( ) => ( {
80+ code : 0 ,
81+ stdout : "A" . repeat ( 100_000 ) ,
82+ stderr : "B" . repeat ( 100_000 ) ,
83+ } ) ) ;
84+ const started = performance . now ( ) ;
85+ const result = await ctx . scan ( ) ;
86+ const elapsed = performance . now ( ) - started ;
87+ assert . ok ( elapsed < 1000 , `redaction took ${ elapsed . toFixed ( 1 ) } ms` ) ;
88+ assert . equal ( result . details . stdoutTruncated , true ) ;
89+ assert . equal ( result . details . stderrTruncated , true ) ;
90+ assert . ok ( result . content [ 0 ] . text . length < 19_000 ) ;
91+ } ) ;
92+
93+ test ( "redacts complete secrets before truncating at display boundaries" , async ( t ) => {
94+ const ctx = await setup ( t , ( ) => ( {
95+ code : 0 ,
96+ stdout : " " . repeat ( 11_990 ) + "sk-" + "x" . repeat ( 32 ) ,
97+ stderr : "NPM_TOKEN=synthetic-token\nCUSTOM_API_KEY: synthetic-key\napi_key=lower-key" ,
98+ } ) ) ;
99+ const result = await ctx . scan ( ) ;
100+ const text = result . content [ 0 ] . text ;
101+ for ( const secret of [ "sk-" , "synthetic-token" , "synthetic-key" , "lower-key" ] ) {
102+ assert . equal ( text . includes ( secret ) , false ) ;
103+ }
104+ assert . match ( text , / N P M _ T O K E N = \[ R E D A C T E D \] / ) ;
105+ assert . match ( text , / C U S T O M _ A P I _ K E Y : \[ R E D A C T E D \] / ) ;
106+ assert . match ( text , / a p i _ k e y = \[ R E D A C T E D \] / ) ;
107+ } ) ;
108+
77109test ( "finds the Windows virtualenv executable without a PATH fallback" , async ( t ) => {
78110 const ctx = await setup ( t ) ;
79111 rmSync ( ctx . bin ) ;
0 commit comments