Files
loki/scripts/test/project-go.ts
CatoandClaude Opus 5.5 d37efc4a87 fix(projects): /projects/go uses the public origin; the demo cannot invite or join (#1268)
* fix(projects): /projects/go redirects to the public origin

Signed in, /projects/go/<name> redirected to req.nextUrl.origin. Behind
Caddy that is the standalone server's own localhost:PORT, so on the live
site the browser was sent to a refused connection. Every local walk
passed because there the two origins are the same.

Redirect to appUrl() like the other route handlers, and add a check that
no route handler redirects to the request's own origin. It fails on the
old line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TNLstupcdvsPfTjy8yjR67

* fix(projects): the shared demo account cannot invite or join

The demo account is every visitor at once. Checking #1265 live, the demo
created a working invite link: anyone could have seated themselves on the
demo's projects, with their name in front of the next visitor, and the
demo accepting someone's link would hand their project to every visitor.

createProjectInvitation and acceptProjectInvitation refuse the demo at the
effect ("tenancy", the copy the sandbox already uses for team settings),
and both routes answer it as a 403 with that sentence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TNLstupcdvsPfTjy8yjR67

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-17 19:08:19 +02:00

51 lines
2.2 KiB
TypeScript

// Opening one of your projects by its name (src/lib/project-go.ts) — the link
// an agent can hand George without knowing the project's id.
import assert from "node:assert/strict";
import { readdirSync, readFileSync, statSync } from "node:fs";
import { join } from "node:path";
import { projectGoTarget, projectNameKey } from "../../src/lib/project-go";
const projects = [
{ name: "Loki", entityProjectId: "11111111-1111-4111-8111-111111111111" },
{ name: "Petvity", entityProjectId: "22222222-2222-4222-8222-222222222222" },
{ name: "unlinked", entityProjectId: null },
];
assert.equal(projectNameKey(" Pet-Vity "), "petvity");
assert.equal(
projectGoTarget(projects, "petvity", "people"),
"/projects/22222222-2222-4222-8222-222222222222#people",
"case and punctuation do not matter; the tab opens",
);
assert.equal(
projectGoTarget(projects, "PETVITY", null),
"/projects/22222222-2222-4222-8222-222222222222",
);
assert.equal(
projectGoTarget(projects, "petvity", "<script>"),
"/projects/22222222-2222-4222-8222-222222222222",
"only a known tab reaches the URL",
);
assert.equal(projectGoTarget(projects, "nope", "people"), "/projects", "no match: the list");
assert.equal(projectGoTarget(projects, "unlinked", null), "/projects", "no page to open");
assert.equal(projectGoTarget(projects, "", null), "/projects");
console.log("✓ project-go: a project opens by its name, never anyone else's");
// Every redirect a route handler makes must name the PUBLIC origin. The go
// route redirected to req.nextUrl.origin; behind Caddy that is the standalone
// server's own localhost:PORT, so the live site sent people to a refused
// connection while every local run (where the two are the same) passed.
{
const walk = (dir: string): string[] =>
readdirSync(dir).flatMap((f) => {
const p = join(dir, f);
return statSync(p).isDirectory() ? walk(p) : /route\.tsx?$/.test(f) ? [p] : [];
});
const root = join(__dirname, "..", "..", "src", "app");
const offenders = walk(root).filter((file) =>
/redirect\([^;]*(nextUrl\.origin|req(uest)?\.url)/s.test(readFileSync(file, "utf8")),
);
assert.deepEqual(offenders, [], "redirect to the request's own origin");
console.log("✓ no route handler redirects to the request's own origin");
}