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.ts2.7 KB · 58 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
/**
 * Same-origin validation for user-supplied redirect targets.
 *
 * Every `?redirect=` sink in the auth flow used to pass the query value
 * straight to `c.redirect()`. `/login?redirect=https://evil.example` sent the
 * browser to the attacker's site carrying the platform's own domain in the
 * link the victim clicked — the classic phishing primitive, and worse on a
 * sign-in page than anywhere else, because the victim has just been asked to
 * type a password and the attacker controls where they land immediately
 * after. It also lets an attacker bounce a freshly-authenticated user to a
 * page that harvests whatever the app puts in the URL.
 *
 * The policy here is deliberately narrow: accept a relative path on this
 * origin, reject everything else. Absolute URLs are refused even when they
 * point at our own host — allowing them means parsing and comparing origins,
 * and origin comparison is exactly where these bugs come from.
 *
 * Rejected, with the reason each one matters:
 *
 *   https://evil.example    absolute URL, different origin
 *   //evil.example          protocol-relative; browsers treat it as absolute
 *   /\evil.example          browsers fold a backslash to a slash, so this
 *                           behaves like the protocol-relative case above
 *   javascript:alert(1)     scheme URL, no leading slash
 *   /foo\r\nSet-Cookie: x   control characters, i.e. header injection
 *   (empty / missing)       nothing to honour
 *
 * Accepted: `/dashboard`, `/owner/repo/pulls?state=open#tab`, `/` — a single
 * leading slash, no backslash anywhere, no control characters.
 *
 * Note on encoding: Hono has already percent-decoded the query value by the
 * time it reaches here, so `%2f%2fevil.example` arrives as `//evil.example`
 * and `%0d%0a` arrives as real control characters. Both are caught above.
 * Validate the decoded value — never the raw one.
 */

/**
 * A single leading slash, not followed by another slash, then any run of
 * characters that are neither backslashes nor C0/C1 control characters.
 */
const SAFE_PATH = /^\/(?!\/)[^\\\x00-\x1f\x7f-\x9f]*$/;

/** True if `value` is a relative path safe to redirect to on this origin. */
export function isSafeRedirect(value: unknown): value is string {
  if (typeof value !== "string") return false;
  if (value.length === 0) return false;
  return SAFE_PATH.test(value);
}

/**
 * Return `value` when it is a safe same-origin path, otherwise `fallback`.
 *
 * Always use this — never the raw query value — when building a `Location`
 * header from anything the caller supplied.
 */
export function safeRedirect(value: unknown, fallback: string = "/"): string {
  return isSafeRedirect(value) ? value : fallback;
}