playwright-security-scan 0.0.0 → 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 +36 -0
- package/LICENSE +21 -0
- package/README.md +333 -1
- package/dist/chunk-6HZSEXCR.js +2727 -0
- package/dist/chunk-BBF7BGCZ.cjs +10 -0
- package/dist/chunk-GHGZTTAG.cjs +1581 -0
- package/dist/chunk-HWVW6NBJ.cjs +2740 -0
- package/dist/chunk-IHU2HYVH.js +1554 -0
- package/dist/chunk-SFWIEETP.js +8 -0
- package/dist/config.cjs +153 -0
- package/dist/config.d.cts +219 -0
- package/dist/config.d.ts +219 -0
- package/dist/config.js +144 -0
- package/dist/fixture.cjs +733 -0
- package/dist/fixture.d.cts +35 -0
- package/dist/fixture.d.ts +35 -0
- package/dist/fixture.js +725 -0
- package/dist/reporter.cjs +1118 -0
- package/dist/reporter.d.cts +18 -0
- package/dist/reporter.d.ts +18 -0
- package/dist/reporter.js +1113 -0
- package/dist/rules.cjs +10 -0
- package/dist/rules.d.cts +4 -0
- package/dist/rules.d.ts +4 -0
- package/dist/rules.js +1 -0
- package/package.json +87 -4
- package/schemas/attachment.schema.json +15 -0
- package/schemas/baseline.schema.json +47 -0
- package/schemas/common.schema.json +307 -0
- package/schemas/outcome.schema.json +28 -0
- package/schemas/run-report.schema.json +192 -0
package/dist/config.cjs
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkGHGZTTAG_cjs = require('./chunk-GHGZTTAG.cjs');
|
|
4
|
+
var chunkBBF7BGCZ_cjs = require('./chunk-BBF7BGCZ.cjs');
|
|
5
|
+
var crypto = require('crypto');
|
|
6
|
+
var fs = require('fs');
|
|
7
|
+
var module$1 = require('module');
|
|
8
|
+
var path = require('path');
|
|
9
|
+
|
|
10
|
+
// src/config/reporter-path.ts
|
|
11
|
+
function currentFile() {
|
|
12
|
+
return typeof __filename === "string" ? __filename : undefined;
|
|
13
|
+
}
|
|
14
|
+
function reporterPathNextTo(file) {
|
|
15
|
+
const cut = Math.max(file.lastIndexOf("/"), file.lastIndexOf("\\")) + 1;
|
|
16
|
+
const name = file.slice(cut);
|
|
17
|
+
const dot = name.lastIndexOf(".");
|
|
18
|
+
return `${file.slice(0, cut)}reporter${dot === -1 ? "" : name.slice(dot)}`;
|
|
19
|
+
}
|
|
20
|
+
function reporterEntryPath() {
|
|
21
|
+
return reporterPathNextTo(currentFile());
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/config/with-security.ts
|
|
25
|
+
var LOCAL_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
26
|
+
function defineSecurityConfig(config) {
|
|
27
|
+
return config;
|
|
28
|
+
}
|
|
29
|
+
function loadConfigFile(path$1) {
|
|
30
|
+
const file = path.isAbsolute(path$1) ? path$1 : path.resolve(process.cwd(), path$1);
|
|
31
|
+
try {
|
|
32
|
+
if (path.extname(file).toLowerCase() === ".json") return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
33
|
+
const loaded = module$1.createRequire(path.resolve(process.cwd(), "noop.js"))(file);
|
|
34
|
+
if (typeof loaded === "object" && loaded !== null && "default" in loaded) {
|
|
35
|
+
return loaded.default;
|
|
36
|
+
}
|
|
37
|
+
return loaded;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
const issue = {
|
|
40
|
+
code: "CONFIG_FILE_UNREADABLE",
|
|
41
|
+
path: chunkGHGZTTAG_cjs.CONFIG_ENV,
|
|
42
|
+
message: `${chunkGHGZTTAG_cjs.CONFIG_ENV}: cannot load ${JSON.stringify(path$1)}: ${error instanceof Error ? error.message : String(error)}`,
|
|
43
|
+
hint: "Point it to a .json file or a module whose default export is the config."
|
|
44
|
+
};
|
|
45
|
+
throw new chunkGHGZTTAG_cjs.ConfigError([issue]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function scannedProjects(config, projects) {
|
|
49
|
+
const list = config.projects !== void 0 && config.projects.length > 0 ? config.projects : [{ name: "" }];
|
|
50
|
+
const names = [];
|
|
51
|
+
const origins = /* @__PURE__ */ new Set();
|
|
52
|
+
for (const project of list) {
|
|
53
|
+
const name = project.name ?? "";
|
|
54
|
+
if (projects !== "all" && !projects.includes(name)) continue;
|
|
55
|
+
names.push(name);
|
|
56
|
+
const baseURL = project.use?.baseURL ?? config.use?.baseURL;
|
|
57
|
+
const origin = baseURL === void 0 ? null : chunkGHGZTTAG_cjs.canonicalOrigin(baseURL);
|
|
58
|
+
if (origin !== null) origins.add(origin);
|
|
59
|
+
}
|
|
60
|
+
return { names, baseOrigins: [...origins].sort() };
|
|
61
|
+
}
|
|
62
|
+
function withReporter(config, path) {
|
|
63
|
+
const current = config.reporter;
|
|
64
|
+
let list;
|
|
65
|
+
if (current === void 0) {
|
|
66
|
+
list = [[process.env.CI ? "dot" : "list"]];
|
|
67
|
+
} else if (typeof current === "string") {
|
|
68
|
+
list = [[current]];
|
|
69
|
+
} else {
|
|
70
|
+
list = [...current];
|
|
71
|
+
}
|
|
72
|
+
if (!list.some(([name]) => name === path)) list.push([path]);
|
|
73
|
+
return list;
|
|
74
|
+
}
|
|
75
|
+
function reporterFlagIssue(argv) {
|
|
76
|
+
const start = argv.indexOf("test");
|
|
77
|
+
const args = start < 0 ? [] : argv.slice(start + 1);
|
|
78
|
+
const values = [];
|
|
79
|
+
for (let i = 0; i < args.length; i++) {
|
|
80
|
+
const arg = args[i] ?? "";
|
|
81
|
+
if (arg === "--reporter") values.push(args[i + 1] ?? "");
|
|
82
|
+
else if (arg.startsWith("--reporter=")) values.push(arg.slice("--reporter=".length));
|
|
83
|
+
}
|
|
84
|
+
if (values.length === 0) return void 0;
|
|
85
|
+
const names = values.flatMap((v) => v.split(","));
|
|
86
|
+
if (names.some((n) => n.includes("playwright-security-scan/reporter"))) return void 0;
|
|
87
|
+
return {
|
|
88
|
+
code: "RUN_REPORTER_FLAG",
|
|
89
|
+
path: "--reporter",
|
|
90
|
+
message: `--reporter=${values.join(",")} replaces the reporters of the Playwright config, so the security reporter would not run and the scan could not fail`,
|
|
91
|
+
hint: `Add it to the flag: --reporter=${values.join(",")},playwright-security-scan/reporter (or drop --reporter).`
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function mainProcessSetup() {
|
|
95
|
+
if (process.env.TEST_WORKER_INDEX !== void 0) return;
|
|
96
|
+
if ((process.env[chunkGHGZTTAG_cjs.RUN_ID_ENV] ?? "") === "") {
|
|
97
|
+
process.env[chunkGHGZTTAG_cjs.RUN_ID_ENV] = `${(/* @__PURE__ */ new Date()).toISOString().replace(/[-:.]/g, "").slice(0, 15)}-${crypto.randomBytes(3).toString("hex")}`;
|
|
98
|
+
}
|
|
99
|
+
if ((process.env[chunkGHGZTTAG_cjs.SALT_ENV] ?? "") === "") process.env[chunkGHGZTTAG_cjs.SALT_ENV] = crypto.randomBytes(16).toString("hex");
|
|
100
|
+
}
|
|
101
|
+
function withSecurity(config, securityConfig) {
|
|
102
|
+
const mode = chunkGHGZTTAG_cjs.readMode(process.env);
|
|
103
|
+
if (!mode.ok) throw new chunkGHGZTTAG_cjs.ConfigError(mode.issues);
|
|
104
|
+
if (mode.mode === null) return config;
|
|
105
|
+
const fromEnv = (process.env[chunkGHGZTTAG_cjs.CONFIG_ENV] ?? "").trim();
|
|
106
|
+
const input = fromEnv === "" ? securityConfig : loadConfigFile(fromEnv);
|
|
107
|
+
const resolved = chunkGHGZTTAG_cjs.resolveConfig(input);
|
|
108
|
+
if (!resolved.ok) throw new chunkGHGZTTAG_cjs.ConfigError(resolved.issues);
|
|
109
|
+
if (process.env.TEST_WORKER_INDEX === void 0) {
|
|
110
|
+
const flag = reporterFlagIssue(process.argv);
|
|
111
|
+
if (flag !== void 0) throw new chunkGHGZTTAG_cjs.ConfigError([flag]);
|
|
112
|
+
}
|
|
113
|
+
mainProcessSetup();
|
|
114
|
+
const { names, baseOrigins } = scannedProjects(config, resolved.config.scope.projects);
|
|
115
|
+
const warnings = [];
|
|
116
|
+
if ((baseOrigins.length === 0 || !resolved.config.scope.includeBaseURL) && resolved.config.scope.origins.length === 0) {
|
|
117
|
+
warnings.push({
|
|
118
|
+
code: "SCOPE_EMPTY",
|
|
119
|
+
level: "warn",
|
|
120
|
+
message: "scope: no origin is in scope; set `use.baseURL` or `scope.origins`"
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (resolved.config.scope.includeBaseURL && baseOrigins.some((origin) => LOCAL_HOSTS.has(new URL(origin).hostname))) {
|
|
124
|
+
warnings.push({
|
|
125
|
+
code: "LOCAL_ORIGIN",
|
|
126
|
+
level: "info",
|
|
127
|
+
message: "local origin: transport rules are advisory"
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
chunkGHGZTTAG_cjs.setRegistered({
|
|
131
|
+
config: resolved.config,
|
|
132
|
+
mode: mode.mode,
|
|
133
|
+
runId: process.env[chunkGHGZTTAG_cjs.RUN_ID_ENV] ?? "",
|
|
134
|
+
salt: process.env[chunkGHGZTTAG_cjs.SALT_ENV] ?? "",
|
|
135
|
+
pkgVersion: chunkBBF7BGCZ_cjs.VERSION,
|
|
136
|
+
baseOrigins,
|
|
137
|
+
scannedProjects: names,
|
|
138
|
+
configPassed: input !== void 0,
|
|
139
|
+
warnings
|
|
140
|
+
});
|
|
141
|
+
return { ...config, reporter: withReporter(config, reporterEntryPath()) };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
Object.defineProperty(exports, "ConfigError", {
|
|
145
|
+
enumerable: true,
|
|
146
|
+
get: function () { return chunkGHGZTTAG_cjs.ConfigError; }
|
|
147
|
+
});
|
|
148
|
+
Object.defineProperty(exports, "VERSION", {
|
|
149
|
+
enumerable: true,
|
|
150
|
+
get: function () { return chunkBBF7BGCZ_cjs.VERSION; }
|
|
151
|
+
});
|
|
152
|
+
exports.defineSecurityConfig = defineSecurityConfig;
|
|
153
|
+
exports.withSecurity = withSecurity;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { PlaywrightTestConfig } from '@playwright/test';
|
|
2
|
+
export { VERSION } from './rules.cjs';
|
|
3
|
+
|
|
4
|
+
/** A string matches a whole path segment literally; a RegExp is tested against it. */
|
|
5
|
+
type IdPattern = string | RegExp;
|
|
6
|
+
interface KeyBuilderInput {
|
|
7
|
+
/** Uppercase HTTP method. */
|
|
8
|
+
method: string;
|
|
9
|
+
/** Raw URL. */
|
|
10
|
+
url: string;
|
|
11
|
+
resourceType: string;
|
|
12
|
+
}
|
|
13
|
+
/** Returns a whole key, or undefined for the built-in normalization. */
|
|
14
|
+
type KeyBuilder = (req: KeyBuilderInput) => string | undefined;
|
|
15
|
+
/** Resolved normalization settings: every option has a value. */
|
|
16
|
+
interface NormalizationConfig {
|
|
17
|
+
/** Origin to label mapping; a key with `*` is a host pattern. */
|
|
18
|
+
origins: Record<string, string>;
|
|
19
|
+
idPatterns: {
|
|
20
|
+
number: boolean;
|
|
21
|
+
uuid: boolean;
|
|
22
|
+
hex: boolean;
|
|
23
|
+
token: boolean;
|
|
24
|
+
mixed: boolean;
|
|
25
|
+
prefixed: boolean;
|
|
26
|
+
email: boolean;
|
|
27
|
+
};
|
|
28
|
+
extraIdPatterns: IdPattern[];
|
|
29
|
+
query: 'names' | 'ignore';
|
|
30
|
+
keepQueryValues: string[];
|
|
31
|
+
dropQueryParams: string[];
|
|
32
|
+
keyBuilder?: KeyBuilder;
|
|
33
|
+
}
|
|
34
|
+
/** What a user may give: every option optional; regexes also as { regex, flags }. */
|
|
35
|
+
interface NormalizationInput {
|
|
36
|
+
origins?: Record<string, string>;
|
|
37
|
+
idPatterns?: Partial<NormalizationConfig['idPatterns']>;
|
|
38
|
+
extraIdPatterns?: (IdPattern | {
|
|
39
|
+
regex: string;
|
|
40
|
+
flags?: string;
|
|
41
|
+
})[];
|
|
42
|
+
query?: 'names' | 'ignore';
|
|
43
|
+
keepQueryValues?: string[];
|
|
44
|
+
dropQueryParams?: string[];
|
|
45
|
+
keyBuilder?: KeyBuilder;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A deduplicated finding (02, chapter 4).
|
|
50
|
+
*/
|
|
51
|
+
interface Finding {
|
|
52
|
+
/**
|
|
53
|
+
* Stable rule id, '<group>.<name>'.
|
|
54
|
+
*/
|
|
55
|
+
ruleId: string;
|
|
56
|
+
/**
|
|
57
|
+
* Severity of a finding.
|
|
58
|
+
*/
|
|
59
|
+
severity: 'info' | 'low' | 'medium' | 'high' | 'critical';
|
|
60
|
+
/**
|
|
61
|
+
* How sure a rule is that the finding is a real problem.
|
|
62
|
+
*/
|
|
63
|
+
confidence: 'low' | 'medium' | 'high';
|
|
64
|
+
/**
|
|
65
|
+
* What the subject of a finding is (07, chapter 3).
|
|
66
|
+
*/
|
|
67
|
+
scope: 'origin' | 'endpoint' | 'cookie' | 'storage-key' | 'asset';
|
|
68
|
+
/**
|
|
69
|
+
* Origin, endpoint key, name@domain, storage key or normalized asset URL.
|
|
70
|
+
*/
|
|
71
|
+
subject: string;
|
|
72
|
+
/**
|
|
73
|
+
* Tells apart findings of one rule on one subject (07-REQ-06); never a value.
|
|
74
|
+
*/
|
|
75
|
+
discriminator?: string;
|
|
76
|
+
location: Location;
|
|
77
|
+
/**
|
|
78
|
+
* @maxItems 3
|
|
79
|
+
*/
|
|
80
|
+
evidence: Evidence[];
|
|
81
|
+
message: string;
|
|
82
|
+
fingerprint: string;
|
|
83
|
+
occurrences: number;
|
|
84
|
+
firstSeen: TestContextRef;
|
|
85
|
+
/**
|
|
86
|
+
* testId of every test the finding occurred in, at most 50.
|
|
87
|
+
*
|
|
88
|
+
* @maxItems 50
|
|
89
|
+
*/
|
|
90
|
+
tests: string[];
|
|
91
|
+
/**
|
|
92
|
+
* Traffic sources the finding was seen in (15-REQ-09).
|
|
93
|
+
*
|
|
94
|
+
* @minItems 1
|
|
95
|
+
*
|
|
96
|
+
* Items: Where the traffic came from: a browser context or an APIRequestContext (15).
|
|
97
|
+
*/
|
|
98
|
+
sources: ('browser' | 'api')[];
|
|
99
|
+
}
|
|
100
|
+
interface Location {
|
|
101
|
+
origin: string;
|
|
102
|
+
endpointKey?: string;
|
|
103
|
+
param?: string;
|
|
104
|
+
header?: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* One piece of evidence, already redacted (07, chapter 5).
|
|
108
|
+
*/
|
|
109
|
+
interface Evidence {
|
|
110
|
+
kind: 'header' | 'cookie' | 'body' | 'url' | 'storage' | 'event';
|
|
111
|
+
/**
|
|
112
|
+
* Header, cookie, parameter or storage key name.
|
|
113
|
+
*/
|
|
114
|
+
name?: string;
|
|
115
|
+
snippet: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The test (and step) a record or finding comes from.
|
|
119
|
+
*/
|
|
120
|
+
interface TestContextRef {
|
|
121
|
+
testId: string;
|
|
122
|
+
/**
|
|
123
|
+
* Titles from the outermost describe to the test.
|
|
124
|
+
*/
|
|
125
|
+
titlePath: string[];
|
|
126
|
+
/**
|
|
127
|
+
* Test file path relative to the Playwright config directory, with forward slashes.
|
|
128
|
+
*/
|
|
129
|
+
file: string;
|
|
130
|
+
line: number;
|
|
131
|
+
project: string;
|
|
132
|
+
/**
|
|
133
|
+
* Title of the innermost running test.step, best effort.
|
|
134
|
+
*/
|
|
135
|
+
step?: string;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
type Severity = Finding['severity'];
|
|
139
|
+
type Confidence = Finding['confidence'];
|
|
140
|
+
|
|
141
|
+
type Preset = 'recommended' | 'strict' | 'minimal';
|
|
142
|
+
/** Per-rule setting (03, chapter 4). */
|
|
143
|
+
type RuleSetting = 'off' | 'on' | {
|
|
144
|
+
severity?: Severity;
|
|
145
|
+
confidence?: Confidence;
|
|
146
|
+
options?: Record<string, unknown>;
|
|
147
|
+
};
|
|
148
|
+
/** Config accepted by defineSecurityConfig() and withSecurity(); every option is optional. */
|
|
149
|
+
interface SecurityConfigInput {
|
|
150
|
+
scope?: {
|
|
151
|
+
origins?: string[];
|
|
152
|
+
includeBaseURL?: boolean;
|
|
153
|
+
exclude?: string[];
|
|
154
|
+
projects?: string[] | 'all';
|
|
155
|
+
api?: boolean;
|
|
156
|
+
};
|
|
157
|
+
rules?: {
|
|
158
|
+
preset?: Preset;
|
|
159
|
+
} & {
|
|
160
|
+
[ruleId: string]: RuleSetting | Preset | undefined;
|
|
161
|
+
};
|
|
162
|
+
limits?: {
|
|
163
|
+
maxBodyBytes?: number;
|
|
164
|
+
bodyContentTypes?: string[];
|
|
165
|
+
maxFindingsPerRule?: number;
|
|
166
|
+
};
|
|
167
|
+
browser?: {
|
|
168
|
+
cspEvents?: boolean;
|
|
169
|
+
storageScan?: boolean;
|
|
170
|
+
};
|
|
171
|
+
gate?: {
|
|
172
|
+
minSeverity?: Severity;
|
|
173
|
+
minConfidence?: Confidence;
|
|
174
|
+
failOnExpired?: boolean;
|
|
175
|
+
failOnNoTraffic?: boolean;
|
|
176
|
+
};
|
|
177
|
+
baseline?: {
|
|
178
|
+
path?: string;
|
|
179
|
+
pruneResolved?: boolean;
|
|
180
|
+
requireNote?: boolean;
|
|
181
|
+
};
|
|
182
|
+
report?: {
|
|
183
|
+
dir?: string;
|
|
184
|
+
html?: boolean;
|
|
185
|
+
json?: boolean;
|
|
186
|
+
sarif?: boolean;
|
|
187
|
+
junit?: boolean;
|
|
188
|
+
junitPath?: string;
|
|
189
|
+
junitIncludeAccepted?: boolean;
|
|
190
|
+
sarifIncludeAccepted?: boolean;
|
|
191
|
+
};
|
|
192
|
+
normalization?: NormalizationInput;
|
|
193
|
+
}
|
|
194
|
+
/** A config problem; `path` is the option path, e.g. "rules.cookie.no-htponly". */
|
|
195
|
+
interface ConfigIssue {
|
|
196
|
+
code: string;
|
|
197
|
+
path: string;
|
|
198
|
+
message: string;
|
|
199
|
+
hint?: string;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
declare class ConfigError extends Error {
|
|
203
|
+
readonly issues: ConfigIssue[];
|
|
204
|
+
constructor(issues: ConfigIssue[]);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Identity helper with types for pw-sec.config.ts (01, chapter 5). */
|
|
208
|
+
declare function defineSecurityConfig(config: SecurityConfigInput): SecurityConfigInput;
|
|
209
|
+
/**
|
|
210
|
+
* Wraps the Playwright config. Without PW_SEC_MODE it returns `config` itself (01-REQ-08, P-02).
|
|
211
|
+
* In scan or baseline mode it validates the package config (03-REQ-02), registers it for the
|
|
212
|
+
* reporter and the fixtures of this process (01-REQ-05) and returns a copy of `config` with the
|
|
213
|
+
* package reporter appended (01-REQ-07); workers, retries and timeouts are not changed (D-04).
|
|
214
|
+
* Invalid config or mode throws ConfigError before any test runs (04-AC-01).
|
|
215
|
+
*/
|
|
216
|
+
declare function withSecurity<T extends PlaywrightTestConfig>(config: T, securityConfig?: SecurityConfigInput): T;
|
|
217
|
+
|
|
218
|
+
export { ConfigError, defineSecurityConfig, withSecurity };
|
|
219
|
+
export type { ConfigIssue, Preset, RuleSetting, SecurityConfigInput };
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { PlaywrightTestConfig } from '@playwright/test';
|
|
2
|
+
export { VERSION } from './rules.js';
|
|
3
|
+
|
|
4
|
+
/** A string matches a whole path segment literally; a RegExp is tested against it. */
|
|
5
|
+
type IdPattern = string | RegExp;
|
|
6
|
+
interface KeyBuilderInput {
|
|
7
|
+
/** Uppercase HTTP method. */
|
|
8
|
+
method: string;
|
|
9
|
+
/** Raw URL. */
|
|
10
|
+
url: string;
|
|
11
|
+
resourceType: string;
|
|
12
|
+
}
|
|
13
|
+
/** Returns a whole key, or undefined for the built-in normalization. */
|
|
14
|
+
type KeyBuilder = (req: KeyBuilderInput) => string | undefined;
|
|
15
|
+
/** Resolved normalization settings: every option has a value. */
|
|
16
|
+
interface NormalizationConfig {
|
|
17
|
+
/** Origin to label mapping; a key with `*` is a host pattern. */
|
|
18
|
+
origins: Record<string, string>;
|
|
19
|
+
idPatterns: {
|
|
20
|
+
number: boolean;
|
|
21
|
+
uuid: boolean;
|
|
22
|
+
hex: boolean;
|
|
23
|
+
token: boolean;
|
|
24
|
+
mixed: boolean;
|
|
25
|
+
prefixed: boolean;
|
|
26
|
+
email: boolean;
|
|
27
|
+
};
|
|
28
|
+
extraIdPatterns: IdPattern[];
|
|
29
|
+
query: 'names' | 'ignore';
|
|
30
|
+
keepQueryValues: string[];
|
|
31
|
+
dropQueryParams: string[];
|
|
32
|
+
keyBuilder?: KeyBuilder;
|
|
33
|
+
}
|
|
34
|
+
/** What a user may give: every option optional; regexes also as { regex, flags }. */
|
|
35
|
+
interface NormalizationInput {
|
|
36
|
+
origins?: Record<string, string>;
|
|
37
|
+
idPatterns?: Partial<NormalizationConfig['idPatterns']>;
|
|
38
|
+
extraIdPatterns?: (IdPattern | {
|
|
39
|
+
regex: string;
|
|
40
|
+
flags?: string;
|
|
41
|
+
})[];
|
|
42
|
+
query?: 'names' | 'ignore';
|
|
43
|
+
keepQueryValues?: string[];
|
|
44
|
+
dropQueryParams?: string[];
|
|
45
|
+
keyBuilder?: KeyBuilder;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A deduplicated finding (02, chapter 4).
|
|
50
|
+
*/
|
|
51
|
+
interface Finding {
|
|
52
|
+
/**
|
|
53
|
+
* Stable rule id, '<group>.<name>'.
|
|
54
|
+
*/
|
|
55
|
+
ruleId: string;
|
|
56
|
+
/**
|
|
57
|
+
* Severity of a finding.
|
|
58
|
+
*/
|
|
59
|
+
severity: 'info' | 'low' | 'medium' | 'high' | 'critical';
|
|
60
|
+
/**
|
|
61
|
+
* How sure a rule is that the finding is a real problem.
|
|
62
|
+
*/
|
|
63
|
+
confidence: 'low' | 'medium' | 'high';
|
|
64
|
+
/**
|
|
65
|
+
* What the subject of a finding is (07, chapter 3).
|
|
66
|
+
*/
|
|
67
|
+
scope: 'origin' | 'endpoint' | 'cookie' | 'storage-key' | 'asset';
|
|
68
|
+
/**
|
|
69
|
+
* Origin, endpoint key, name@domain, storage key or normalized asset URL.
|
|
70
|
+
*/
|
|
71
|
+
subject: string;
|
|
72
|
+
/**
|
|
73
|
+
* Tells apart findings of one rule on one subject (07-REQ-06); never a value.
|
|
74
|
+
*/
|
|
75
|
+
discriminator?: string;
|
|
76
|
+
location: Location;
|
|
77
|
+
/**
|
|
78
|
+
* @maxItems 3
|
|
79
|
+
*/
|
|
80
|
+
evidence: Evidence[];
|
|
81
|
+
message: string;
|
|
82
|
+
fingerprint: string;
|
|
83
|
+
occurrences: number;
|
|
84
|
+
firstSeen: TestContextRef;
|
|
85
|
+
/**
|
|
86
|
+
* testId of every test the finding occurred in, at most 50.
|
|
87
|
+
*
|
|
88
|
+
* @maxItems 50
|
|
89
|
+
*/
|
|
90
|
+
tests: string[];
|
|
91
|
+
/**
|
|
92
|
+
* Traffic sources the finding was seen in (15-REQ-09).
|
|
93
|
+
*
|
|
94
|
+
* @minItems 1
|
|
95
|
+
*
|
|
96
|
+
* Items: Where the traffic came from: a browser context or an APIRequestContext (15).
|
|
97
|
+
*/
|
|
98
|
+
sources: ('browser' | 'api')[];
|
|
99
|
+
}
|
|
100
|
+
interface Location {
|
|
101
|
+
origin: string;
|
|
102
|
+
endpointKey?: string;
|
|
103
|
+
param?: string;
|
|
104
|
+
header?: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* One piece of evidence, already redacted (07, chapter 5).
|
|
108
|
+
*/
|
|
109
|
+
interface Evidence {
|
|
110
|
+
kind: 'header' | 'cookie' | 'body' | 'url' | 'storage' | 'event';
|
|
111
|
+
/**
|
|
112
|
+
* Header, cookie, parameter or storage key name.
|
|
113
|
+
*/
|
|
114
|
+
name?: string;
|
|
115
|
+
snippet: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The test (and step) a record or finding comes from.
|
|
119
|
+
*/
|
|
120
|
+
interface TestContextRef {
|
|
121
|
+
testId: string;
|
|
122
|
+
/**
|
|
123
|
+
* Titles from the outermost describe to the test.
|
|
124
|
+
*/
|
|
125
|
+
titlePath: string[];
|
|
126
|
+
/**
|
|
127
|
+
* Test file path relative to the Playwright config directory, with forward slashes.
|
|
128
|
+
*/
|
|
129
|
+
file: string;
|
|
130
|
+
line: number;
|
|
131
|
+
project: string;
|
|
132
|
+
/**
|
|
133
|
+
* Title of the innermost running test.step, best effort.
|
|
134
|
+
*/
|
|
135
|
+
step?: string;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
type Severity = Finding['severity'];
|
|
139
|
+
type Confidence = Finding['confidence'];
|
|
140
|
+
|
|
141
|
+
type Preset = 'recommended' | 'strict' | 'minimal';
|
|
142
|
+
/** Per-rule setting (03, chapter 4). */
|
|
143
|
+
type RuleSetting = 'off' | 'on' | {
|
|
144
|
+
severity?: Severity;
|
|
145
|
+
confidence?: Confidence;
|
|
146
|
+
options?: Record<string, unknown>;
|
|
147
|
+
};
|
|
148
|
+
/** Config accepted by defineSecurityConfig() and withSecurity(); every option is optional. */
|
|
149
|
+
interface SecurityConfigInput {
|
|
150
|
+
scope?: {
|
|
151
|
+
origins?: string[];
|
|
152
|
+
includeBaseURL?: boolean;
|
|
153
|
+
exclude?: string[];
|
|
154
|
+
projects?: string[] | 'all';
|
|
155
|
+
api?: boolean;
|
|
156
|
+
};
|
|
157
|
+
rules?: {
|
|
158
|
+
preset?: Preset;
|
|
159
|
+
} & {
|
|
160
|
+
[ruleId: string]: RuleSetting | Preset | undefined;
|
|
161
|
+
};
|
|
162
|
+
limits?: {
|
|
163
|
+
maxBodyBytes?: number;
|
|
164
|
+
bodyContentTypes?: string[];
|
|
165
|
+
maxFindingsPerRule?: number;
|
|
166
|
+
};
|
|
167
|
+
browser?: {
|
|
168
|
+
cspEvents?: boolean;
|
|
169
|
+
storageScan?: boolean;
|
|
170
|
+
};
|
|
171
|
+
gate?: {
|
|
172
|
+
minSeverity?: Severity;
|
|
173
|
+
minConfidence?: Confidence;
|
|
174
|
+
failOnExpired?: boolean;
|
|
175
|
+
failOnNoTraffic?: boolean;
|
|
176
|
+
};
|
|
177
|
+
baseline?: {
|
|
178
|
+
path?: string;
|
|
179
|
+
pruneResolved?: boolean;
|
|
180
|
+
requireNote?: boolean;
|
|
181
|
+
};
|
|
182
|
+
report?: {
|
|
183
|
+
dir?: string;
|
|
184
|
+
html?: boolean;
|
|
185
|
+
json?: boolean;
|
|
186
|
+
sarif?: boolean;
|
|
187
|
+
junit?: boolean;
|
|
188
|
+
junitPath?: string;
|
|
189
|
+
junitIncludeAccepted?: boolean;
|
|
190
|
+
sarifIncludeAccepted?: boolean;
|
|
191
|
+
};
|
|
192
|
+
normalization?: NormalizationInput;
|
|
193
|
+
}
|
|
194
|
+
/** A config problem; `path` is the option path, e.g. "rules.cookie.no-htponly". */
|
|
195
|
+
interface ConfigIssue {
|
|
196
|
+
code: string;
|
|
197
|
+
path: string;
|
|
198
|
+
message: string;
|
|
199
|
+
hint?: string;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
declare class ConfigError extends Error {
|
|
203
|
+
readonly issues: ConfigIssue[];
|
|
204
|
+
constructor(issues: ConfigIssue[]);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Identity helper with types for pw-sec.config.ts (01, chapter 5). */
|
|
208
|
+
declare function defineSecurityConfig(config: SecurityConfigInput): SecurityConfigInput;
|
|
209
|
+
/**
|
|
210
|
+
* Wraps the Playwright config. Without PW_SEC_MODE it returns `config` itself (01-REQ-08, P-02).
|
|
211
|
+
* In scan or baseline mode it validates the package config (03-REQ-02), registers it for the
|
|
212
|
+
* reporter and the fixtures of this process (01-REQ-05) and returns a copy of `config` with the
|
|
213
|
+
* package reporter appended (01-REQ-07); workers, retries and timeouts are not changed (D-04).
|
|
214
|
+
* Invalid config or mode throws ConfigError before any test runs (04-AC-01).
|
|
215
|
+
*/
|
|
216
|
+
declare function withSecurity<T extends PlaywrightTestConfig>(config: T, securityConfig?: SecurityConfigInput): T;
|
|
217
|
+
|
|
218
|
+
export { ConfigError, defineSecurityConfig, withSecurity };
|
|
219
|
+
export type { ConfigIssue, Preset, RuleSetting, SecurityConfigInput };
|