Public: anyone can read this; the crew can change it.
An app.looks path with a backslash never sends the page fetch to another host #14981
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14957-an-app-looks-path-with-a-backslash-never → main 4 commits fork 4 threads · 4 unresolved
7 files
changed +74
−10
src/apps/manifest.ts +4
| @@ -458,6 +458,10 @@ function pathList( | ||
| 458 | 458 | return invalid( |
| 459 | 459 | `forge.json: ${field} entries must be a path starting with / (no scheme, no host)`, |
| 460 | 460 | ); |
| 461 | if (item.includes("\\")) | |
| 462 | return invalid( | |
| 463 | `forge.json: ${field} entries must not contain \\ (it can name another host)`, | |
| 464 | ); | |
| 461 | 465 | if (item.includes("..")) |
| 462 | 466 | return invalid(`forge.json: ${field} entries must not contain ..`); |
| 463 | 467 | if (/[\x00-\x1f\x7f]/.test(item)) |
src/kernel/same_path.ts added +25
| @@ -0,0 +1,25 @@ | ||
| 1 | /** | |
| 2 | * A page path an app names (`app.looks`, `app.looksAsOwner`) is the app's own, | |
| 3 | * never another host's: `/\evil.example` and `//evil.example` resolve to a | |
| 4 | * different origin under the WHATWG URL parser (#14957). One rule, used where | |
| 5 | * forge.json is read and again by every fetcher of those paths. | |
| 6 | */ | |
| 7 | ||
| 8 | /** True when `path` starts with exactly one `/` and holds no `\` or control character. */ | |
| 9 | export function samePath(path: string): boolean { | |
| 10 | return path.startsWith("/") && !path.startsWith("//") && !/[\\\x00-\x1f\x7f]/.test(path); | |
| 11 | } | |
| 12 | ||
| 13 | /** | |
| 14 | * The URL `path` names on `base`, or null when the path breaks `samePath` or the URL leaves | |
| 15 | * `base`'s origin. | |
| 16 | */ | |
| 17 | export function sameOriginUrl(path: string, base: string): string | null { | |
| 18 | if (!samePath(path)) return null; | |
| 19 | try { | |
| 20 | const url = new URL(path, base); | |
| 21 | return url.origin === new URL(base).origin ? url.href : null; | |
| 22 | } catch { | |
| 23 | return null; | |
| 24 | } | |
| 25 | } |
src/release/axe.ts +10 −5
| @@ -17,6 +17,7 @@ | ||
| 17 | 17 | import { findChromium } from "../looks/capture.ts"; |
| 18 | 18 | import { withPage } from "./devtools.ts"; |
| 19 | 19 | import { s, type Finding } from "./webspec.ts"; |
| 20 | import { sameOriginUrl } from "../kernel/same_path.ts"; | |
| 20 | 21 | |
| 21 | 22 | const SCHEMES = ["light", "dark"] as const; |
| 22 | 23 | |
| @@ -54,8 +55,10 @@ export function noScriptProblems(html: string): string[] { | ||
| 54 | 55 | export async function noScript(base: string, paths: string[], fetcher: typeof fetch = fetch): Promise<Finding[]> { |
| 55 | 56 | const findings: Finding[] = []; |
| 56 | 57 | for (const path of paths) { |
| 58 | const url = sameOriginUrl(path, base); | |
| 59 | if (url === null) continue; // webspec() reports a path that is not the app's (#14957) | |
| 57 | 60 | try { |
| 58 | const res = await fetcher(new URL(path, base).href, { headers: { accept: "text/html" }, redirect: "manual", signal: AbortSignal.timeout(10000) }); | |
| 61 | const res = await fetcher(url, { headers: { accept: "text/html" }, redirect: "manual", signal: AbortSignal.timeout(10000) }); | |
| 59 | 62 | if (!res.ok) continue; // webspec() already reports the status |
| 60 | 63 | for (const message of noScriptProblems(await res.text())) |
| 61 | 64 | findings.push({ path, check: "no-js", message, section: s("progressive-enhancement") }); |
| @@ -75,16 +78,18 @@ export async function axe(base: string, paths: string[]): Promise<Finding[]> { | ||
| 75 | 78 | try { |
| 76 | 79 | await withPage(binary, async (send, once) => { |
| 77 | 80 | await send("Page.enable"); |
| 78 | const load = async (path: string) => { | |
| 81 | const load = async (url: string) => { | |
| 79 | 82 | const loaded = once("Page.loadEventFired"); |
| 80 | 83 | loaded.catch(() => {}); |
| 81 | await send("Page.navigate", { url: new URL(path, base).href }); | |
| 84 | await send("Page.navigate", { url }); | |
| 82 | 85 | await loaded; |
outdated
The |
||
| 83 | 86 | }; |
| 84 | 87 | for (const path of paths) { |
| 88 | const url = sameOriginUrl(path, base); | |
| 89 | if (url === null) continue; // webspec() reports it (#14957) | |
| 85 | 90 | try { |
| 86 | 91 | await send("Emulation.setScriptExecutionDisabled", { value: true }); |
| 87 | await load(path); | |
| 92 | await load(url); | |
| 88 | 93 | const dom = await send("Runtime.evaluate", { expression: "document.documentElement.outerHTML", returnByValue: true }); |
| 89 | 94 | for (const message of noScriptProblems(`<!doctype html>${dom.result.value}`)) |
| 90 | 95 | findings.push({ path, check: "no-js", message, section: s("progressive-enhancement") }); |
| @@ -96,7 +101,7 @@ export async function axe(base: string, paths: string[]): Promise<Finding[]> { | ||
| 96 | 101 | for (const scheme of SCHEMES) { |
| 97 | 102 | try { |
| 98 | 103 | await send("Emulation.setEmulatedMedia", { features: [{ name: "prefers-color-scheme", value: scheme }] }); |
| 99 | await load(path); | |
| 104 | await load(url); | |
| 100 | 105 | const res = await send("Runtime.evaluate", { |
| 101 | 106 | expression: `${source};axe.run(document,{resultTypes:["violations"]}).then(r=>JSON.stringify(r.violations))`, |
| 102 | 107 | awaitPromise: true, |
src/release/webspec.ts +5 −5
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | import { siteFindings } from "./webspec-site.ts"; |
| 10 | import { sameOriginUrl } from "../kernel/same_path.ts"; | |
| 10 | 11 | |
| 11 | 12 | export interface Finding { |
| 12 | 13 | path: string; |
| @@ -221,11 +222,10 @@ export async function webspec(base: string, paths: string[], fetcher: Fetcher = | ||
| 221 | 222 | const report = (ps: Problem[]) => { |
| 222 | 223 | for (const p of ps) findings.push({ path, ...p }); |
| 223 | 224 | }; |
| 224 | let url: string; | |
| 225 | try { | |
| 226 | url = new URL(path, base).href; | |
| 227 | } catch { | |
| 228 | report([{ check: "fetch", message: `${path} is not a URL`, section: SPEC }]); | |
| 225 | // A path is the app's to name, never another host's (#14957). | |
| 226 | const url = sameOriginUrl(path, base); | |
| 227 | if (url === null) { | |
| 228 | report([{ check: "fetch", message: `${JSON.stringify(path)} is not a path on this app; it was not fetched`, section: SPEC }]); | |
| 229 | 229 | continue; |
| 230 | 230 | } |
| 231 | 231 | let res: Response; |
test/apps-adversarial.test.ts +12
| @@ -401,6 +401,18 @@ describe("manifest: parseManifest edge cases", () => { | ||
| 401 | 401 | } |
| 402 | 402 | }); |
| 403 | 403 | |
| 404 | test("an app.looks or app.looksAsOwner entry with a backslash is refused: /\\evil.example is another host (#14957)", () => { | |
| 405 | for (const app of [ | |
| 406 | { run: "x", looks: ["/\\evil.example"] }, | |
| 407 | { run: "x", looks: ["/", "/a\\b"] }, | |
| 408 | { run: "x", looks: ["/"], looksAsOwner: ["/\\evil.example"] }, | |
| 409 | ]) { | |
| 410 | const result = parseManifest(JSON.stringify({ app }), undefined); | |
| 411 | expect(result.ok).toBe(false); | |
| 412 | if (!result.ok && result.error.kind === "invalid") expect(result.error.message).toContain("must not contain \\"); | |
| 413 | } | |
| 414 | }); | |
| 415 | ||
| 404 | 416 | test("an over-long app.looks entry is refused", () => { |
| 405 | 417 | const result = parseManifest( |
| 406 | 418 | JSON.stringify({ app: { run: "x", looks: [`/${"a".repeat(300)}`] } }), |
test/axe.test.ts +7
| @@ -24,6 +24,13 @@ test("a page that fills <main> from a script is a no-js finding; a rendered one | ||
| 24 | 24 | expect(found[0]!.section).toContain("specification.website"); |
| 25 | 25 | }); |
| 26 | 26 | |
| 27 | test("noScript never fetches a path that leaves the app's origin (#14957)", async () => { | |
| 28 | const asked: string[] = []; | |
| 29 | const f = (async (input: string) => (asked.push(input), new Response(PAGES["/script"]!))) as unknown as typeof fetch; | |
| 30 | expect(await noScript(base, ["/\\evil.example", "//evil.example", "https://evil.example/"], f)).toEqual([]); | |
| 31 | expect(asked).toEqual([]); | |
| 32 | }); | |
| 33 | ||
| 27 | 34 | test("noScriptProblems names a missing main and heading", () => { |
| 28 | 35 | expect(noScriptProblems("<body>x</body>")).toEqual(["the page has no <main>", "no main heading (<h1>) without JavaScript"]); |
| 29 | 36 | }); |
test/webspec.test.ts +11
| @@ -241,3 +241,14 @@ test("#14755: a preview's HTML cannot aim the checker at a private or metadata a | ||
| 241 | 241 | expect(off.join("\n")).toContain("169.254.169.254"); |
| 242 | 242 | expect(found.some((f) => f.check === "head-links" && f.message.includes("169.254"))).toBe(false); |
| 243 | 243 | }); |
| 244 | ||
| 245 | test("a looks path that would leave the app's origin is refused, never fetched (#14957)", async () => { | |
| 246 | const asked: string[] = []; | |
| 247 | const f = async (input: string) => (asked.push(input), new Response(GOOD_HTML, { headers: GOOD_HEADERS })); | |
| 248 | for (const path of ["/\\evil.example", "//evil.example", "https://evil.example/", "evil", "/a\nb", "/a\tb"]) { | |
| 249 | const found = await webspec("https://x.test", [path], f); | |
| 250 | expect(found.map((x) => x.check)).toEqual(["fetch"]); | |
| 251 | expect(found[0]!.message).toContain("not a path on this app"); | |
| 252 | } | |
| 253 | expect(asked).toEqual([]); | |
| 254 | }); |
new above
offline
This line is over 100 columns, and the gate reports it. Wrap it. The
\u0000-\u001frange is also written differently from the\x00-\x1fform in manifest.ts. Use one form.