eaa-kit 0.7.0 → 0.11.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/README.md +182 -135
- package/dist/astro/index.d.ts +1 -3
- package/dist/astro/index.js +2 -3
- package/dist/audit/runners/worker.js +2 -3
- package/dist/{audit-DRjAY2iY.js → audit-DbqNIrt6.js} +85 -219
- package/dist/audit-rUhqnm3o.js +1 -0
- package/dist/{baseline-BpE7DbDq.js → baseline-CKElWbx4.js} +18 -8
- package/dist/baseline-DU0EPiTq.js +1 -0
- package/dist/baseline-DYOejLFO.js +1 -0
- package/dist/baseline-DvdsFTQy.js +126 -0
- package/dist/{cache-D4dOIuOi.js → cache-DIV4G0TI.js} +24 -5
- package/dist/{checklist-DDd9jewi.js → checklist-CA0Ri71Z.js} +8 -9
- package/dist/cli/index.js +115 -158
- package/dist/{collect-Cu1q9NTB.js → collect-CjucwTEF.js} +16 -8
- package/dist/{command-3r4fht5f.js → command-C8ZFvcc1.js} +33 -10
- package/dist/completeness-Cg-XIKWN.js +1 -0
- package/dist/completeness-Dzyvgr4Z.js +72 -0
- package/dist/component-CgbeRgJa.js +1 -0
- package/dist/{component-ChisoFyY.js → component-ZLd8DA_a.js} +3 -4
- package/dist/countries-B_PE6r5R.js +180 -0
- package/dist/countries-CCqog6dy.js +28 -0
- package/dist/coverage-B9_6yv_8.js +2 -0
- package/dist/{coverage-cb5kPp48.js → coverage-C1Z6t9Ct.js} +5 -7
- package/dist/{crawl-BHkJmUkA.js → crawl-CkHJJV4w.js} +135 -25
- package/dist/{criteria-CnPJKGeb.js → criteria-CacF0HP1.js} +1 -2
- package/dist/{load-BaWMa-G_.js → define-BdTPIfqE.js} +46 -99
- package/dist/detect-DnFHXpWh.js +49 -0
- package/dist/detect-oLDadgee.js +160 -0
- package/dist/doctor-q8IebwAb.js +248 -0
- package/dist/eleventy/index.d.ts +1 -3
- package/dist/eleventy/index.js +2 -3
- package/dist/entry-kf94P140.js +173 -0
- package/dist/{fingerprint-BjYV_0F7.js → fingerprint-CcoQ1WxQ.js} +1 -2
- package/dist/{frameworks-B4ClIJgE.js → frameworks-BboC8eNk.js} +234 -28
- package/dist/frameworks-Y-n3NUuG.js +1 -0
- package/dist/{fs-BmPtmFke.js → fs-tPD5r0wY.js} +1 -2
- package/dist/hosts-B48qR6Vt.js +19 -0
- package/dist/{html-BIxxF3FC.js → html-Bjq3Iw3g.js} +56 -14
- package/dist/{impact-luGCnN8F.js → impact-BGlJ6j0Y.js} +1 -2
- package/dist/{impact-EEB9ZXmC.d.ts → impact-CZjUloYC.d.ts} +0 -2
- package/dist/index.d.ts +50 -26
- package/dist/index.js +3 -2
- package/dist/init-3Ti3ao5Z.js +232 -0
- package/dist/issues-WLlepU95.js +120 -0
- package/dist/{jsdom-CsW_xVcA.js → jsdom-C4pLIMyP.js} +2 -3
- package/dist/jsdom-Zle--VQ1.js +2 -0
- package/dist/{json-Bus6YhxB.js → json-B_k4CDmR.js} +5 -6
- package/dist/json-IL1JxlTL.js +1 -0
- package/dist/load-C3eFEdoH.js +98 -0
- package/dist/load-oQQJPNlV.js +1 -0
- package/dist/markdown-D-QpPYsz.js +138 -0
- package/dist/next-8zDgH0nP.js +119 -0
- package/dist/nuxt/index.d.ts +1 -3
- package/dist/nuxt/index.js +2 -3
- package/dist/pages-CCP1WfYe.js +363 -0
- package/dist/{playwright-ukCr_5o3.js → playwright-ky4b_HME.js} +98 -16
- package/dist/{pool-B4tEUa2S.js → pool-B3XKdk57.js} +4 -5
- package/dist/project-B21NT_aX.js +502 -0
- package/dist/project-Dht13sb1.js +1 -0
- package/dist/{remediation-C0klJblu.js → remediation-BkE7q7dT.js} +2 -176
- package/dist/{render-C1sUZZI_.js → render-ky8cm4QF.js} +50 -24
- package/dist/result-DhoT4g0P.js +1 -0
- package/dist/{result-B7_zVxAX.js → result-g8dGsrcv.js} +1 -2
- package/dist/{review-CdMK2GpQ.js → review-BGjTBFvd.js} +11 -4
- package/dist/review-iheEjp7_.js +1 -0
- package/dist/{routes-CmdRUuOs.js → routes-BpQeBDmM.js} +4 -5
- package/dist/{run-DrS0Komf.js → run-D7tc7IU2.js} +2 -3
- package/dist/{run-BK2blxMI.d.ts → run-VXnP4uLp.d.ts} +2 -6
- package/dist/{sarif-BNCE0PNT.js → sarif-v66-PjdE.js} +9 -9
- package/dist/{schema-DJSF4K05.js → schema-DfC-Ww1w.js} +1 -2
- package/dist/setup-BYlqHlo0.js +2 -0
- package/dist/setup-Cf82ONw0.js +353 -0
- package/dist/shell-BdQYTaBQ.js +89 -0
- package/dist/site-CxVyh8IO.js +71 -0
- package/dist/start-bdanSxZr.js +100 -0
- package/dist/statement/templates/be.de.md +148 -0
- package/dist/statement/templates/be.en.md +142 -0
- package/dist/statement/templates/be.fr.md +146 -0
- package/dist/statement/templates/be.nl.md +147 -0
- package/dist/statement/templates/cz.cs.md +138 -0
- package/dist/statement/templates/cz.en.md +140 -0
- package/dist/statement/templates/dk.da.md +142 -0
- package/dist/statement/templates/dk.en.md +142 -0
- package/dist/statement/templates/fi.en.md +139 -0
- package/dist/statement/templates/fi.fi.md +141 -0
- package/dist/statement/templates/ie.en.md +144 -0
- package/dist/statement/templates/pl.en.md +143 -0
- package/dist/statement/templates/pl.pl.md +144 -0
- package/dist/statement/templates/pt.en.md +143 -0
- package/dist/statement/templates/pt.pt.md +145 -0
- package/dist/statement/templates/se.en.md +148 -0
- package/dist/statement/templates/se.sv.md +150 -0
- package/dist/{text-BF1LHMiV.js → text-CISDPU49.js} +11 -3
- package/dist/{version-B3v4rNoG.js → version-C8aJm8YJ.js} +1 -2
- package/dist/vite/index.d.ts +1 -3
- package/dist/vite/index.js +2 -3
- package/dist/watch-CefxwMsZ.js +121 -0
- package/dist/webpack/index.d.ts +1 -3
- package/dist/webpack/index.js +2 -3
- package/dist/{worksheet-BIxMtbUd.js → worksheet-CcBo9G7s.js} +4 -5
- package/dist/workspaces-BBFXOyeV.js +85 -0
- package/package.json +16 -14
- package/dist/audit-Bwm1xBdJ.js +0 -2
- package/dist/baseline-rtnj3RHB.js +0 -2
- package/dist/component-DcCn3BJS.js +0 -2
- package/dist/coverage-n1X9CkiG.js +0 -3
- package/dist/frameworks-etFg_O8K.js +0 -2
- package/dist/init-DrFfzjvm.js +0 -119
- package/dist/jsdom-BUYuVJJm.js +0 -3
- package/dist/json-CrQmoTj6.js +0 -2
- package/dist/load-n62iXDq_.js +0 -2
- package/dist/project-CzOnkLH6.js +0 -274
- package/dist/project-MFrXcw1M.js +0 -2
- package/dist/result-CRmjjoAA.js +0 -2
- package/dist/review-DIbOTmOM.js +0 -2
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { a as holdsHtml, i as emptyDirectoryHint, r as collectPages, t as BuildDirectoryError } from "./collect-CjucwTEF.js";
|
|
2
|
+
import { n as count } from "./text-CISDPU49.js";
|
|
3
|
+
import { c as nextStep, d as warn, l as note, o as fail, s as failWith } from "./command-C8ZFvcc1.js";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
// src/cli/pages.ts
|
|
6
|
+
/**
|
|
7
|
+
* Collect the pages to audit, reporting to stderr on the way.
|
|
8
|
+
*
|
|
9
|
+
* Returns undefined when there is nothing to audit, having already explained
|
|
10
|
+
* why. Every caller turns that into exit 2 — a run that reached no verdict,
|
|
11
|
+
* which is not the same as a clean one.
|
|
12
|
+
*/
|
|
13
|
+
async function resolvePages(directory, options = {}) {
|
|
14
|
+
if (directory === void 0 && options.url === void 0) return resolveAutomatically(options);
|
|
15
|
+
if (options.url !== void 0) {
|
|
16
|
+
const crawled = await crawlPages(options.url, options);
|
|
17
|
+
if (!crawled) return void 0;
|
|
18
|
+
if (crawled.pages.length === 0) {
|
|
19
|
+
warn(`No pages could be fetched from ${options.url}`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const { kept, shells } = await setAsideShells(crawled.pages, options.browser, "absolutePath");
|
|
23
|
+
if (kept.length === 0) {
|
|
24
|
+
warn(`${options.url} serves only a single-page-app shell, which JavaScript fills in and this engine does not run.`);
|
|
25
|
+
nextStep({
|
|
26
|
+
command: `eaa-kit audit --url ${options.url} --browser`,
|
|
27
|
+
why: "audit it in Chromium, scripts and all"
|
|
28
|
+
});
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
warnUnmeasured(shells, "page", "audited");
|
|
32
|
+
crawled.completeness.unreachable.push(...shells);
|
|
33
|
+
return {
|
|
34
|
+
pages: kept,
|
|
35
|
+
origin: crawled.origin,
|
|
36
|
+
label: options.url,
|
|
37
|
+
completeness: crawled.completeness
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const cwd = options.cwd ?? process.cwd();
|
|
41
|
+
const shown = options.label ?? directory;
|
|
42
|
+
const unreachable = [];
|
|
43
|
+
let pages;
|
|
44
|
+
try {
|
|
45
|
+
pages = await collectPages(directory, {
|
|
46
|
+
...options.include ? { include: options.include } : {},
|
|
47
|
+
...options.exclude ? { exclude: options.exclude } : {},
|
|
48
|
+
onUnreadable: (relativePath, reason) => unreachable.push({
|
|
49
|
+
location: relativePath,
|
|
50
|
+
reason
|
|
51
|
+
})
|
|
52
|
+
});
|
|
53
|
+
} catch (cause) {
|
|
54
|
+
if (!(cause instanceof BuildDirectoryError)) throw cause;
|
|
55
|
+
failWith(cause);
|
|
56
|
+
note(await emptyDirectoryHint(shown, cwd));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (pages.length === 0) {
|
|
60
|
+
if ((options.include !== void 0 || options.exclude !== void 0) && await holdsHtml(directory)) {
|
|
61
|
+
warn(`No page in ${shown} matched the filters, so nothing was audited.`);
|
|
62
|
+
if (options.include !== void 0) note(` --include ${options.include.join(" ")}`);
|
|
63
|
+
if (options.exclude !== void 0) note(` --exclude ${options.exclude.join(" ")}`);
|
|
64
|
+
note(" Patterns are relative to the audited directory, with POSIX separators.");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
warn(await emptyDirectoryHint(shown, cwd));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
warnUnmeasured(unreachable, "file", "readable");
|
|
71
|
+
const { kept, shells } = await setAsideShells(pages, options.browser);
|
|
72
|
+
if (kept.length === 0) {
|
|
73
|
+
warn(`${shown} holds only a single-page-app shell, which JavaScript fills in and this engine does not run.`);
|
|
74
|
+
nextStep({
|
|
75
|
+
command: `eaa-kit audit ${shown} --browser`,
|
|
76
|
+
why: "audit it in Chromium, scripts and all"
|
|
77
|
+
});
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
warnUnmeasured(shells, "page", "audited");
|
|
81
|
+
pages = kept;
|
|
82
|
+
unreachable.push(...shells);
|
|
83
|
+
return {
|
|
84
|
+
pages,
|
|
85
|
+
directory,
|
|
86
|
+
label: shown,
|
|
87
|
+
completeness: {
|
|
88
|
+
discovery: "directory",
|
|
89
|
+
collected: pages.length,
|
|
90
|
+
unreachable,
|
|
91
|
+
truncated: false
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Take out the pages that are empty shells a script fills in, unless the audit
|
|
97
|
+
* runs in a browser that would run the script. See `isAppShell`.
|
|
98
|
+
*/
|
|
99
|
+
async function setAsideShells(pages, browser, locate = "relativePath") {
|
|
100
|
+
if (browser) return {
|
|
101
|
+
kept: pages,
|
|
102
|
+
shells: []
|
|
103
|
+
};
|
|
104
|
+
const { isAppShell } = await import("./shell-BdQYTaBQ.js");
|
|
105
|
+
const kept = [];
|
|
106
|
+
const shells = [];
|
|
107
|
+
for (const page of pages) if (isAppShell(page.html)) shells.push({
|
|
108
|
+
location: page[locate],
|
|
109
|
+
reason: "a single-page-app shell: its content is rendered by JavaScript, which this engine does not run; audit it with --browser"
|
|
110
|
+
});
|
|
111
|
+
else kept.push(page);
|
|
112
|
+
return {
|
|
113
|
+
kept,
|
|
114
|
+
shells
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Name what was missed, up to ten of them, and count the rest.
|
|
119
|
+
*
|
|
120
|
+
* Both collectors need this and neither may skip it: a file that could not be
|
|
121
|
+
* read and a URL that could not be fetched are pages with no verdict, and a run
|
|
122
|
+
* that mentioned neither would report the rest of the site as though it were
|
|
123
|
+
* the site. Ten because the point is to make the problem recognisable, and two
|
|
124
|
+
* hundred failures usually have the one reason the first few show — the count
|
|
125
|
+
* that follows is what says the list was cut.
|
|
126
|
+
*/
|
|
127
|
+
function warnUnmeasured(missed, noun, reached) {
|
|
128
|
+
if (missed.length === 0) return;
|
|
129
|
+
warn(`${count(missed.length, noun)} ${missed.length === 1 ? "was" : "were"} not ${reached}, and so not audited:`);
|
|
130
|
+
for (const item of missed.slice(0, 10)) note(` ${item.location} — ${item.reason}`);
|
|
131
|
+
if (missed.length > 10) note(` …and ${missed.length - 10} more`);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Fetch the pages of a running site, reporting what happened on the way.
|
|
135
|
+
*
|
|
136
|
+
* Returns undefined when the crawl could not start, which the caller turns into
|
|
137
|
+
* exit 2 — a run that reached no verdict, not a clean one.
|
|
138
|
+
*/
|
|
139
|
+
async function crawlPages(url, options) {
|
|
140
|
+
const { collapsedOnto, crawlSite, CrawlError, parseEntryUrl } = await import("./crawl-CkHJJV4w.js");
|
|
141
|
+
let entry;
|
|
142
|
+
try {
|
|
143
|
+
entry = parseEntryUrl(url, options.allowRemote ?? false);
|
|
144
|
+
} catch (cause) {
|
|
145
|
+
if (cause instanceof CrawlError) {
|
|
146
|
+
failWith(cause);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
throw cause;
|
|
150
|
+
}
|
|
151
|
+
note(`Crawling ${entry.origin}…`);
|
|
152
|
+
const followed = await followEntry(entry, options);
|
|
153
|
+
if (followed === void 0) return void 0;
|
|
154
|
+
entry = followed.entry;
|
|
155
|
+
const result = await crawlSite(entry, {
|
|
156
|
+
...options.allowRemote ? { allowRemote: true } : {},
|
|
157
|
+
...options.ignoreRobots ? { ignoreRobots: true } : {},
|
|
158
|
+
...options.sitemap === void 0 ? {} : { sitemap: options.sitemap },
|
|
159
|
+
...options.maxPages === void 0 ? {} : { maxPages: options.maxPages },
|
|
160
|
+
...options.maxDepth === void 0 ? {} : { maxDepth: options.maxDepth },
|
|
161
|
+
...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs },
|
|
162
|
+
...options.headers === void 0 ? {} : { headers: options.headers },
|
|
163
|
+
...options.seeds === void 0 ? {} : { seeds: options.seeds },
|
|
164
|
+
...options.fetchImpl === void 0 ? {} : { fetchImpl: options.fetchImpl }
|
|
165
|
+
});
|
|
166
|
+
if (result.pages.length === 0 && result.failures.length > 0) {
|
|
167
|
+
fail(`Could not fetch ${entry.href} (${result.failures[0]?.reason})`);
|
|
168
|
+
note(" Is the site running at that address?");
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const { discoveryLabel } = await import("./completeness-Cg-XIKWN.js");
|
|
172
|
+
const found = discoveryLabel(result.discovery);
|
|
173
|
+
note(`Found ${count(result.pages.length, "page")} from ${found}`);
|
|
174
|
+
const failed = result.failures.map((failure) => ({
|
|
175
|
+
location: failure.url,
|
|
176
|
+
reason: failure.reason
|
|
177
|
+
}));
|
|
178
|
+
warnUnmeasured(failed, "URL", "fetched");
|
|
179
|
+
const known = options.knownUnreachable ?? [];
|
|
180
|
+
warnUnmeasured(known, "route", "listed");
|
|
181
|
+
if (result.truncated) warn(`Stopped at ${count(result.pages.length, "page")}; the site has more. Raise --max-pages to go further.`);
|
|
182
|
+
const collapsed = collapsedOnto(result);
|
|
183
|
+
const { hasPasswordField } = await import("./entry-kf94P140.js");
|
|
184
|
+
const landedOn = collapsed[0]?.landedOn ?? "";
|
|
185
|
+
const signInForm = collapsed.length > 0 && result.pages.some((page) => page.absolutePath === landedOn && hasPasswordField(page.html));
|
|
186
|
+
if (collapsed.length > 0) {
|
|
187
|
+
if (signInForm) warn(`Every page requested answered at ${landedOn}, which has a password field on it: a sign-in page stands in front of the site.`);
|
|
188
|
+
else {
|
|
189
|
+
warn(`Every page requested answered at ${landedOn}, which is not where it was asked.`);
|
|
190
|
+
note(" A sign-in page in front of the site looks like this, and so does a one-page site.");
|
|
191
|
+
}
|
|
192
|
+
nextStep({
|
|
193
|
+
command: `eaa-kit audit --url ${entry.href} --basic-auth user:password`,
|
|
194
|
+
why: "or --header \"Cookie: …\" with a signed-in session; neither is written into a report"
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
pages: result.pages,
|
|
199
|
+
origin: result.origin,
|
|
200
|
+
completeness: {
|
|
201
|
+
discovery: result.discovery,
|
|
202
|
+
collected: result.pages.length,
|
|
203
|
+
unreachable: [
|
|
204
|
+
...failed,
|
|
205
|
+
...known,
|
|
206
|
+
...collapsed.map((redirect) => ({
|
|
207
|
+
location: redirect.requested,
|
|
208
|
+
reason: signInForm ? `answered at ${redirect.landedOn} instead, a sign-in page, so this page was not audited` : `answered at ${redirect.landedOn} instead, so this page was not audited`
|
|
209
|
+
}))
|
|
210
|
+
],
|
|
211
|
+
truncated: result.truncated,
|
|
212
|
+
...followed.redirect === void 0 ? {} : { entryRedirect: followed.redirect }
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Where the crawl should start, once the entry's redirects are known.
|
|
218
|
+
*
|
|
219
|
+
* Returns undefined when the run must stop, having said why and what to type:
|
|
220
|
+
* a sign-in wall, or a redirect to another site nobody agreed to follow. Those
|
|
221
|
+
* are the two ways a run can audit something other than what it was sent to,
|
|
222
|
+
* and each one ends here rather than in a report about the wrong pages.
|
|
223
|
+
*/
|
|
224
|
+
async function followEntry(entry, options) {
|
|
225
|
+
const { describeSignIn, isSameSite, probeEntry } = await import("./entry-kf94P140.js");
|
|
226
|
+
const { CrawlError, DEFAULT_REQUEST_TIMEOUT_MS, MAX_BODY_BYTES, parseEntryUrl } = await import("./crawl-CkHJJV4w.js");
|
|
227
|
+
const probe = await probeEntry(entry, {
|
|
228
|
+
timeoutMs: options.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS,
|
|
229
|
+
maxBodyBytes: MAX_BODY_BYTES,
|
|
230
|
+
...options.headers === void 0 ? {} : { headers: options.headers },
|
|
231
|
+
...options.seeds === void 0 ? {} : { seeds: options.seeds },
|
|
232
|
+
...options.fetchImpl === void 0 ? {} : { fetchImpl: options.fetchImpl }
|
|
233
|
+
});
|
|
234
|
+
if (probe.error !== void 0 && probe.hops.length === 0) return { entry };
|
|
235
|
+
if (probe.error !== void 0) {
|
|
236
|
+
fail(`${entry.href} did not settle on a page: ${probe.error}`);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (probe.signIn !== void 0) {
|
|
240
|
+
const at = probe.final.href;
|
|
241
|
+
fail(`${entry.href} is behind a sign-in wall: ${describeSignIn(probe.signIn, at)}.`);
|
|
242
|
+
note(options.headers !== void 0 ? " The credentials that were sent were not accepted, so nothing was audited." : probe.signIn === "http-401" || probe.signIn === "http-403" ? " Nothing was audited: there is no page to audit until the site lets the run in." : " eaa-kit will not audit a sign-in form as though it were the site, so nothing was audited.");
|
|
243
|
+
nextStep(probe.signIn === "http-401" ? {
|
|
244
|
+
command: `eaa-kit audit --url ${entry.href} --basic-auth user:password`,
|
|
245
|
+
why: "send the credentials it asks for; they are never written into a report"
|
|
246
|
+
} : {
|
|
247
|
+
command: `eaa-kit audit --url ${entry.href} --header "Cookie: <session>"`,
|
|
248
|
+
why: "send a signed-in session, copied from your browser; never written into a report"
|
|
249
|
+
});
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const destination = probe.final;
|
|
253
|
+
if (destination.origin === entry.origin) return { entry };
|
|
254
|
+
const statuses = probe.hops.slice(0, -1).map((hop) => hop.status);
|
|
255
|
+
const chain = `${statuses.join(" → ")}`;
|
|
256
|
+
const sameSite = isSameSite(entry, destination);
|
|
257
|
+
const mode = options.redirects ?? "ask";
|
|
258
|
+
let because;
|
|
259
|
+
if (mode !== "stop" && sameSite) because = "same-site";
|
|
260
|
+
else if (mode === "follow") because = "flag";
|
|
261
|
+
else if (mode === "ask") {
|
|
262
|
+
const confirm = options.confirm ?? terminalConfirm();
|
|
263
|
+
if (confirm !== void 0 && await confirm(`${entry.href} redirects to ${destination.href} (${chain}). Audit ${destination.href} instead?`)) because = "prompt";
|
|
264
|
+
}
|
|
265
|
+
if (because === void 0) {
|
|
266
|
+
fail(`${entry.href} redirects to ${destination.href} (${chain}), ${sameSite ? "the same site at another address" : "which is a different site"}, so nothing was audited.`);
|
|
267
|
+
note(mode === "stop" ? " --redirects stop was asked for, so the redirect was not followed." : " eaa-kit only follows a redirect to another site when you agree to it: otherwise the\n report would describe a site you did not name.");
|
|
268
|
+
const remote = options.allowRemote ? " --allow-remote" : "";
|
|
269
|
+
nextStep({
|
|
270
|
+
command: `eaa-kit audit --url ${destination.href}${remote}`,
|
|
271
|
+
why: "audit the address it leads to"
|
|
272
|
+
});
|
|
273
|
+
nextStep({
|
|
274
|
+
command: `eaa-kit audit --url ${entry.href}${remote} --redirects follow`,
|
|
275
|
+
why: "or follow it on every run, and have each report say so"
|
|
276
|
+
});
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
let target;
|
|
280
|
+
try {
|
|
281
|
+
target = parseEntryUrl(destination.href, options.allowRemote ?? false);
|
|
282
|
+
} catch (cause) {
|
|
283
|
+
if (cause instanceof CrawlError) {
|
|
284
|
+
fail(`${entry.href} redirects to ${destination.href}.`);
|
|
285
|
+
failWith(cause);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
throw cause;
|
|
289
|
+
}
|
|
290
|
+
warn(`${entry.href} redirects to ${target.href} (${chain}). Auditing ${target.href}; every report says so.`);
|
|
291
|
+
return {
|
|
292
|
+
entry: target,
|
|
293
|
+
redirect: {
|
|
294
|
+
requested: entry.href,
|
|
295
|
+
auditedFrom: target.href,
|
|
296
|
+
statuses,
|
|
297
|
+
followedBecause: because
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
/** A yes/no question on the terminal, or nothing when there is no terminal to ask at. */
|
|
302
|
+
function terminalConfirm() {
|
|
303
|
+
if (process.stdin.isTTY !== true || process.stderr.isTTY !== true) return void 0;
|
|
304
|
+
return async (question) => {
|
|
305
|
+
const { createInterface } = await import("node:readline/promises");
|
|
306
|
+
const rl = createInterface({
|
|
307
|
+
input: process.stdin,
|
|
308
|
+
output: process.stderr
|
|
309
|
+
});
|
|
310
|
+
try {
|
|
311
|
+
const answer = await rl.question(`${question} (y/N) `);
|
|
312
|
+
return /^y(es)?$/i.test(answer.trim());
|
|
313
|
+
} finally {
|
|
314
|
+
rl.close();
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* No directory and no URL: work out what this project needs.
|
|
320
|
+
*
|
|
321
|
+
* The point is that `eaa-kit audit` on its own does something useful. Anything
|
|
322
|
+
* this starts is handed back as `cleanup` so the caller can stop it once the
|
|
323
|
+
* report is written.
|
|
324
|
+
*/
|
|
325
|
+
async function resolveAutomatically(options) {
|
|
326
|
+
const cwd = options.cwd ?? process.cwd();
|
|
327
|
+
const { autoDetectSource } = await import("./project-Dht13sb1.js");
|
|
328
|
+
const detected = await autoDetectSource(cwd, {
|
|
329
|
+
...options.noBuild ? { noBuild: true } : {},
|
|
330
|
+
onStep: note
|
|
331
|
+
});
|
|
332
|
+
if (detected?.directory !== void 0) return resolvePages(detected.directory, {
|
|
333
|
+
...options,
|
|
334
|
+
label: path.relative(cwd, detected.directory) || "."
|
|
335
|
+
});
|
|
336
|
+
if (detected?.url !== void 0) {
|
|
337
|
+
const resolved = await resolvePages(void 0, {
|
|
338
|
+
...options,
|
|
339
|
+
url: detected.url,
|
|
340
|
+
...detected.seeds === void 0 ? {} : { seeds: detected.seeds },
|
|
341
|
+
...detected.unreachable === void 0 ? {} : { knownUnreachable: detected.unreachable }
|
|
342
|
+
});
|
|
343
|
+
if (resolved === void 0) {
|
|
344
|
+
await detected.cleanup?.();
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
return {
|
|
348
|
+
...resolved,
|
|
349
|
+
...detected.cleanup ? { cleanup: detected.cleanup } : {}
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
await detected?.cleanup?.();
|
|
353
|
+
if (detected?.sites !== void 0) {
|
|
354
|
+
warn("Choose which site to audit, and run the audit inside it:");
|
|
355
|
+
for (const site of detected.sites) nextStep({
|
|
356
|
+
command: `cd ${site} && npx eaa-kit`,
|
|
357
|
+
why: ""
|
|
358
|
+
});
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
warn(await emptyDirectoryHint("./dist", cwd));
|
|
362
|
+
}
|
|
363
|
+
export { resolvePages as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { c as pageUrl, d as runOptions, f as shapeResults, n as DEFAULT_TAGS, o as failedPage } from "./result-g8dGsrcv.js";
|
|
2
|
+
import { r as isFile } from "./fs-tPD5r0wY.js";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { stat } from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
@@ -7,7 +7,7 @@ import { pathToFileURL } from "node:url";
|
|
|
7
7
|
import axe from "axe-core";
|
|
8
8
|
import { createReadStream } from "node:fs";
|
|
9
9
|
import { createServer } from "node:http";
|
|
10
|
-
|
|
10
|
+
// src/audit/serve.ts
|
|
11
11
|
/**
|
|
12
12
|
* Content types for what a static build actually contains. Anything else is
|
|
13
13
|
* served as an octet-stream, which is fine: the browser only needs to parse
|
|
@@ -109,8 +109,7 @@ function closeServer(server) {
|
|
|
109
109
|
server.close(() => resolve());
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
//#region src/audit/runners/playwright.ts
|
|
112
|
+
// src/audit/runners/playwright.ts
|
|
114
113
|
/** Per-page ceiling. Real pages fetch real resources, so it is looser. */
|
|
115
114
|
const DEFAULT_TIMEOUT_MS = 6e4;
|
|
116
115
|
var BrowserUnavailableError = class extends Error {
|
|
@@ -165,9 +164,13 @@ async function runBrowserAudit(directory, pages, options = {}) {
|
|
|
165
164
|
try {
|
|
166
165
|
const context = await browser.newContext({
|
|
167
166
|
viewport,
|
|
168
|
-
bypassCSP: true
|
|
169
|
-
...options.headers === void 0 ? {} : { extraHTTPHeaders: options.headers }
|
|
167
|
+
bypassCSP: true
|
|
170
168
|
});
|
|
169
|
+
if (options.headers !== void 0) {
|
|
170
|
+
const credentials = options.headers;
|
|
171
|
+
const origins = siteOrigins(pages, server?.origin);
|
|
172
|
+
await context.route("**/*", credentialsRoute(origins, credentials));
|
|
173
|
+
}
|
|
171
174
|
const audits = Array.from({ length: pages.length });
|
|
172
175
|
const lanes = Math.max(1, Math.min(options.concurrency ?? DEFAULT_CONCURRENCY, pages.length));
|
|
173
176
|
let next = 0;
|
|
@@ -238,6 +241,60 @@ function servedUrl(origin, relativePath) {
|
|
|
238
241
|
return `${origin}/${relativePath.split("/").map(encodeURIComponent).join("/")}`;
|
|
239
242
|
}
|
|
240
243
|
/**
|
|
244
|
+
* A route handler that adds `credentials` to requests for `origins`, and to
|
|
245
|
+
* nothing else, redirects included.
|
|
246
|
+
*
|
|
247
|
+
* Requests to the site are fetched here and handed back, not continued with
|
|
248
|
+
* the headers added: Playwright carries a continued request's header
|
|
249
|
+
* overrides onto every redirect hop, so a page or asset on the site that
|
|
250
|
+
* redirected elsewhere took the credentials with it. With no redirects
|
|
251
|
+
* followed here, a 3xx goes back to the browser, which follows it as a new
|
|
252
|
+
* request; that one is routed again, and leaves the site bare.
|
|
253
|
+
*
|
|
254
|
+
* One side effect, on the safe side: Chromium treats a document handed back
|
|
255
|
+
* this way as public, so it may not load assets from another loopback or
|
|
256
|
+
* private address. Turning that check off would let an audited page probe the
|
|
257
|
+
* network of the machine running the audit.
|
|
258
|
+
*/
|
|
259
|
+
function credentialsRoute(origins, credentials) {
|
|
260
|
+
return async (route) => {
|
|
261
|
+
const request = route.request();
|
|
262
|
+
if (!origins.has(originOf(request.url()))) return route.continue();
|
|
263
|
+
try {
|
|
264
|
+
const response = await route.fetch({
|
|
265
|
+
headers: {
|
|
266
|
+
...request.headers(),
|
|
267
|
+
...credentials
|
|
268
|
+
},
|
|
269
|
+
maxRedirects: 0
|
|
270
|
+
});
|
|
271
|
+
return await route.fulfill({ response });
|
|
272
|
+
} catch {
|
|
273
|
+
return route.abort();
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* The origins credentials may go to: those of the crawled pages, which a crawl
|
|
279
|
+
* keeps to one origin, and the loopback server for a build off disk.
|
|
280
|
+
*/
|
|
281
|
+
function siteOrigins(pages, serverOrigin) {
|
|
282
|
+
const origins = /* @__PURE__ */ new Set();
|
|
283
|
+
if (serverOrigin !== void 0) origins.add(serverOrigin);
|
|
284
|
+
for (const page of pages) {
|
|
285
|
+
const origin = originOf(page.absolutePath);
|
|
286
|
+
if (origin.startsWith("http")) origins.add(origin);
|
|
287
|
+
}
|
|
288
|
+
return origins;
|
|
289
|
+
}
|
|
290
|
+
function originOf(url) {
|
|
291
|
+
try {
|
|
292
|
+
return new URL(url).origin;
|
|
293
|
+
} catch {
|
|
294
|
+
return "null";
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
241
298
|
* A launch that failed because the browser was never downloaded, told as setup.
|
|
242
299
|
*
|
|
243
300
|
* The third setup failure, and the only one that used to arrive as a crash.
|
|
@@ -268,10 +325,19 @@ function launchFailure(cause) {
|
|
|
268
325
|
async function loadChromium(cwd = process.cwd()) {
|
|
269
326
|
const tried = [];
|
|
270
327
|
const specifiers = ["playwright", "@playwright/test"];
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
328
|
+
const passes = [
|
|
329
|
+
{
|
|
330
|
+
root: cwd,
|
|
331
|
+
installedIn: cwd
|
|
332
|
+
},
|
|
333
|
+
{ root: cwd },
|
|
334
|
+
{ root: void 0 }
|
|
335
|
+
];
|
|
336
|
+
const seen = /* @__PURE__ */ new Set();
|
|
337
|
+
for (const { root, installedIn } of passes) for (const specifier of specifiers) {
|
|
338
|
+
const loaded = await tryLoad(specifier, root, installedIn);
|
|
339
|
+
if (loaded === void 0 || seen.has(loaded)) continue;
|
|
340
|
+
seen.add(loaded);
|
|
275
341
|
tried.push(`${specifier}${root === void 0 ? " (from eaa-kit)" : ""}`);
|
|
276
342
|
const chromium = launcherIn(loaded);
|
|
277
343
|
if (chromium !== void 0) return chromium;
|
|
@@ -282,16 +348,33 @@ async function loadChromium(cwd = process.cwd()) {
|
|
|
282
348
|
npx playwright install chromium --force`);
|
|
283
349
|
}
|
|
284
350
|
/** Import a specifier, resolved from `root` when given. Undefined if absent. */
|
|
285
|
-
async function tryLoad(specifier, root) {
|
|
351
|
+
async function tryLoad(specifier, root, installedIn) {
|
|
286
352
|
try {
|
|
287
353
|
if (root === void 0) return await import(specifier);
|
|
288
|
-
const
|
|
289
|
-
|
|
354
|
+
const resolved = createRequire(pathToFileURL(path.join(root, "package.json")).href).resolve(specifier);
|
|
355
|
+
if (installedIn !== void 0 && !isInstalledFor(resolved, installedIn)) return void 0;
|
|
356
|
+
return await import(pathToFileURL(resolved).href);
|
|
290
357
|
} catch {
|
|
291
358
|
return;
|
|
292
359
|
}
|
|
293
360
|
}
|
|
294
361
|
/**
|
|
362
|
+
* Whether a resolved file came from the project's own dependencies: a
|
|
363
|
+
* node_modules directory in the project or above it (a monorepo hoists to its
|
|
364
|
+
* root), or Yarn's cache, which is where Plug'n'Play keeps them.
|
|
365
|
+
*/
|
|
366
|
+
function isInstalledFor(resolved, project, paths = path) {
|
|
367
|
+
const fold = paths.sep === "\\" ? (value) => value.toLowerCase() : (value) => value;
|
|
368
|
+
const file = fold(paths.resolve(resolved));
|
|
369
|
+
let dir = fold(paths.resolve(project));
|
|
370
|
+
for (;;) {
|
|
371
|
+
for (const store of ["node_modules", ".yarn"]) if (file.startsWith(paths.join(dir, store) + paths.sep)) return true;
|
|
372
|
+
const parent = paths.dirname(dir);
|
|
373
|
+
if (parent === dir) return false;
|
|
374
|
+
dir = parent;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
295
378
|
* The chromium launcher, whichever shape the module came back in.
|
|
296
379
|
*
|
|
297
380
|
* Playwright is CommonJS. Whether `await import()` of it exposes named exports
|
|
@@ -314,5 +397,4 @@ function launcherIn(module) {
|
|
|
314
397
|
if (chromium !== void 0 && typeof chromium.launch === "function") return chromium;
|
|
315
398
|
}
|
|
316
399
|
}
|
|
317
|
-
|
|
318
|
-
export { BrowserUnavailableError, runBrowserAudit };
|
|
400
|
+
export { BrowserUnavailableError, loadChromium, runBrowserAudit };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { r as isFile } from "./fs-
|
|
2
|
-
import { c as pageUrl, o as failedPage } from "./result-
|
|
1
|
+
import { r as isFile } from "./fs-tPD5r0wY.js";
|
|
2
|
+
import { c as pageUrl, o as failedPage } from "./result-g8dGsrcv.js";
|
|
3
3
|
import { Worker } from "node:worker_threads";
|
|
4
4
|
import { availableParallelism } from "node:os";
|
|
5
|
-
|
|
5
|
+
// src/audit/runners/pool.ts
|
|
6
6
|
/**
|
|
7
7
|
* Audit pages across worker threads.
|
|
8
8
|
*
|
|
@@ -110,7 +110,7 @@ async function runPooledAudit(pages, options = {}) {
|
|
|
110
110
|
* for pages the threads never reported on.
|
|
111
111
|
*/
|
|
112
112
|
async function auditHere(pages, options) {
|
|
113
|
-
const { runJsdomAudit } = await import("./jsdom-
|
|
113
|
+
const { runJsdomAudit } = await import("./jsdom-Zle--VQ1.js");
|
|
114
114
|
return runJsdomAudit(pages, options);
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
@@ -230,5 +230,4 @@ async function findWorkerEntry() {
|
|
|
230
230
|
];
|
|
231
231
|
for (const candidate of candidates) if (await isFile(candidate)) return candidate;
|
|
232
232
|
}
|
|
233
|
-
//#endregion
|
|
234
233
|
export { plannedWorkers, runPooledAudit };
|