playwright-security-scan 0.0.0-stage → 0.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,36 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file. The format is based on
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and this project adheres to
5
+ [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0-beta.0] - 2026-11-25
10
+
11
+ First test release, published under the `next` dist-tag (`npm i -D playwright-security-scan@next`).
12
+
13
+ ### Fixed
14
+
15
+ - Google Analytics, consent and CDN cookies (e.g. `_ga_*`, `cf_clearance`) are no longer taken for session cookies; the session heuristic is configurable with `nonSessionNames`.
16
+ - `data.password-in-response` no longer reports labels such as `"password": "Password"` in translation files; the value must look like a password or a hash.
17
+ - `--reporter` on the command line removed the package reporter, so a scan could not fail; it now stops with `RUN_REPORTER_FLAG` and the flag to use.
18
+ - Responses whose body the page never read (e.g. `fetch` without `.json()`) were lost when the test ended before the body arrived; the collector now waits for them.
19
+
20
+ ### Added
21
+
22
+ - Documentation: README (set-up, modes, baseline, configuration, rules table, reports, CI examples for GitHub Actions, GitLab and Azure DevOps, limits), one page per rule in `docs/rules/` and `docs/troubleshooting.md` with every code.
23
+ - HTML report (`reports/pw-sec/report.html`): one offline file with the outcome, filters (classification, severity, confidence, rule group, origin, test), grouping by rule, origin or endpoint, finding details with evidence, tests, why/fix/false positives and a ready baseline entry, the coverage of the run and the box "What this scan does not cover".
24
+ - SARIF 2.1.0 (`reports/pw-sec/results.sarif`) for GitHub code scanning and other security dashboards: every rule with help, CWE/OWASP tags and `security-severity`, findings located at the test that first saw them, stable fingerprints. JUnit XML (`reports/pw-sec/junit.xml`, `report.junitPath`) for GitLab, Azure DevOps, Jenkins and other CI: one suite per rule group, blocking findings as failures, baseline entries as skipped.
25
+ - The reporter: a start banner (mode, scope, rules, gate, baseline), findings deduplicated across the run and classified against `security-baseline.json` (new, accepted, wontfix, false-positive, expired; resolved and not covered entries), a summary of at most 30 lines, `reports/pw-sec/report.json` and `reports/pw-sec/outcome.json`, and the exit code: new findings above the gate (1), expired entries (2), tool errors (3) or no traffic in scope (4) fail the run. `PW_SEC_MODE=baseline` writes the baseline (sorted, notes and dates kept, resolved entries pruned except in filtered runs) and prints the diff.
26
+ - Rules for tokens and data (`data.*`: tokens in URLs, unsigned, endless, long-lived JWTs and JWTs with sensitive claims, passwords and hashes in responses), information disclosure (`disclosure.*`: stack traces, SQL errors, server versions, debug pages, private IP addresses, directory listings, source maps, server errors) and the browser (`browser.csp-violation`, `asset.sri-missing`, `browser.open-redirect-candidate`, `browser.reflected-param`). The catalog now has all 44 rules of the `recommended` preset (46 in `strict`).
27
+ - Rules for security headers (`header.*`: CSP missing/unsafe/incomplete/report-only, clickjacking, HSTS missing/weak, nosniff, Referrer-Policy, Content-Type; Permissions-Policy and COOP in the `strict` preset), cookies (`cookie.*`: Secure, HttpOnly, SameSite, long-lived sessions), CORS (`cors.*`) and transport (`transport.*`: cleartext, mixed content, forms over HTTP, outdated TLS). Each rule documents why it matters, how to fix it (nginx, Express, Spring) and known false positives.
28
+ - API tests are scanned too: calls of the `request` fixture, `page.request`, `context.request` and contexts registered with `trackRequestContext()` / `security.trackRequestContext()` become records of source `api`, analysed by the same rules where they apply. Wrapped methods return the original promise, value and error. Works together with `playwright-performance-regression` (use `withSecurity(withPerf(...))`).
29
+ - `withSecurityFixtures()`, `trackContext()` and the `security` fixture (`playwright-security-scan/fixture`): in scan mode the browser contexts of each test are scanned passively — responses in scope, CSP violation events, and the cookie jar and Web Storage at the end of the test — and the redacted findings are attached to the test result. Bodies are read with limits, static assets once per worker. Without `PW_SEC_MODE` only an inactive `security` fixture is added.
30
+ - First rules: `header.xcto-missing`, `data.secret-in-asset`, `data.token-in-storage`.
31
+ - `withSecurity()` and `defineSecurityConfig()` (`playwright-security-scan/config`): `PW_SEC_MODE=scan|baseline` turns the scan on, the package reporter is appended, and the package config is validated with suggestions for mistyped options and rule ids. Without `PW_SEC_MODE` the Playwright config is returned unchanged. `PW_SEC_CONFIG` points to another config file.
32
+ - Rule presets `recommended` (default), `strict` and `minimal`.
33
+ - JSON Schemas of the file formats (`schemas/`, exported as `playwright-security-scan/schemas/*`): test attachment, baseline file, run report and outcome file.
34
+
35
+ [Unreleased]: https://github.com/Meser6/playwright-security-scan/compare/v0.1.0-beta.0...HEAD
36
+ [0.1.0-beta.0]: https://github.com/Meser6/playwright-security-scan/releases/tag/v0.1.0-beta.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jakub Kaczmarczyk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,335 @@
1
- # Temporary Holding Version
1
+ # playwright-security-scan
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Passive security scan (DAST) of the HTTP traffic your existing Playwright tests already produce —
4
+ e2e tests in the browser and API tests with the `request` fixture. No proxy, no ZAP, no new
5
+ scenarios: run your usual test command with `PW_SEC_MODE=scan`, review the findings, accept the
6
+ current state into a committed baseline, and from then on the run fails only when a **new**
7
+ problem appears.
8
+
9
+ It checks security headers, cookies, CORS, transport, tokens and secrets, information disclosure
10
+ and what the browser itself reports (CSP violations, Web Storage), with 44 rules by default.
11
+ Reports: console, HTML, JSON, SARIF (GitHub code scanning) and JUnit XML (any CI).
12
+
13
+ > **Status:** pre-release, not published on npm yet.
14
+
15
+ ## What it does not do
16
+
17
+ - It is **passive**: it never sends a request of its own and never changes your tests' requests.
18
+ So it does not test for injection, broken access control or other issues that need attacks;
19
+ active checks are planned for later versions.
20
+ - It only sees what your tests visit. Endpoints no test calls are not checked.
21
+ - WebSockets, Server-Sent Events and service worker traffic are not analysed.
22
+ - It does **not** replace a penetration test or a dependency (SCA) scan. A green run means "nothing
23
+ new since the last accepted baseline", not "the application is secure".
24
+
25
+ ## Install
26
+
27
+ ```sh
28
+ npm install --save-dev playwright-security-scan
29
+ ```
30
+
31
+ Requires Node.js ≥ 22.18 and `@playwright/test` ≥ 1.57. No runtime dependencies.
32
+
33
+ ## Set up: two changes
34
+
35
+ ```ts
36
+ // playwright.config.ts
37
+ import { defineConfig } from '@playwright/test';
38
+ import { withSecurity } from 'playwright-security-scan/config';
39
+
40
+ export default withSecurity(
41
+ defineConfig({
42
+ // your config, unchanged
43
+ }),
44
+ );
45
+ ```
46
+
47
+ ```ts
48
+ // fixtures.ts — the one place your tests import `test` from
49
+ import { test as base } from '@playwright/test';
50
+ import { withSecurityFixtures } from 'playwright-security-scan/fixture';
51
+
52
+ export { expect } from '@playwright/test';
53
+ export const test = withSecurityFixtures(base);
54
+ ```
55
+
56
+ If your specs import `test` from `@playwright/test` directly, create `fixtures.ts` as above and
57
+ change those imports to `./fixtures`. Without `PW_SEC_MODE` both wrappers change nothing.
58
+
59
+ The scope is the origin of `use.baseURL` of each project. If your API runs on another origin, add
60
+ it in a config file (see [Configuration](#configuration)).
61
+
62
+ ## Use
63
+
64
+ ```sh
65
+ # 1. First run: accept the current state as the baseline
66
+ PW_SEC_MODE=baseline npx playwright test
67
+
68
+ # 2. Review security-baseline.json and the report, add a "note" to each entry you accept, commit
69
+ git add security-baseline.json && git commit -m "Accept the current security findings"
70
+
71
+ # 3. In CI (and locally): fail only on new findings at or above the gate (medium by default)
72
+ PW_SEC_MODE=scan npx playwright test
73
+ ```
74
+
75
+ On Windows use `cross-env PW_SEC_MODE=scan npx playwright test` or, in PowerShell,
76
+ `$env:PW_SEC_MODE="scan"; npx playwright test`.
77
+
78
+ | `PW_SEC_MODE` | What happens |
79
+ | ------------- | -------------------------------------------------------------------------------------------- |
80
+ | (unset) | Nothing: the package adds no listener, no script and no reporter. |
81
+ | `scan` | Analyses the traffic, compares with the baseline, writes the reports, fails on new findings. |
82
+ | `baseline` | The same analysis without failing; writes `security-baseline.json` and prints the diff. |
83
+
84
+ A `baseline` run filtered with `--grep`, `--project`, `--shard`, file arguments or `--only-changed`
85
+ keeps the entries it could not confirm as resolved. Avoid `test.only` in a baseline run.
86
+
87
+ ### Result codes
88
+
89
+ `reports/pw-sec/outcome.json` tells CI why a scan failed, separately from your tests:
90
+
91
+ | Code | Name | Meaning |
92
+ | ---- | ------------------ | ---------------------------------------------------------------------------- |
93
+ | 0 | `OK` | No new finding at or above the gate. |
94
+ | 1 | `NEW_FINDINGS` | At least one new finding at or above the gate. |
95
+ | 2 | `BASELINE_EXPIRED` | A baseline entry passed its `until` date and the finding still occurs. |
96
+ | 3 | `TOOL_ERROR` | The scan could not be trusted (e.g. an invalid baseline file); see the logs. |
97
+ | 4 | `NO_TRAFFIC` | No response was in scope: set `use.baseURL` or `scope.origins`. |
98
+
99
+ Any code other than 0 makes the Playwright command exit with 1. See
100
+ [docs/troubleshooting.md](docs/troubleshooting.md) for every code.
101
+
102
+ ## The baseline
103
+
104
+ `security-baseline.json` lists the findings you have decided about, one entry per fingerprint:
105
+
106
+ ```json
107
+ {
108
+ "schemaVersion": 1,
109
+ "findings": {
110
+ "cookie.no-httponly|cookie|session_id@app.example.com": {
111
+ "ruleId": "cookie.no-httponly",
112
+ "subject": "session_id@app.example.com",
113
+ "severity": "medium",
114
+ "status": "accepted",
115
+ "note": "The frontend reads the cookie; ticket SEC-123",
116
+ "until": "2027-02-01",
117
+ "addedAt": "2026-11-24"
118
+ }
119
+ }
120
+ }
121
+ ```
122
+
123
+ - `status`: `accepted` (risk accepted), `wontfix` (needs a `note`) or `false-positive` (never
124
+ expires).
125
+ - `until` (optional): after this date the entry no longer protects the finding (code 2).
126
+ - The file holds no evidence, no URLs with values and no test names, so diffs stay small. Merge
127
+ conflicts: keep both sides and run `PW_SEC_MODE=baseline` again.
128
+
129
+ ## Configuration
130
+
131
+ Everything is optional. Pass a config as the second argument of `withSecurity()`, or point
132
+ `PW_SEC_CONFIG` to a file:
133
+
134
+ ```ts
135
+ // pw-sec.config.ts
136
+ import { defineSecurityConfig } from 'playwright-security-scan/config';
137
+
138
+ export default defineSecurityConfig({
139
+ scope: {
140
+ origins: ['https://api.example.com'], // more origins of your app besides use.baseURL
141
+ exclude: ['https://*.google-analytics.com'],
142
+ },
143
+ rules: {
144
+ 'header.referrer-policy-unsafe': 'off',
145
+ 'cookie.samesite-missing': { severity: 'info' },
146
+ 'data.token-in-url': { options: { paramNames: ['token', 'access_token', 'sig'] } },
147
+ },
148
+ gate: { minSeverity: 'medium', minConfidence: 'medium' },
149
+ });
150
+ ```
151
+
152
+ | Option | Default | What it does |
153
+ | ------------------------------------------------------------- | -------------------------- | ----------------------------------------------------------------- |
154
+ | `scope.origins` | `[]` | Origins to scan besides `use.baseURL` (`*` allowed in subdomains) |
155
+ | `scope.includeBaseURL` | `true` | Scan the origin of `use.baseURL` |
156
+ | `scope.exclude` | `[]` | Origins never scanned |
157
+ | `scope.projects` | `'all'` | Playwright projects to scan (setup projects included) |
158
+ | `scope.api` | `true` | Scan `APIRequestContext` calls |
159
+ | `rules.preset` | `'recommended'` | `minimal` (high-confidence rules), `recommended`, `strict` |
160
+ | `rules['<id>']` | on | `'off'`, `'on'` or `{ severity, confidence, options }` |
161
+ | `limits.maxBodyBytes` | `1048576` | Longer bodies are cut before analysis |
162
+ | `limits.bodyContentTypes` | HTML, JSON, JS, text, XML | Content types whose bodies are read |
163
+ | `limits.maxFindingsPerRule` | `200` | Per test |
164
+ | `browser.cspEvents` / `browser.storageScan` | `true` | CSP violation listener / Web Storage scan at the end of a test |
165
+ | `gate.minSeverity` / `gate.minConfidence` | `'medium'` / `'medium'` | The lowest new finding that fails the scan |
166
+ | `gate.failOnExpired` / `gate.failOnNoTraffic` | `true` / `true` | Codes 2 and 4 fail the run |
167
+ | `baseline.path` | `'security-baseline.json'` | Relative to the Playwright config |
168
+ | `baseline.pruneResolved` / `baseline.requireNote` | `true` / `false` | Remove resolved entries / require a note on accepted entries |
169
+ | `report.dir` | `'reports/pw-sec'` | Where reports go |
170
+ | `report.html` / `json` / `sarif` / `junit` | `true` | Which reports to write |
171
+ | `report.junitPath` | `<report.dir>/junit.xml` | For CI artifact patterns |
172
+ | `report.junitIncludeAccepted` / `report.sarifIncludeAccepted` | `true` / `false` | Baseline entries in JUnit (skipped) and SARIF (suppressed) |
173
+ | `normalization` | as the perf package | How URLs become endpoint keys (`GET /api/items/:id`) |
174
+
175
+ Mistyped options and rule ids fail at once with the closest valid name.
176
+
177
+ ### Contexts created by hand
178
+
179
+ Contexts from `browser.newContext()` inside a test are scanned after
180
+ `await security.track(context)`; worker-scoped contexts after `await trackContext(context)` (from
181
+ `playwright-security-scan/fixture`); contexts from `playwright.request.newContext()` after
182
+ `trackRequestContext(context)`.
183
+
184
+ ## Rules
185
+
186
+ <!-- rules:start -->
187
+
188
+ | Rule | Severity | Confidence | Traffic | CWE |
189
+ | ---------------------------------------------------------------------------------------------------------------------------------------- | -------- | ---------- | ------------ | ------- |
190
+ | [`header.csp-missing`](docs/rules/header.csp-missing.md) — Content-Security-Policy missing | medium | high | browser | 693 |
191
+ | [`header.csp-unsafe`](docs/rules/header.csp-unsafe.md) — Unsafe Content-Security-Policy | medium | high | browser | 693 |
192
+ | [`header.csp-missing-directives`](docs/rules/header.csp-missing-directives.md) — CSP without object-src or base-uri | low | high | browser | 693 |
193
+ | [`header.csp-report-only`](docs/rules/header.csp-report-only.md) — CSP in report-only mode only | info | high | browser | 693 |
194
+ | [`header.clickjacking`](docs/rules/header.clickjacking.md) — No clickjacking protection | medium | medium | browser | 1021 |
195
+ | [`header.hsts-missing`](docs/rules/header.hsts-missing.md) — Strict-Transport-Security missing | low | high | browser, api | 319 |
196
+ | [`header.hsts-weak`](docs/rules/header.hsts-weak.md) — Strict-Transport-Security max-age too short | low | high | browser, api | 319 |
197
+ | [`header.xcto-missing`](docs/rules/header.xcto-missing.md) — X-Content-Type-Options: nosniff missing | low | high | browser, api | 693 |
198
+ | [`header.referrer-policy-unsafe`](docs/rules/header.referrer-policy-unsafe.md) — Unsafe Referrer-Policy | low | high | browser | 200 |
199
+ | [`header.content-type-missing`](docs/rules/header.content-type-missing.md) — Content-Type missing | low | high | browser, api | 16 |
200
+ | [`header.permissions-policy-missing`](docs/rules/header.permissions-policy-missing.md) (strict) — Permissions-Policy missing | info | high | browser | 693 |
201
+ | [`header.coop-missing`](docs/rules/header.coop-missing.md) (strict) — Cross-Origin-Opener-Policy missing | info | high | browser | 693 |
202
+ | [`cookie.no-secure`](docs/rules/cookie.no-secure.md) — Session cookie without Secure | medium | high | browser, api | 614 |
203
+ | [`cookie.no-httponly`](docs/rules/cookie.no-httponly.md) — Session cookie without HttpOnly | medium | high | browser, api | 1004 |
204
+ | [`cookie.samesite-none`](docs/rules/cookie.samesite-none.md) — Session cookie with SameSite=None | low | medium | browser, api | 1275 |
205
+ | [`cookie.samesite-missing`](docs/rules/cookie.samesite-missing.md) — Cookie without SameSite | info | high | browser, api | 1275 |
206
+ | [`cookie.long-lived-session`](docs/rules/cookie.long-lived-session.md) — Long-lived session cookie | low | medium | browser, api | 613 |
207
+ | [`cookie.non-session-insecure`](docs/rules/cookie.non-session-insecure.md) — Cookie without Secure | info | medium | browser, api | 614 |
208
+ | [`cors.wildcard-credentials`](docs/rules/cors.wildcard-credentials.md) — CORS wildcard with credentials | high | high | browser, api | 942 |
209
+ | [`cors.reflected-origin-credentials`](docs/rules/cors.reflected-origin-credentials.md) — CORS reflects a foreign origin with credentials | high | medium | browser, api | 942 |
210
+ | [`cors.null-origin`](docs/rules/cors.null-origin.md) — CORS allows the null origin | medium | high | browser, api | 942 |
211
+ | [`cors.wildcard-sensitive`](docs/rules/cors.wildcard-sensitive.md) — CORS wildcard on an authenticated endpoint | low | low | browser, api | 942 |
212
+ | [`transport.cleartext`](docs/rules/transport.cleartext.md) — Application served over HTTP | medium | high | browser, api | 319 |
213
+ | [`transport.mixed-content`](docs/rules/transport.mixed-content.md) — Mixed content | medium | high | browser | 311 |
214
+ | [`transport.form-to-http`](docs/rules/transport.form-to-http.md) — Form submits over HTTP | medium | high | browser | 319 |
215
+ | [`transport.weak-tls`](docs/rules/transport.weak-tls.md) — Outdated TLS version | medium | high | browser | 326 |
216
+ | [`data.token-in-url`](docs/rules/data.token-in-url.md) — Token in URL | medium | high | browser, api | 598 |
217
+ | [`data.jwt-alg-none`](docs/rules/data.jwt-alg-none.md) — JWT with alg none | critical | high | browser, api | 347 |
218
+ | [`data.jwt-no-exp`](docs/rules/data.jwt-no-exp.md) — JWT without expiry | medium | high | browser, api | 613 |
219
+ | [`data.jwt-long-lived`](docs/rules/data.jwt-long-lived.md) — Long-lived JWT | low | high | browser, api | 613 |
220
+ | [`data.jwt-sensitive-claims`](docs/rules/data.jwt-sensitive-claims.md) — Sensitive data in JWT claims | medium | medium | browser, api | 312 |
221
+ | [`data.password-in-response`](docs/rules/data.password-in-response.md) — Password or hash in a response | high | medium | browser, api | 200 |
222
+ | [`data.secret-in-asset`](docs/rules/data.secret-in-asset.md) — Secret in a script, page or response | high | high | browser, api | 798 |
223
+ | [`data.token-in-storage`](docs/rules/data.token-in-storage.md) — Token in Web Storage | low | medium | browser | 922 |
224
+ | [`disclosure.stack-trace`](docs/rules/disclosure.stack-trace.md) — Stack trace in a response | medium | high | browser, api | 209 |
225
+ | [`disclosure.sql-error`](docs/rules/disclosure.sql-error.md) — SQL error in a response | high | medium | browser, api | 209, 89 |
226
+ | [`disclosure.server-version`](docs/rules/disclosure.server-version.md) — Server version disclosed | low | high | browser, api | 200 |
227
+ | [`disclosure.debug-mode`](docs/rules/disclosure.debug-mode.md) — Debug page exposed | medium | medium | browser, api | 489 |
228
+ | [`disclosure.private-ip`](docs/rules/disclosure.private-ip.md) — Private IP address disclosed | low | medium | browser, api | 200 |
229
+ | [`disclosure.directory-listing`](docs/rules/disclosure.directory-listing.md) — Directory listing | low | high | browser, api | 548 |
230
+ | [`disclosure.source-map`](docs/rules/disclosure.source-map.md) — Source map exposed | info | high | browser | 540 |
231
+ | [`disclosure.server-error`](docs/rules/disclosure.server-error.md) — Server error during tests | info | high | browser, api | 755 |
232
+ | [`browser.csp-violation`](docs/rules/browser.csp-violation.md) — CSP violation in the browser | info | high | browser | 693 |
233
+ | [`asset.sri-missing`](docs/rules/asset.sri-missing.md) — Third-party script or style without SRI | low | high | browser | 353 |
234
+ | [`browser.open-redirect-candidate`](docs/rules/browser.open-redirect-candidate.md) — Open redirect candidate | medium | medium | browser, api | 601 |
235
+ | [`browser.reflected-param`](docs/rules/browser.reflected-param.md) — Query parameter reflected in HTML | info | low | browser | 79 |
236
+
237
+ <!-- rules:end -->
238
+
239
+ Every rule page explains why it matters, how to fix it (nginx, Express, Spring) and its known
240
+ false positives.
241
+
242
+ ## Reports
243
+
244
+ All in `reports/pw-sec/`, written also when tests fail:
245
+
246
+ - `report.html` — one offline file: outcome, filters, details with evidence and a ready baseline
247
+ entry, coverage, and what the scan does not cover.
248
+ - `report.json` — everything, for your own tooling.
249
+ - `results.sarif` — SARIF 2.1.0; findings point to the test that first saw them.
250
+ - `junit.xml` — one suite per rule group; new blocking findings are failures.
251
+ - `outcome.json` — the result code.
252
+
253
+ Evidence is redacted before it leaves the browser worker: cookie values, tokens, JWTs, secrets and
254
+ `Authorization` headers never reach any file; response bodies never leave the worker.
255
+
256
+ ## CI
257
+
258
+ ### GitHub Actions (SARIF in the Security tab)
259
+
260
+ ```yaml
261
+ - run: npx playwright test
262
+ env:
263
+ PW_SEC_MODE: scan
264
+ - uses: github/codeql-action/upload-sarif@v3
265
+ if: always()
266
+ with:
267
+ sarif_file: reports/pw-sec/results.sarif
268
+ category: playwright-security-scan
269
+ - uses: actions/upload-artifact@v4
270
+ if: always()
271
+ with:
272
+ name: pw-sec
273
+ path: reports/pw-sec/
274
+ ```
275
+
276
+ ### GitLab CI
277
+
278
+ ```yaml
279
+ security-scan:
280
+ script:
281
+ - PW_SEC_MODE=scan npx playwright test
282
+ artifacts:
283
+ when: always
284
+ paths: [reports/pw-sec/]
285
+ reports:
286
+ junit: reports/pw-sec/junit.xml
287
+ ```
288
+
289
+ ### Azure DevOps
290
+
291
+ ```yaml
292
+ - script: npx playwright test
293
+ env:
294
+ PW_SEC_MODE: scan
295
+ - task: PublishTestResults@2
296
+ condition: always()
297
+ inputs:
298
+ testResultsFormat: JUnit
299
+ testResultsFiles: reports/pw-sec/junit.xml
300
+ testRunTitle: pw-sec
301
+ ```
302
+
303
+ ## With playwright-performance-regression
304
+
305
+ Both packages can be used in one project. Wrap the config with `withSecurity()` **outside**
306
+ `withPerf()` (in perf mode `withPerf()` keeps only the reporters it knows); the fixtures can be
307
+ chained in any order:
308
+
309
+ ```ts
310
+ export default withSecurity(withPerf(defineConfig({/* … */})));
311
+ export const test = withSecurityFixtures(withPerfFixtures(base));
312
+ ```
313
+
314
+ In the reverse order (`withPerf(withSecurity(...))`) perf mode removes the security reporter:
315
+ nothing is scanned and the run still passes. Check that the console shows the `pw-sec · mode: …` header
316
+ after the first run.
317
+
318
+ Run the two scans in separate CI jobs: body analysis adds load that can distort step timings.
319
+
320
+ ## Limitations
321
+
322
+ - Chromium is the supported browser; Firefox and WebKit work on a best-effort basis.
323
+ - Responses mocked with `route.fulfill()` are skipped.
324
+ - `transport.weak-tls` needs a server offering TLS 1.0/1.1, which current browsers refuse anyway.
325
+ - On `localhost`, transport rules (HSTS, `Secure` cookies, cleartext) are reported with low
326
+ confidence and do not fail the scan.
327
+
328
+ ## Privacy
329
+
330
+ The package sends nothing anywhere: no telemetry, no network calls of its own, and the HTML report
331
+ loads nothing from the network.
332
+
333
+ ## License
334
+
335
+ MIT