Public: anyone can read this; the crew can change it.
Signed out, /new-forge says how to start instead of answering 404 #13075
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13070-signed-out-new-forge-says-how-to-start-i → main 3 commits fork 1 thread · 1 unresolved
2 files
changed +27
−0
src/http/server.ts +6
| @@ -313,6 +313,7 @@ import { forgeItSubmit } from "../web/pages/forge-it.ts"; | ||
| 313 | 313 | import { funnelSubmit } from "./funnel.ts"; |
| 314 | 314 | import { pricingDone, pricingOrder, pricingPage, resendPage, resendSubmit } from "../web/pages/pricing.ts"; |
| 315 | 315 | import { startForgeSubmit } from "../web/pages/start-forge.ts"; |
| 316 | import { redirect } from "../web/layout.ts"; | |
| 316 | 317 | import { newForgePage, newForgeSubmit } from "../web/pages/new-forge.ts"; |
| 317 | 318 | import { askedPage } from "../web/studio/asked_page.ts"; |
| 318 | 319 | import { notesOverrule, notesSave, notesView } from "../web/pages/notes.ts"; |
| @@ -3257,6 +3258,11 @@ async function answerGet( | ||
| 3257 | 3258 | const adminRefusal = adminGate(app, request, url, auth, matched.pattern); |
| 3258 | 3259 | if (adminRefusal !== undefined) return adminRefusal; |
| 3259 | 3260 | |
| 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}`); | |
| 3265 | ||
| 3260 | 3266 | // A transferred repository's old path answers 308 to its new one (#569). |
| 3261 | 3267 | const moved = movedResponse(app.db, url, auth.user, request.method); |
| 3262 | 3268 | 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 | ||
| 72 | 72 | expect(text).toContain("alice/yard"); |
| 73 | 73 | expect(text).toContain("apps to start from"); |
| 74 | 74 | }); |
| 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 | }); |
new above
offline
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.