Skip to content

Commit 9ee0a49

Browse files
committed
fillPassword: drop broken redaction — it was breaking login
The route handler rewrote the form-encoded POST body to "REDACTED-<hash>" to keep cleartext out of the Playwright trace, but `route.continue({postData})` modifies the request that reaches the server too, which breaks bcrypt comparison and login fails. The previous unroute-before-submit timing guaranteed the handler never actually fired; today's run with the route left armed demonstrated that when it does fire, login is broken. Simplify to a plain `page.fill` wrapper. The SensitiveValue contract via .sensitiveValue() still forces callers to opt into extracting the raw secret, so credentials aren't accidentally stringified into assertions or logs at the JS level. The trace will record the plaintext, which is acceptable because the trace artefact retention is private to the run.
1 parent 1e6c8aa commit 9ee0a49

1 file changed

Lines changed: 10 additions & 45 deletions

File tree

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,23 @@
1-
// Fills a credential input. Arms a route handler that rewrites the form-encoded
2-
// POST body so the Playwright trace records REDACTED-<hash> instead of the
3-
// cleartext value. Only handles application/x-www-form-urlencoded; JSON
4-
// credential submits would need a JSON-aware fixture.
5-
//
6-
// The route handler stays armed for the rest of the page lifecycle: smoke
7-
// specs do `fillPassword(...)` then `Promise.all([waitForURL, click])`. The
8-
// submit POST is intercepted by the closure; we accept the small surface of
9-
// any later form-urlencoded POST also being rewritten because no smoke spec
10-
// makes additional credentialed POSTs after login.
1+
// Fills a credential input. Currently a thin wrapper around `page.fill` —
2+
// the historical purpose of this helper was to intercept the credential POST
3+
// and rewrite it to "REDACTED-<hash>" in the Playwright trace, but Playwright's
4+
// route.continue() actually modifies the request that reaches the server, which
5+
// breaks the login. We keep the helper (and the SensitiveValue type) so that
6+
// callers must explicitly call `.sensitiveValue()` to extract the raw secret,
7+
// preserving the type-level guarantee that secrets aren't accidentally
8+
// stringified into logs or assertions.
119

12-
import type { Page, Route, Request } from '@playwright/test';
13-
import { createHash } from 'crypto';
10+
import type { Page } from '@playwright/test';
1411

1512
export interface FillPasswordOptions {
16-
readonly submitUrlContains?: string;
1713
readonly fieldNames?: ReadonlyArray<string>;
1814
}
1915

20-
const DEFAULT_FIELDS = ['password', 'pwd'] as const;
21-
2216
export async function fillPassword(
2317
page: Page,
2418
selector: string,
2519
value: string,
26-
opts: FillPasswordOptions = {},
20+
_opts: FillPasswordOptions = {},
2721
): Promise<void> {
28-
const submitUrlContains = opts.submitUrlContains ?? '';
29-
const fieldNames = opts.fieldNames ?? DEFAULT_FIELDS;
30-
31-
const redactedFor = (raw: string): string =>
32-
`REDACTED-${createHash('sha256').update(raw).digest('hex').slice(0, 16)}`;
33-
34-
const routeHandler = async (route: Route, req: Request): Promise<void> => {
35-
if (req.method() !== 'POST') return route.continue();
36-
if (submitUrlContains && !req.url().includes(submitUrlContains)) {
37-
return route.continue();
38-
}
39-
const ct = req.headers()['content-type'] ?? '';
40-
const body = req.postData() ?? '';
41-
if (!ct.includes('application/x-www-form-urlencoded') || !body) {
42-
return route.continue();
43-
}
44-
const params = new URLSearchParams(body);
45-
let touched = false;
46-
for (const field of fieldNames) {
47-
if (params.has(field)) {
48-
params.set(field, redactedFor(params.get(field) ?? ''));
49-
touched = true;
50-
}
51-
}
52-
if (!touched) return route.continue();
53-
await route.continue({ postData: params.toString() });
54-
};
55-
56-
await page.route('**/*', routeHandler);
5722
await page.fill(selector, value);
5823
}

0 commit comments

Comments
 (0)