Skip to content

Only redirect to a referrer on the same host - #12

Open
loevgaard wants to merge 1 commit into
masterfrom
fix/validate-referer-redirect
Open

loevgaard wants to merge 1 commit into
masterfrom
fix/validate-referer-redirect

Conversation

@loevgaard

Copy link
Copy Markdown
Member

ToggleVatAction redirected to the Referer header verbatim, which is an open redirect.

It is hard to actually abuse — the visitor has to already be on the referring page for it to fire — but it costs nothing to close, and it is exactly the pattern security scanners flag on a Sylius shop.

The referrer host is now compared to the request host, falling back to the shop homepage when they differ. Covered by a data provider:

Referer Result
https://example.com/previous-page (same host) redirects to the referrer
https://evil.example/phishing homepage
//evil.example/phishing (protocol relative) homepage
https://evil.example.com/phishing (suffix of the host) homepage
'' homepage
/previous-page (relative) homepage

One behaviour note: a relative referrer now falls back to the homepage rather than being followed. Browsers send absolute URLs here, so this should not come up in practice — but it is a real difference, and I chose the strict reading over adding a special case that only exists for a client nobody has. Say the word if you would rather allow relative paths through.

Addresses the second security item in #5.

https://claude.ai/code/session_01P9NzuVPQGvaVR97HZFq98a

The toggle action redirected to the Referer header verbatim, which is an open
redirect. It is hard to abuse in practice, since the visitor has to already be
on the referring page, but it is the kind of thing security scanners flag and
there is no reason to keep it.

Compare the referrer host to the request host and fall back to the shop
homepage when they differ, when the referrer carries no host at all, or when it
is protocol relative.

Claude-Session: https://claude.ai/code/session_01P9NzuVPQGvaVR97HZFq98a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant