Public: anyone can read this; the crew can change it.
A signed-out 404 offers sign-in back to the same address, and /go/:code's dead-code 404 stays one page #4156
scout/forge:scout/4139-a-signed-out-404-offers-sign-in-back-to → main 2 commits fork 1 thread · 1 unresolved
3 files
changed +24
−5
src/http/server.ts +1 −1
| @@ -960,7 +960,7 @@ export function buildRouter(): Router<Handler> { | ||
| 960 | 960 | ctx.app.config.dataDir, |
| 961 | 961 | ctx.params.code ?? "", |
| 962 | 962 | ); |
| 963 | if (target === undefined) return notFoundPage(ctx); | |
| 963 | if (target === undefined) return notFoundPage(ctx, { plain: true }); | |
| 964 | 964 | return new Response(null, { |
| 965 | 965 | status: 303, |
| 966 | 966 | headers: { location: target, "cache-control": "no-store" }, |
src/web/chrome.ts +9 −3
| @@ -66,8 +66,12 @@ export function crumbsFor(repo: Repo): { label: string; href: string }[] { | ||
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** The one 404 in the product: same words for "no such thing" and "not |
| 69 | * yours to see". */ | |
| 70 | export function notFoundPage(ctx: Ctx): Response { | |
| 69 | * yours to see". With no session, on a GET, it also offers sign-in back to | |
| 70 | * this address; `plain` leaves that out for a miss that must reveal nothing | |
| 71 | * (a dead `/go/:code`). */ | |
| 72 | export function notFoundPage(ctx: Ctx, opts: { plain?: boolean } = {}): Response { | |
| 73 | const offerSignIn = | |
| 74 | !opts.plain && ctx.auth.user === undefined && ctx.request.method === "GET"; | |
| 71 | 75 | return page( |
| 72 | 76 | { |
| 73 | 77 | ctx, |
| @@ -77,7 +81,9 @@ export function notFoundPage(ctx: Ctx): Response { | ||
| 77 | 81 | icon: "search", |
| 78 | 82 | title: "Nothing here", |
| 79 | 83 | note: "The page you asked for does not exist, or is not visible to you.", |
| 80 | action: btn("Go home", { href: "/", variant: "primary" }), | |
| 84 | action: offerSignIn | |
| 85 | ? btn("Sign in", { href: signInHref(ctx), variant: "primary" }) | |
| 86 | : btn("Go home", { href: "/", variant: "primary" }), | |
| 81 | 87 | })}`, |
| 82 | 88 | }, |
| 83 | 89 | 404, |
test/web-ui.test.ts +14 −1
| @@ -299,10 +299,23 @@ describe("web ui", () => { | ||
| 299 | 299 | const scrub = (t: string) => |
| 300 | 300 | t |
| 301 | 301 | .replaceAll(/nonce-?="?[\w-]+/g, "nonce") |
| 302 | .replaceAll(/here\?path=[^"&\s]*/g, "here?path="); | |
| 302 | .replaceAll(/here\?path=[^"&\s]*/g, "here?path=") | |
| 303 | .replaceAll(/signin\?next=[^"&\s]*/g, "signin?next="); | |
| 303 | 304 | expect(scrub(await hidden.text())).toBe(scrub(await absent.text())); |
| 304 | 305 | }); |
| 305 | 306 | |
| 307 | test("a signed-out 404 offers sign-in back to the same address", async () => { | |
| 308 | const path = "/kim/secret/raw/main/a.txt?x=1"; | |
| 309 | const out = await (await fetch(`${base}${path}`)).text(); | |
| 310 | expect(out).toContain(`href="/signin?next=${encodeURIComponent(path)}"`); | |
| 311 | expect(out).not.toContain("Go home"); | |
| 312 | const inn = await fetch(`${base}${path}`, { headers: { cookie: stranger } }); | |
| 313 | expect(inn.status).toBe(404); | |
| 314 | const innText = await inn.text(); | |
| 315 | expect(innText).not.toContain("/signin?next="); | |
| 316 | expect(innText).toContain("Go home"); | |
| 317 | }); | |
| 318 | ||
| 306 | 319 | // ---- ref safety ---- |
| 307 | 320 | |
| 308 | 321 | test("tree and commits refuse a ref that is not a ref", async () => { |
new above
offline
Two buttons in
empty()break DESIGN.md §5 and review rule 6 ("The empty state has exactly one button"). Signed out, make the one actionSign in(primary,signInHref(ctx)); otherwise keepGo home. The topbar's brand mark already leads home.