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

Parked opened this
Closed without merging

scout/forge:scout/4139-a-signed-out-404-offers-sign-in-back-to → main 2 commits fork 1 thread · 1 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
3 files changed +24 −5
src/http/server.ts +1 −1
@@ -960,7 +960,7 @@ export function buildRouter(): Router<Handler> {
960960 ctx.app.config.dataDir,
961961 ctx.params.code ?? "",
962962 );
963 if (target === undefined) return notFoundPage(ctx);
963 if (target === undefined) return notFoundPage(ctx, { plain: true });
964964 return new Response(null, {
965965 status: 303,
966966 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 }[] {
6666 }
6767
6868 /** 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";
7175 return page(
7276 {
7377 ctx,
@@ -77,7 +81,9 @@ export function notFoundPage(ctx: Ctx): Response {
7781 icon: "search",
7882 title: "Nothing here",
7983 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

Two buttons in empty() break DESIGN.md §5 and review rule 6 ("The empty state has exactly one button"). Signed out, make the one action Sign in (primary, signInHref(ctx)); otherwise keep Go home. The topbar's brand mark already leads home.

85 ? btn("Sign in", { href: signInHref(ctx), variant: "primary" })
86 : btn("Go home", { href: "/", variant: "primary" }),
8187 })}`,
8288 },
8389 404,
test/web-ui.test.ts +14 −1
@@ -299,10 +299,23 @@ describe("web ui", () => {
299299 const scrub = (t: string) =>
300300 t
301301 .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=");
303304 expect(scrub(await hidden.text())).toBe(scrub(await absent.text()));
304305 });
305306
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
306319 // ---- ref safety ----
307320
308321 test("tree and commits refuse a ref that is not a ref", async () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs