audit-redirects
Skill106 starsChanged 7 months agoMITView on GitHub
Find open redirects in pracht loaders, middleware, and navigation, including hand-rolled 3xx responses that bypass the built-in guards. Use for "audit redirects", "check for open redirects", "is my ?redirect= param safe", "review login redirects".
In this repository33 other files it gives its agents.
- AGENTS.mdAGENTS.md
- add-authSkill
- add-capabilitiesSkill
- add-contentSkill
- add-dbSkill
- add-i18nSkill
- add-imagesSkill
- add-observabilitySkill
- add-openapiSkill
- audit-a11ySkill
- audit-agent-surfaceSkill
- audit-authSkill
- audit-bundlesSkill
- audit-csrfSkill
- audit-depsSkill
- audit-headersSkill
- audit-islandsSkill
- audit-loadersSkill
- audit-secretsSkill
- audit-seoSkill
- audit-shellsSkill
- configure-isgSkill
- migrate-nextjsSkill
- pracht-debugSkill
- pracht-deploySkill
- pracht-scaffoldSkill
- pracht-test-apiSkill
- pre-deploySkill
- scaffold-e2eSkill
- scaffold-testsSkill
- tune-render-modeSkill
- typed-routesSkill
- upgrade-prachtSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 147
Default to suspicion for any request-derived target.
- Very specific: line 149
Do not trust referer as a gate.
- Distinctive: line 150
After-login redirects are the most dangerous — user is authenticated.
- Distinctive: line 153
Do not auto-fix; surface the gap and propose the patch.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Pracht Audit Redirects
The classic open-redirect bug: /login?redirect=https://evil.example →
after login, the app redirects the user to attacker territory carrying a fresh
session.
What the framework guarantees: the client router drops non-http(s): schemes
at the navigation boundary, and server-side redirect() /
buildRedirectResponse() reject non-http(s): schemes and CR/LF injection
against the Location header. What it cannot decide is whether the target
origin or path is one you trust — and a raw
new Response(null, { status: 302, headers: { location: userInput } })
bypasses all of those guards entirely.
Prerequisites: pracht inspect requires a vite config that registers the
pracht plugin.
Step 1: Inventory redirect sites
Bound the search first — do not grep the whole repo blind:
pracht inspect routes --jsonMCP: if pracht dev-mcp is registered, prefer its inspect_*, doctor, and verify tools to the CLI.
The resolved graph gives you each route's file, loaderFile, and
middleware names (resolve names to files via the defineApp({ middleware })
map in the manifest). Grep those files plus the API handler files from
pracht inspect api --json, and client components, for two distinct classes:
Class A — guarded sites (scheme/CRLF-safe, still open-redirect capable):
- Middleware/loaders/handlers returning
redirect(...)orbuildRedirectResponse(...). useNavigate()(value)and<a href={value}>wherevalueis dynamic (client guard applies).prefetchRouteState(value)calls with dynamic input.
Class B — unguarded sites (bypass every framework guard):
- Hand-rolled 3xx
Responses:new Response(null, { status: 302, headers: { location: ... } })orheaders.set("location", ...)in loaders, middleware, or API handlers. With user input these allow not just open redirects but also unsafe schemes and header-injection attempts — flag at higher severity.
Step 2: Trace the input
For each site, identify whether the redirect target is:
- Static — string literal. Safe.
- Internal-derived — built from
params,route.path, or a closed allowlist. Safe if the allowlist is verifiable. - Request-derived — read from
url.searchParams.get(...),request.headers.get('referer'), request body fields, cookie values, or query parameters. Suspect.
Common suspect names: redirect, redirectTo, next, returnTo, continue,
url, dest, goto.
Step 3: Check the gate
For each request-derived target, look for one of:
| Gate | Safe? |
| Hardcoded allowlist of paths/origins | Yes |
new URL(target, base).origin === url.origin | Yes — origin comparison |
target.startsWith('/') AND !target.startsWith('//') | Bypassable (/\evil.example) |
new URL(target).hostname === expected | Yes if expected is trusted |
| No check | Open redirect |
target.includes(domain) (substring) | Bypassable (evil.com#yourdomain.com) |
| Regex without anchors | Likely bypassable |
Prefix checks are not sufficient. //evil.example/path is
protocol-relative, and URL parsing turns \ into / and strips tabs and
newlines, so /\evil.example and /\t/evil.example pass
startsWith('/') && !startsWith('//') yet land on another origin. Only an
origin comparison after new URL(target, url) is a real gate.
Remember: redirect()'s built-in validation covers scheme and CRLF only — it
happily redirects to any well-formed http(s) origin, so Class A sites still
need an origin/path gate for request-derived targets.
Step 4: Report
| File:Line | Class (A/B) | Source | Target expression | Gate | Severity | Verdict |
Severity is the primary scale; the verdict is a secondary domain label:
error/open— request-derived target, no check. A Class B site here is the worst case (no scheme/CRLF guard either) — say so explicitly.warn/risky— substring/regex check; suggest URL-parse rewrite.info/safe— static or properly gated. For Class B sites that are static today, still recommend migrating toredirect()so the scheme/CRLF guards apply if the target ever becomes dynamic.
For each open/risky finding, propose a fix snippet, e.g.:
function safeRedirectPath(value: unknown, base: URL, fallback: string): string {
if (typeof value !== "string" || !value.startsWith("/")) return fallback;
try {
const target = new URL(value, base);
return target.origin === base.origin
? `${target.pathname}${target.search}${target.hash}`
: fallback;
} catch {
return fallback;
}
}
return redirect(safeRedirectPath(url.searchParams.get("redirect"), url, "/dashboard"), {
request,
});Step 5: Cross-check with the framework guards
Note in the report that pracht drops javascript:, data:, vbscript:,
blob:, and file: schemes both in the client router (since #122) and in
server-side redirect()/buildRedirectResponse() — so a guarded open
redirect cannot become script execution. But it can still phish (redirect to
a look-alike origin) and leak session/referrer headers, and Class B raw
Responses get none of this protection.
Rules
- Default to suspicion for any request-derived target.
- Recommend
URLparsing over string prefix checks for non-trivial gates. - Do not trust
refereras a gate; it is forgeable and often stripped. - After-login redirects are the most dangerous — user is authenticated.
- Recommend
redirect()over hand-rolled 3xx Responses so the scheme/CRLF guards apply. - Do not auto-fix; surface the gap and propose the patch.
$ARGUMENTS
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

