Skip to content

Ignore other sites' referers in Redirect::back and stop serving hidden public files - #617

Open
AlfonsoCampodonico wants to merge 1 commit into
0.xfrom
fix/back-and-hidden-files
Open

AlfonsoCampodonico wants to merge 1 commit into
0.xfrom
fix/back-and-hidden-files

Conversation

@AlfonsoCampodonico

Copy link
Copy Markdown
Contributor

What was wrong

Redirect::back() followed any Referer, so a page on another site that links to a route returning back() sent the user to that site. Separately, hidden files under public/, such as .env, .git/config or build/.vite/manifest.json, were served whenever they existed.

What's fixed

  • Redirect::back() uses the Referer only when it resolves to the request's own scheme, host and port. A relative path still counts; another host, scheme or port, user info, a protocol-relative //host or /\host doesn't. Otherwise it falls back to the session's previous page, then the root URL.
  • A request path with a segment starting with ., other than .well-known, skips public/ and falls through to routes or a 404. The path is decoded before splitting, so %2F and %2E can't hide the dot.
  • responses.md, lifecycle.md and structure.md describe both.

Replaces #4, which was closed before it merged.

Copy link
Copy Markdown
Member

This is an automated, agent-powered review.

Confirmed, for both halves. On 0.x, Redirect::back() sends the user to whatever the Referer header says, so a page on another site can link to any route that redirects back and land the user wherever it likes. Separately, a request for /.env or /build/.vite/manifest.json returns the file whenever it exists under public/. Seven of the new cross-site referer cases, the session fallback check in tests/web.rs, and hidden_public_files_are_not_found all fail on 0.x and pass here.

  • The referer half duplicates Ignore referers from other sites in Redirect::back #416, which checks the header in the same place and goes further: it also accepts APP_URL's origin, redirects to the URL it checked instead of the raw header, rejects blob: referers (this PR still redirects to blob:http://localhost/...), and applies the same check to Inertia::back() and back_with_errors(). Ignore referers from other sites in Redirect::back #416 should land for the referer fix, and this PR should drop its redirect.rs, responses.md, tests/http.rs and tests/web.rs changes.
  • The public/ half is the same change as Stop serving hidden files from public #422, which was closed without merging: it checks the decoded path just before ServeDir, which has no option to skip dotfiles, so it's the right place. It's independent of the referer fix and of Stop serving hidden files from public storage mounts #426, which applies the same .well-known rule to storage mounts. If it's still wanted, it can land on its own as this PR's remaining change, with Stop serving hidden files from public #422's hidden_public_files_reach_the_fallback_route test and /.git/ case brought along.
  • No breaking changes beyond the intended behavior: hidden paths under public/ now return a 404 or reach the fallback route.

Thanks for your contribution, a human review will follow shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug p2 Priority 2: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants