Public: anyone can read this; the crew can change it.

Signed out, /new-forge says how to start instead of answering 404 #13075

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/13070-signed-out-new-forge-says-how-to-start-i → main 3 commits fork 1 thread · 1 unresolved

  • Merged. scout/13070-signed-out-new-forge-says-how-to-start-i was merged into main as 6b4bd0f.

Review

Sign in to review this change.
2 files changed +27 −0
src/http/server.ts +6
@@ -313,6 +313,7 @@ import { forgeItSubmit } from "../web/pages/forge-it.ts";
313313 import { funnelSubmit } from "./funnel.ts";
314314 import { pricingDone, pricingOrder, pricingPage, resendPage, resendSubmit } from "../web/pages/pricing.ts";
315315 import { startForgeSubmit } from "../web/pages/start-forge.ts";
316 import { redirect } from "../web/layout.ts";
316317 import { newForgePage, newForgeSubmit } from "../web/pages/new-forge.ts";
317318 import { askedPage } from "../web/studio/asked_page.ts";
318319 import { notesOverrule, notesSave, notesView } from "../web/pages/notes.ts";
@@ -3257,6 +3258,11 @@ async function answerGet(
32573258 const adminRefusal = adminGate(app, request, url, auth, matched.pattern);
32583259 if (adminRefusal !== undefined) return adminRefusal;
32593260
3261 // The short address people guess goes to the one form, which a stranger sees too. Not a page of
3262 // its own: one form, one route.
3263 if (url.pathname === "/new-forge" && (request.method === "GET" || request.method === "HEAD"))
3264 return redirect(`/forges/new${url.search}`);

Fine: GET/HEAD only, fixed target, query carried over. A 303 is slightly unusual for a GET alias (301/308 would be cacheable) but acceptable.

3265
32603266 // A transferred repository's old path answers 308 to its new one (#569).
32613267 const moved = movedResponse(app.db, url, auth.user, request.method);
32623268 if (moved !== undefined) return moved;
test/new-forge-stranger.test.ts +21
@@ -72,3 +72,24 @@ test("signed in with a forkable repository: the picker and its count show", asyn
7272 expect(text).toContain("alice/yard");
7373 expect(text).toContain("apps to start from");
7474 });
75
76 test("/new-forge signed out: goes to the one form, which answers 200 with the name field", async () => {
77 const res = await fetch(`${servers.url}/new-forge?name=hello`, { redirect: "manual" });
78 expect(res.status).toBe(303);
79 expect(res.headers.get("location")).toBe("/forges/new?name=hello");
80 const page = await fetch(`${servers.url}${res.headers.get("location")}`);
81 expect(page.status).toBe(200);
82 expect(await page.text()).toContain('name="name"');
83 });
84
85 test("/new-forge: the POST keeps its same-origin check and has no second route", async () => {
86 const res = await fetch(`${servers.url}/forges/new`, {
87 method: "POST",
88 headers: { origin: "https://evil.test", "content-type": "application/x-www-form-urlencoded" },
89 body: new URLSearchParams({ name: "zz-evil" }),
90 });
91 expect(res.status).toBeGreaterThanOrEqual(400);
92 const alias = await fetch(`${servers.url}/new-forge`, { method: "POST", redirect: "manual" });
93 expect(alias.status).not.toBe(303);
94 expect(alias.status).toBeGreaterThanOrEqual(400);
95 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs