Skip to content

Commit eb26d30

Browse files
committed
fix(router): replace known secrets before masking emails in URLs
An address could swallow the start of a known secret, such as a secret route param, so the secret no longer matched and its end stayed readable. Email masking now runs last in url mode. The docs also say an address inside an encoded nested URL is masked with its host.
1 parent 0a4c32b commit eb26d30

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎apps/docs/src/content/security.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ The URL user stays visible, so you can tell which account a call uses. Ordinary
293293

294294
An email address in a URL is replaced with `[email]`, in a path segment, a query value, a matrix param or the fragment, also when its `@` is encoded as `%40`. So `/invite/[email protected]?to=bob%40example.org` shows as `/invite/[email]?to=[email]`. This holds for every URL that is redacted like router URLs: router navigations and link targets, SSR & HTTP request and page URLs, TransferState request URLs, the NgRx page URL, `httpResource` request URLs, Capacitor and Analog URLs, and the URLs agent tools answer with.
295295

296-
An `@` that isn't part of an address stays, as in `/@angular/core`, `[email protected]` or `/users/@alice`. The user in a URL's authority, such as `git` in `ssh://[email protected]`, stays visible like the user before a URL password. The router lint (`lint-routes` and the [Lint](./inspectors/router.md#lint) view) still reports the `email-in-url` rule for a navigation whose address was masked.
296+
An `@` that isn't part of an address stays, as in `/@angular/core`, `[email protected]` or `/users/@alice`. The user in a URL's authority, such as `git` in `ssh://[email protected]`, stays visible like the user before a URL password. Inside an encoded URL in a query value (`?next=https%3A%2F%2Fbob%40example.com`) there is no authority to tell apart, so the address is masked, host included. The router lint (`lint-routes` and the [Lint](./inspectors/router.md#lint) view) still reports the `email-in-url` rule for a navigation whose address was masked.
297297

298298
### Router
299299

‎packages/devtools/src/__tests__/url-email-redaction.test.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { applyRouterEvent, redactUrl, type NavigationRecord } from '../router.ts
77
import { explainNavigationText, type RouterPage } from '../rpc/router-tools.ts';
88
import { listHttpCallsText } from '../rpc/http-tools.ts';
99
import { lintRoutes } from '../rpc/router-config-tools.ts';
10-
import { maskEmails } from '../text-redact.ts';
10+
import { maskEmails, redactText } from '../text-redact.ts';
1111

1212
describe('emails in URLs', () => {
1313
it('masks an address in a path segment, a query value and a fragment', () => {
@@ -60,6 +60,13 @@ describe('emails in URLs', () => {
6060
);
6161
});
6262

63+
it('hides a known secret whole when an address overlaps its start', () => {
64+
const out = redactText('/files/[email protected]/raw', ['bob.comXYZ123'], 'url');
65+
expect(out).not.toContain('XYZ');
66+
expect(out).not.toContain('123');
67+
expect(out).toContain('[redacted]');
68+
});
69+
6370
it('stays fast on long text with many @ and %40 signs', () => {
6471
const nasty = [
6572
'a%40'.repeat(50_000),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ export function redactText(
219219
});
220220
out = redactJwt(out).replace(BEARER, `Bearer ${REDACTED}`);
221221
out = out.replace(LONG_TOKEN, (token) => (isOpaqueToken(token) ? REDACTED : token));
222-
out = maskEmails(out);
223222
} else {
224223
// Bearer tokens and JWTs first, so `token: Bearer abc` can't keep `abc` once `Bearer` is hidden.
225224
out = redactJwt(out).replace(BEARER, `Bearer ${REDACTED}`);
@@ -266,5 +265,6 @@ export function redactText(
266265
out = out.split(form).join(REDACTED);
267266
}
268267
}
269-
return out;
268+
// After the known secrets, so an address can't swallow the start of one and leave the rest readable.
269+
return mode === 'url' ? maskEmails(out) : out;
270270
}

0 commit comments

Comments
 (0)