{{ message }}
Validate Referer host before redirecting in Response::goBack#1980
Open
snoopysecurity wants to merge 1 commit into
Open
Validate Referer host before redirecting in Response::goBack#1980snoopysecurity wants to merge 1 commit into
snoopysecurity wants to merge 1 commit into
Conversation
Response::goBack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

PR fixes a security issue Open Redirect via
RefererHeader inResponse::goBackSummary of security issue
Typecho\Widget\Response::goBackredirects users to the value of theRefererrequest header without verifying that the host matches Typecho's own host. BecauseWidget\Security::protect()callsgoBack()whenever a CSRF token is missing or mismatched, any/action/<name>endpoint can be turned into an open redirect by a cross-origin page that simply links to it without providing the_=<token>parameter. No authentication is required.Summary of fix
In
Response::goBack, only redirect to theRefererif its host matches the host the request was served from. Otherwise fall back to$default(or/). This preserves the legitimate UX (stale-token bounce back) while removing the cross-origin redirect primitive.More information regarding the security issue
1.
Widget\Security::protect()—var/Widget/Security.php:63Every action handler in
/action/<name>calls$this->security->protect()near the top of
action(). When the_=<token>query parameter is missingor stale,
protect()triggersgoBack()instead of throwing an error.2.
Typecho\Widget\Response::goBack()—var/Typecho/Widget/Response.php:187The
Referervalue is passed straight toredirect().3.
Typecho\Widget\Response::redirect()— line 1724.
Common::safeUrl()—var/Typecho/Common.php:537safeUrlonly restricts the scheme tohttp/httpsand stripscharacters that could break out of an HTML attribute (
",',<,>).It does not validate the host. So
https://evil.example/anythingsurvives
safeUrlunchanged.Proof of concept
Attacker page (
https://evil.example/phish.html)Steps
https://evil.example/phish.htmland clicks the link.https://victim.example/index.php/action/loginwithReferer: https://evil.example/phish.html.Widget\Action::executedispatches toWidget\Login::action.$this->security->protect()runs. The request has no_parameter, sothe token comparison fails.
protect()calls$this->response->goBack().goBack()readsReferer: https://evil.example/phish.html, passes itto
redirect(), which passes it tosafeUrl(). The scheme ishttps,so
safeUrlreturns it unchanged.302 Location: https://evil.example/phish.html.Repro with
curlThe redirect fires unauthenticated.