@@ -100,13 +100,6 @@ const OTHER_FRAMED_CREDENTIALS: Array<[RegExp, string]> = [
100100 ) ,
101101 "element" ,
102102 ] ,
103- [
104- new RegExp (
105- `(<[^\\S\\r\\n]*(?:[A-Za-z_][\\w.-]*:)?[A-Za-z_][\\w:.-]*)(?=[^>]*?(?<![\\w:.-])(?:name|key|id)[^\\S]*=[^\\S]*["']?(?:${ CREDENTIAL_HEADER_LABEL } )["']?(?=[\\s/>]))[\\s\\S]*` ,
106- "gi" ,
107- ) ,
108- "element" ,
109- ] ,
110103 // Multipart part: everything from a credential-named part header to the end
111104 // of the input. Part-based, not line-based — a body can span lines and the
112105 // blank line is often missing in a malformed echo.
@@ -136,7 +129,44 @@ const OTHER_FRAMED_CREDENTIALS: Array<[RegExp, string]> = [
136129function maskOtherFramings ( value : string ) : string {
137130 // Same union rule as the header pass: decoding may add coverage, never
138131 // remove it.
139- return maskOtherFramingsOnce ( maskOtherFramingsOnce ( value , true ) , false ) ;
132+ const decoded = maskOtherFramingsOnce ( value , true ) ;
133+ const decodedXml = maskXmlIdentifyingAttribute ( decoded , true ) ;
134+ const plain = maskOtherFramingsOnce ( decodedXml , false ) ;
135+ return maskXmlIdentifyingAttribute ( plain , false ) ;
136+ }
137+
138+ const XML_TAG_NAME = / < [ ^ \S \r \n ] * (?: [ A - Z a - z _ ] [ \w . - ] * : ) ? [ A - Z a - z _ ] [ \w : . - ] * / y;
139+ const XML_CREDENTIAL_ATTRIBUTE = new RegExp (
140+ `(?<![\\w:.-])(?:name|key|id)[^\\S]*=[^\\S]*["']?(?:${ CREDENTIAL_HEADER_LABEL } )["']?(?=[\\s/>])` ,
141+ "i" ,
142+ ) ;
143+
144+ /** Scan each tag once; a suffix-searching lookahead here makes unterminated tags quadratic. */
145+ function maskXmlIdentifyingAttribute ( value : string , decodeEscapes : boolean ) : string {
146+ const { folded, map } = foldForMatching ( value , decodeEscapes ) ;
147+ let searchFrom = 0 ;
148+ while ( searchFrom < folded . length ) {
149+ const relativeStart = folded . indexOf ( "<" , searchFrom ) ;
150+ if ( relativeStart === - 1 ) return value ;
151+ const tagStart = relativeStart ;
152+ XML_TAG_NAME . lastIndex = tagStart ;
153+ const tagName = XML_TAG_NAME . exec ( folded ) ;
154+ if ( ! tagName ) {
155+ searchFrom = tagStart + 1 ;
156+ continue ;
157+ }
158+ const close = folded . indexOf ( ">" , tagStart + tagName [ 0 ] . length ) ;
159+ const tagEnd = close === - 1 ? folded . length : close + 1 ;
160+ const attributes = folded . slice ( tagStart + tagName [ 0 ] . length , tagEnd ) ;
161+ if ( XML_CREDENTIAL_ATTRIBUTE . test ( attributes ) ) {
162+ const start = map [ tagStart ] ?? value . length ;
163+ const headEnd = map [ tagStart + tagName [ 0 ] . length ] ?? value . length ;
164+ return value . slice ( 0 , start ) + value . slice ( start , headEnd ) + REDACTED_SECRET ;
165+ }
166+ if ( close === - 1 ) return value ;
167+ searchFrom = tagEnd ;
168+ }
169+ return value ;
140170}
141171
142172function maskOtherFramingsOnce ( value : string , decodeEscapes : boolean ) : string {
0 commit comments