Skip to content

Commit f482bd7

Browse files
committed
fix(overlay): mask a secret after a key chain that ends in =
In 'Error: context:password= "x"' the chain 'context:password=' was read as the value of 'Error' and not read again, so the password showed. A chain ending in '=' is now read again from its last key when a space follows the '=', so 'xmlns:auth="urn:a"' still stays one attribute.
1 parent 3536e00 commit f482bd7

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎packages/devtools/src/__tests__/redaction-leak-fixes.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,14 @@ describe('a value read again as the next key', () => {
7171
'Error: context:password: "hunter2"',
7272
'Error: context:password: hunter2',
7373
'Error: a:b:c:token: hunter2',
74+
'Error: context:password= "hunter2"',
75+
'Error: context:password= hunter2',
7476
`Error: ${'a:'.repeat(5000)}password: hunter2`,
7577
])('finds a secret after a compact chain of key names: %s', (text) => {
7678
expect(redactText(text, [], 'text')).not.toContain('hunter2');
7779
});
80+
81+
it('keeps a namespaced attribute after a key as one name', () => {
82+
expect(redactText('Log: xmlns:auth="urn:a"', [], 'text')).toContain('urn:a');
83+
});
7884
});

‎packages/devtools/src/text-redact.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,11 @@ type PairReplacer = (
168168
*/
169169
/** A pair value that is one key name and its `:` or `=`, read again as the next pair. */
170170
const NEXT_KEY_VALUE = /^[\w$%.[\]-]+[:=]$/;
171-
/** A pair value that is a chain of key names, each with its `:` (`context:password:`). */
172-
const KEY_CHAIN_VALUE = /^(?:[\w$%.[\]-]+:)+$/;
171+
/**
172+
* A pair value that is a chain of key names (`context:password:`), the last one
173+
* possibly ending in `=` (`context:password=`).
174+
*/
175+
const KEY_CHAIN_VALUE = /^(?:[\w$%.[\]-]+:)+[\w$%.[\]-]*[:=]$/;
173176

174177
function replacePairs(text: string, pair: PairReplacer): string {
175178
const re = new RegExp(TEXT_PAIR.source, TEXT_PAIR.flags);
@@ -195,7 +198,12 @@ function replacePairs(text: string, pair: PairReplacer): string {
195198
// value counts only after `: ` with a space, so `xmlns:auth="urn:a"` stays one name.
196199
// For a chain such as `context:password:` only its last key is read again, so a chain
197200
// like `a:a:a:` is skipped in one step and the scan stays linear.
198-
const chain = !NEXT_KEY_VALUE.test(value) && KEY_CHAIN_VALUE.test(value);
201+
// A chain ending in `=` counts only when a space follows, as in `context:password= "x"`,
202+
// so `xmlns:auth="urn:a"` stays one attribute.
203+
const chain =
204+
!NEXT_KEY_VALUE.test(value) &&
205+
KEY_CHAIN_VALUE.test(value) &&
206+
(value.endsWith(':') || /\s/.test(text.charAt(at + match.length)));
199207
const nextKey = chain || (NEXT_KEY_VALUE.test(value) && (value.endsWith(':') || /\s/.test(eq)));
200208
if (replaced === match && value && !/^["']/.test(value) && nextKey) {
201209
const lastKey = chain ? value.lastIndexOf(':', value.length - 2) + 1 : 0;

0 commit comments

Comments
 (0)