Sanitize redirect URLs to prevent XSS and header injection#101
Open
TristanInSec wants to merge 1 commit into
Open
Sanitize redirect URLs to prevent XSS and header injection#101TristanInSec wants to merge 1 commit into
TristanInSec wants to merge 1 commit into
Conversation
The redirect() function places URL-decoded paths directly into both the HTML response body and the Location header. Percent-encoded HTML characters (%3Cscript%3E) are decoded and reflected in the body without escaping, enabling reflected XSS. Percent-encoded CRLF (%0d%0a) is decoded and placed in the Location header, enabling HTTP response splitting and header injection. Add html_escape() to encode HTML-special characters in the response body, and strip_crlf() to remove CR/LF from the Location header value. The existing append_escaped() in generate_dir_listing() uses the apbuf interface and cannot be reused here. Fixes both issues when --forward, --forward-all, or --https-redirect is configured.
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.
Summary
Both issues affect the
redirect()function when--forward,--forward-all, or--https-redirectis configured. URL-decoded paths are placed unsanitized into both the HTML body and theLocationheader.Changes
html_escape()to encode< > & " 'in the HTML response bodystrip_crlf()to remove\rand\nfrom theLocationheader valueappend_escaped()ingenerate_dir_listing()uses theapbufinterface and cannot be reused hereTest