Skip to content

Fix #78719: http wrapper silently ignores long Location headers #6676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Feb 9, 2021

Currently, the HTTP wrapper reads and processes header lines of at most
1024 bytes (including the trailing line break). This appears to be
overly restrictive, particularly with regard to Location headers, which
may contain long URIs. There is no standard regarding the maximum
length of an URI, but assuming about 2000 bytes appears to be prudent.
We therefore increase the size of the buffer to 2048.

That still does not properly cater to header lines which are even
longer. According to RFC 7230, section 3.2.5, it is okay to discard
long header lines, only if that does not change the "message framing or
response semantics". So, e.g. an overlong Location header must not be
discarded if follow_location is set (the default), and probably
should not even if follow_location is not set. We therefore let the
attempt to open the stream fail in this case.

Currently, the HTTP wrapper reads and processes header lines of at most
1024 bytes (including the trailing line break).  This appears to be
overly restrictive, particularly with regard to Location headers, which
may contain long URIs.  There is no standard regarding the maximum
length of an URI, but assuming about 2000 bytes appears to be prudent.
We therefore increase the size of the buffer to 2048.

That still does not properly cater to header lines which are even
longer.  According to RFC 7230, section 3.2.5, it is okay to discard
long header lines, only if that does not change the "message framing or
response semantics".  So, e.g. an overlong Location header must not be
discarded if `follow_location` is set (the default), and probably
should not even if `follow_location` is not set.  We therefore let the
attempt to open the stream fail in this case.
@cmb69 cmb69 added the Bug label Feb 9, 2021
@nikic
Copy link
Member

nikic commented Feb 16, 2021

This doesn't really seem like a solution to the problem. IMHO we should be allowing arbitrary header lengths here, and not limiting them by the size of an internal buffer. For example we could call php_stream_get_line with a NULL buffer, in which case it will allocate one of appropriate size itself. (If we want to avoid allocations in the common case, we'd have to change php_stream_get_line to support both an initial fixed-size buffer and dynamic growth.)

@cmb69
Copy link
Member Author

cmb69 commented Feb 16, 2021

Thanks! Makes sense; I'll overhaul the PR ASAP.

@cmb69
Copy link
Member Author

cmb69 commented Feb 23, 2021

Closing in favor of PR #6720.

@cmb69 cmb69 closed this Feb 23, 2021
@cmb69 cmb69 deleted the cmb/78719 branch February 23, 2021 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants