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.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { readMode, ConfigError, CONFIG_ENV, resolveConfig, setRegistered, SALT_ENV, RUN_ID_ENV, canonicalOrigin } from './chunk-IHU2HYVH.js';
|
|
2
|
+
export { ConfigError } from './chunk-IHU2HYVH.js';
|
|
3
|
+
import { VERSION } from './chunk-SFWIEETP.js';
|
|
4
|
+
export { VERSION } from './chunk-SFWIEETP.js';
|
|
5
|
+
import { randomBytes } from 'crypto';
|
|
6
|
+
import { readFileSync } from 'fs';
|
|
7
|
+
import { createRequire } from 'module';
|
|
8
|
+
import { isAbsolute, resolve, extname } from 'path';
|
|
9
|
+
|
|
10
|
+
// src/config/reporter-path.ts
|
|
11
|
+
function currentFile() {
|
|
12
|
+
return typeof __filename === "string" ? __filename : import.meta.filename;
|
|
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) {
|
|
30
|
+
const file = isAbsolute(path) ? path : resolve(process.cwd(), path);
|
|
31
|
+
try {
|
|
32
|
+
if (extname(file).toLowerCase() === ".json") return JSON.parse(readFileSync(file, "utf8"));
|
|
33
|
+
const loaded = createRequire(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: CONFIG_ENV,
|
|
42
|
+
message: `${CONFIG_ENV}: cannot load ${JSON.stringify(path)}: ${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 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 : 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[RUN_ID_ENV] ?? "") === "") {
|
|
97
|
+
process.env[RUN_ID_ENV] = `${(/* @__PURE__ */ new Date()).toISOString().replace(/[-:.]/g, "").slice(0, 15)}-${randomBytes(3).toString("hex")}`;
|
|
98
|
+
}
|
|
99
|
+
if ((process.env[SALT_ENV] ?? "") === "") process.env[SALT_ENV] = randomBytes(16).toString("hex");
|
|
100
|
+
}
|
|
101
|
+
function withSecurity(config, securityConfig) {
|
|
102
|
+
const mode = readMode(process.env);
|
|
103
|
+
if (!mode.ok) throw new ConfigError(mode.issues);
|
|
104
|
+
if (mode.mode === null) return config;
|
|
105
|
+
const fromEnv = (process.env[CONFIG_ENV] ?? "").trim();
|
|
106
|
+
const input = fromEnv === "" ? securityConfig : loadConfigFile(fromEnv);
|
|
107
|
+
const resolved = resolveConfig(input);
|
|
108
|
+
if (!resolved.ok) throw new 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 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
|
+
setRegistered({
|
|
131
|
+
config: resolved.config,
|
|
132
|
+
mode: mode.mode,
|
|
133
|
+
runId: process.env[RUN_ID_ENV] ?? "",
|
|
134
|
+
salt: process.env[SALT_ENV] ?? "",
|
|
135
|
+
pkgVersion: VERSION,
|
|
136
|
+
baseOrigins,
|
|
137
|
+
scannedProjects: names,
|
|
138
|
+
configPassed: input !== void 0,
|
|
139
|
+
warnings
|
|
140
|
+
});
|
|
141
|
+
return { ...config, reporter: withReporter(config, reporterEntryPath()) };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export { defineSecurityConfig, withSecurity };
|