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

/login and /sign-in send you to /signin, keeping where you were going #7702

Parked opened this
Closed without merging

scout/forge:scout/6038-login-and-sign-in-send-you-to-signin-kee → main 7 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
6 files changed +65 −2
src/http/server.ts +3
@@ -120,6 +120,7 @@ import {
120120 logoutSubmit,
121121 newRepoPage,
122122 newRepoSubmit,
123 signinAlias,
123124 signinPage,
124125 signinSubmit,
125126 signupPage,
@@ -744,6 +745,8 @@ export function buildRouter(): Router<Handler> {
744745 router.add("GET", "/home/archived/:op", homeArchived);
745746 router.add("POST", "/home/archived/:op/undo", homeArchiveUndo);
746747 router.add("GET", "/signin", signinPage);
748 router.add("GET", "/login", signinAlias);
749 router.add("GET", "/sign-in", signinAlias);
747750 router.add("POST", "/signin", signinSubmit);
748751 router.add("GET", "/signin/parent", parentStart);
749752 router.add("GET", "/signin/parent/callback", parentCallback);
src/web/pages/site.ts +7
@@ -440,6 +440,13 @@ export function signinPage(ctx: Ctx): Response {
440440 );
441441 }
442442
443 /** `/login` and `/sign-in` are what people type: 308 to `/signin`, `next` kept only when `safeNext` allows it. */
444 export function signinAlias(ctx: Ctx): Response {
445 const next = safeNext(ctx.url.searchParams.get("next"));
446 const to = next === undefined ? "/signin" : `/signin?next=${encodeURIComponent(next)}`;
447 return new Response(null, { status: 308, headers: { location: to } });
448 }
449
443450 /** The widget's public site key, when signup is gated on Turnstile. */
444451 function siteKey(ctx: Ctx): string | undefined {
445452 const { turnstileSecret, turnstileSiteKey } = ctx.app.config;
test/crew-team-scorecard.test.ts +2 −2
@@ -31,7 +31,7 @@ describe("a scorecard row per team", () => {
3131 function pull(author: string, title: string, merged: boolean, hours = 2, openedAt?: string) {
3232 const issue = createIssue(app.db, { repoId, authorId: ids[author]!, title, kind: "pull" });
3333 if (!issue.ok) throw new Error(issue.error);
34 const opened = openedAt ?? "2026-10-01T00:00:00.000Z";
34 const opened = openedAt ?? new Date(Date.now() - 2 * 86_400_000).toISOString(); // inside the 30-day window whenever this runs
3535 app.db.query(`UPDATE issue SET created_at = ?2 WHERE id = ?1`).run(issue.value.id, opened);
3636 const mergedAt = merged ? new Date(Date.parse(opened) + hours * 3_600_000).toISOString() : null;
3737 app.db
@@ -114,7 +114,7 @@ describe("a scorecard row per team", () => {
114114 expect(cards.has(three!)).toBe(false);
115115 // The members' own cards are unchanged by pooling.
116116 expect(crewScorecards(app.db).get(ids.a1!)!.reviewRounds).toBe(1);
117 // Oct 1 is inside the last 30 days; the idle team is still absent.
117 // Two days ago is inside the last 30 days; the idle team is still absent.
118118 expect(teamScorecards(app.db, recentWindow()).has(three!)).toBe(false);
119119 });
120120
test/forge-looks.test.ts +2
@@ -40,6 +40,8 @@ const NOT_A_PAGE: Record<string, string> = {
4040 "/asks": "redirects to /#needs-you",
4141 "/big": "redirects to /board?wall",
4242 "/flow": "redirects to /boards",
43 "/login": "redirects to /signin",
44 "/sign-in": "redirects to /signin",
4345 "/mcp": "a protocol endpoint, answers 405 to a GET",
4446 "/_measure": "the page-load beacon, a POST endpoint",
4547 "/events": "a live event stream that never ends",
test/server-timing-sweep.test.ts +2
@@ -44,8 +44,10 @@ const REDIRECTS = new Set([
4444 "/alice/forge/tells/new",
4545 "/big",
4646 "/flow",
47 "/login",
4748 "/settings/origins/callback",
4849 "/settings/resilience",
50 "/sign-in",
4951 ]);
5052
5153 /** Every GET pattern the router source registers, one-line or wrapped. */
test/signin-alias.test.ts added +49
@@ -0,0 +1,49 @@
1 /** `/login` and `/sign-in` send you to `/signin`, keeping a same-origin `next` (#6038). */
2 import { afterAll, beforeAll, expect, test } from "bun:test";
3 import { mkdtemp, rm } from "node:fs/promises";
4 import { tmpdir } from "node:os";
5 import { join } from "node:path";
6 import { createApp, type App } from "../src/app.ts";
7 import { serve, type Servers } from "../src/http/server.ts";
8
9 let dataDir = "";
10 let app: App;
11 let servers: Servers;
12
13 beforeAll(async () => {
14 dataDir = await mkdtemp(join(tmpdir(), "forge-signin-alias-"));
15 app = createApp({ dataDir, port: 0, url: "https://forge.example" });
16 servers = await serve(app);
17 });
18 afterAll(async () => {
19 await servers.stop();
20 app.close();
21 await rm(dataDir, { recursive: true, force: true });
22 });
23
24 const go = (path: string) => fetch(`${servers.url}${path}`, { redirect: "manual" });
25
26 for (const alias of ["/login", "/sign-in"]) {
27 test(`${alias} answers 308 to /signin`, async () => {
28 const res = await go(alias);
29 expect(res.status).toBe(308);
30 expect(res.headers.get("location")).toBe("/signin");
31 });
32 test(`${alias} keeps a same-origin next`, async () => {
33 const res = await go(`${alias}?next=/settings`);
34 expect(res.status).toBe(308);
35 expect(res.headers.get("location")).toBe("/signin?next=%2Fsettings");
36 });
37 test(`${alias} drops an off-site next`, async () => {
38 for (const bad of ["//evil.test", "https://evil.test"]) {
39 const res = await go(`${alias}?next=${encodeURIComponent(bad)}`);
40 expect(res.status).toBe(308);
41 expect(res.headers.get("location")).toBe("/signin");
42 }
43 });
44 }
45
46 test("/signup is untouched", async () => {
47 const res = await go("/signup");
48 expect(res.status).not.toBe(308);
49 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs