Skip to content

Commit 7862282

Browse files
committed
fix(overlay): mask a quoted secret after a key chain ending in =
In 'Error: context:password="x"' no space follows the '=', so the chain was not read again and the password showed. A chain whose last key is a strong secret name is now read again from that key, unless the chain starts with xmlns:, so namespaced XML attributes stay one name.
1 parent f482bd7 commit 7862282

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@ describe('a value read again as the next key', () => {
7373
'Error: a:b:c:token: hunter2',
7474
'Error: context:password= "hunter2"',
7575
'Error: context:password= hunter2',
76+
'Error: context:password="hunter2"',
7677
`Error: ${'a:'.repeat(5000)}password: hunter2`,
7778
])('finds a secret after a compact chain of key names: %s', (text) => {
7879
expect(redactText(text, [], 'text')).not.toContain('hunter2');
7980
});
8081

8182
it('keeps a namespaced attribute after a key as one name', () => {
8283
expect(redactText('Log: xmlns:auth="urn:a"', [], 'text')).toContain('urn:a');
84+
expect(redactText('Log: xmlns:password="urn:a"', [], 'text')).toContain('urn:a');
8385
});
8486
});

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,16 @@ function replacePairs(text: string, pair: PairReplacer): string {
198198
// value counts only after `: ` with a space, so `xmlns:auth="urn:a"` stays one name.
199199
// For a chain such as `context:password:` only its last key is read again, so a chain
200200
// like `a:a:a:` is skipped in one step and the scan stays linear.
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.
201+
// A chain ending in `=` counts when a space follows (`context:password= "x"`) or when its
202+
// last key is a strong secret name outside an XML namespace (`context:password="x"`), so
203+
// `xmlns:auth="urn:a"` stays one attribute.
204+
const chainKey = value.slice(value.lastIndexOf(':', value.length - 2) + 1, -1);
203205
const chain =
204206
!NEXT_KEY_VALUE.test(value) &&
205207
KEY_CHAIN_VALUE.test(value) &&
206-
(value.endsWith(':') || /\s/.test(text.charAt(at + match.length)));
208+
(value.endsWith(':') ||
209+
/\s/.test(text.charAt(at + match.length)) ||
210+
(!/^xmlns:/i.test(value) && isStrongSecretKey(decode(chainKey))));
207211
const nextKey = chain || (NEXT_KEY_VALUE.test(value) && (value.endsWith(':') || /\s/.test(eq)));
208212
if (replaced === match && value && !/^["']/.test(value) && nextKey) {
209213
const lastKey = chain ? value.lastIndexOf(':', value.length - 2) + 1 : 0;

0 commit comments

Comments
 (0)