Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesPull RequestsActionsSecurityInsightsSettings
✨ AI
More
claude/adoring-hopper-5x74bqclaude/affectionate-feynman-ykrf1hclaude/architecture-audit-design-wxprenclaude/build-status-update-3MXsfclaude/charming-meitner-mllb5rclaude/compare-gate-gluecron-s4mFQclaude/confident-faraday-tikcwbclaude/continue-work-XMTlIclaude/crontech-gluecron-deploy-7MIECclaude/crontech-platform-setup-SeKfwclaude/design-2026claude/ecstatic-ptolemy-jMdigclaude/enhance-github-integration-QNHdGclaude/fix-aa-loop-issue-PonMQclaude/fix-actions-and-processclaude/fix-desktop-errors-XqoW8claude/fix-red-workflowsclaude/fix-website-access-6FKJNclaude/gatetest-integration-hardeningclaude/github-audit-improvements-bDFr9claude/gluecron-launch-status-FoMRlclaude/hopeful-lamport-olfCTclaude/issue-to-pr-and-protectionsclaude/jolly-heisenberg-2sg1Qclaude/launch-preparation-QmTb6claude/new-session-xk1l7claude/plan-platform-architecture-kkN4yclaude/platform-analysis-roadmap-1nUGLclaude/platform-launch-assessment-8dWV8claude/polish-platform-release-AeDrUclaude/resume-previous-work-KzyLwclaude/review-crontech-handoff-qYEVqclaude/review-project-completeness-lHhS2claude/review-readme-docs-ulqPKclaude/serene-edison-rj87weclaude/setup-multi-repo-dev-BCwNQclaude/ship-fixes-and-tests-Jvz1cclaude/site-audit-competitive-pctlwgclaude/site-migration-vercel-XstpKclaude/standalone-product-repos-XHFTDcopilot/feat-smart-empty-states-keyboard-first-enhancementcopilot/feat-smart-morning-digest-review-context-restorecopilot/fix-and-process-workflowscopilot/update-ai-powered-code-reviewfeat/debt-mapfeat/push-policy-codeowners-hardeningfeat/smart-digest-contextfeat/stage-impactfeat/t1-secret-migrationfeat/u-polishfeat/w-self-hostfeat/w2-claude-configfix/agent-journey-orphan-sweepfix/audit-sweep-2026-07-26gatetest/auto-fix-1776586424172gatetest/auto-fix-1776586534814gatetest/auto-fix-1776590685143gatetest/auto-fix-1776590808199mainops/redeploy-retriggerstyle/dxt-cta-themeworktree-agent-a3377aad30d55da26worktree-agent-a7ef607b7ee1d6c74
safe-redirect.test.ts4.5 KB · 117 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
 * Regression guard: open redirect on the sign-in flow.
 *
 * Every `?redirect=` sink in auth.tsx passed the query value straight to
 * `c.redirect()`. `/login?redirect=https://evil.example` sent the browser to
 * the attacker's site from a link carrying the platform's own domain — the
 * classic phishing primitive, and at its worst on a sign-in page, because
 * the victim has just been asked for a password and the attacker chooses
 * where they land immediately afterwards.
 *
 * Hono percent-decodes the query value before a handler sees it, so
 * `%2f%2fevil.example` arrives as `//evil.example` and `%0d%0a` arrives as
 * real control characters. The decoded value is what these cases cover.
 */

import { describe, it, expect } from "bun:test";
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { safeRedirect, isSafeRedirect } from "../lib/safe-redirect";

describe("isSafeRedirect rejects off-origin targets", () => {
  const attacks: Array<[string, string]> = [
    ["https://evil.example", "absolute URL"],
    ["http://evil.example/x", "absolute URL, plain http"],
    ["//evil.example", "protocol-relative — browsers treat it as absolute"],
    ["//evil.example/path?a=b", "protocol-relative with a path"],
    ["/\\evil.example", "browsers fold the backslash to a slash"],
    ["\\\\evil.example", "UNC-style, folds to protocol-relative"],
    ["javascript:alert(1)", "scheme URL"],
    ["data:text/html,<script>", "data URL"],
    ["  /dashboard", "leading whitespace, no leading slash"],
    ["dashboard", "bare relative path, not rooted"],
    ["", "empty"],
  ];

  for (const [value, why] of attacks) {
    it(`rejects ${JSON.stringify(value)} (${why})`, () => {
      expect(isSafeRedirect(value)).toBe(false);
      expect(safeRedirect(value, "/dashboard")).toBe("/dashboard");
    });
  }

  it("rejects control characters (header injection)", () => {
    expect(isSafeRedirect("/foo\r\nSet-Cookie: a=b")).toBe(false);
    expect(isSafeRedirect("/foo\nLocation: https://evil.example")).toBe(false);
    expect(isSafeRedirect("/foo\tbar")).toBe(false);
    expect(isSafeRedirect("/foo\x00bar")).toBe(false);
  });

  it("rejects non-strings", () => {
    expect(isSafeRedirect(undefined)).toBe(false);
    expect(isSafeRedirect(null)).toBe(false);
    expect(isSafeRedirect(42)).toBe(false);
    expect(isSafeRedirect(["/a"])).toBe(false);
  });
});

describe("isSafeRedirect accepts ordinary same-origin paths", () => {
  const ok = [
    "/",
    "/dashboard",
    "/onboarding?welcome=1",
    "/ccantynz/Gluecron.com/pulls?state=open",
    "/settings/tokens#new",
    "/a/b/c/d/e",
    "/repo/with-dash_and.dot",
    "/search?q=hello+world&page=2",
  ];

  for (const value of ok) {
    it(`accepts ${JSON.stringify(value)}`, () => {
      expect(isSafeRedirect(value)).toBe(true);
      expect(safeRedirect(value, "/fallback")).toBe(value);
    });
  }

  it("defaults the fallback to the site root", () => {
    expect(safeRedirect("https://evil.example")).toBe("/");
  });
});

// --- the sinks must actually use it ----------------------------------------
//
// The bug was an absent check, so testing the helper alone would not have
// caught it. Strip ONLY line comments: a block-comment regex eats route
// paths, which contain a slash followed by a star.

function sourceWithoutLineComments(...rel: string[]): string {
  const text = readFileSync(join(import.meta.dir, "..", ...rel), "utf8");
  const stripped = text
    .split("\n")
    .filter((l) => !l.trim().startsWith("//"))
    .join("\n");
  expect(stripped.length).toBeGreaterThan(0);
  return stripped;
}

describe("redirect sinks are validated", () => {
  it("auth.tsx never reads the redirect query without validating it", () => {
    const src = sourceWithoutLineComments("routes", "auth.tsx");
    // Every read of the parameter must be wrapped. If a new sink is added
    // with a bare `c.req.query("redirect")`, this fails.
    const bare = src.match(/(?<!safeRedirect\(\s*)c\.req\.query\("redirect"\)/g);
    expect(bare).toBeNull();
    // ...and the helper is genuinely in use, so the check above cannot pass
    // vacuously by the sinks having been deleted.
    expect(src).toContain("safeRedirect(c.req.query(\"redirect\")");
    const uses = src.split("safeRedirect(").length - 1;
    expect(uses).toBeGreaterThanOrEqual(5);
  });

  it("personal-chat.tsx validates its form-supplied redirect", () => {
    const src = sourceWithoutLineComments("routes", "personal-chat.tsx");
    expect(src).toContain("safeRedirect(body.redirect");
    expect(src).not.toContain('String(body.redirect || "/chat")');
  });
});