@@ -1190,4 +1190,40 @@ describe("redaction", () => {
11901190 expect . stringContaining ( kept ) ,
11911191 ) ;
11921192 } ) ;
1193+
1194+ it ( "does not let a key header take the place of a form field in the text of a miss" , async ( ) => {
1195+ // A run with the token redacts the text of a miss in its own process.
1196+ // The key header ends with a field that holds `<<redacted>>`, and the
1197+ // pattern takes the `&` before the password away.
1198+ const rules = [ { ...rule ( ) , values : { v : "x&" } , keyHeaders : [ "x-trace" ] } ] ;
1199+ const form = { "content-type" : "application/x-www-form-urlencoded" } ;
1200+ const recorded = await start ( "auto" , rules ) ;
1201+ await send ( recorded , "/v1/fields" , `note=y&password=${ HIDDEN } ` , {
1202+ ...form ,
1203+ "x-trace" : "b" ,
1204+ } ) ;
1205+ const [ sample ] = [ ...( await stored ( "_requests/api" ) ) . values ( ) ] ;
1206+ expect ( JSON . parse ( sample ! ) ) . not . toHaveProperty ( "withheld" ) ;
1207+ const replay = await start ( "replay" , rules ) ;
1208+ const missed = await send (
1209+ replay ,
1210+ "/v1/fields" ,
1211+ `note=x&password=${ HIDDEN } ` ,
1212+ {
1213+ ...form ,
1214+ "x-trace" : "a&password=<<redacted>>" ,
1215+ } ,
1216+ ) ;
1217+ expect ( missed . source ) . toBe ( "missed" ) ;
1218+ // The text of the miss shows the password, so it has no change, and
1219+ // the span gets no `miss.request`.
1220+ const { misses } = await replay . stats ( ) ;
1221+ expect ( misses ) . toHaveLength ( 1 ) ;
1222+ expect ( misses [ 0 ] ! . change ) . toBeUndefined ( ) ;
1223+ for ( const dir of [ "api" , "_requests/api" ] ) {
1224+ const files = [ ...( await stored ( dir ) ) . values ( ) ] ;
1225+ expect ( files . length ) . toBeGreaterThan ( 0 ) ;
1226+ expect ( files . join ( "" ) ) . not . toContain ( "SECRET" ) ;
1227+ }
1228+ } ) ;
11931229} ) ;
0 commit comments