Skip to content
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

[5.1] Fix for bad accept headers #13039

Merged
merged 2 commits into from
Apr 6, 2016
Merged

[5.1] Fix for bad accept headers #13039

merged 2 commits into from
Apr 6, 2016

Conversation

GrahamCampbell
Copy link
Member

For some reason someone passed:

Mozilla/5.0 (Windows; U; Windows NT 5.1; pt-PT; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)

as an Accept header to my server (either by mistake, or as an attempt to attack it), and successfully crashed it with:

preg_match(): Compilation failed: missing ) at offset 25`

and since preg_match returns false when an error occurs, simply suppressing errors is the desired behaviour here.

@taylorotwell taylorotwell merged commit c0f9f9c into 5.1 Apr 6, 2016
@GrahamCampbell GrahamCampbell deleted the accept branch April 6, 2016 13:46
@vlakoff
Copy link
Contributor

vlakoff commented Apr 6, 2016

More importantly, why does the regex crash?
Only hiding the possible error doesn't sound sufficient to me.

I guess there's some use of preg_quote to do.

@GrahamCampbell
Copy link
Member Author

We don't need to care why it crashed. It was an invalid header.

@GrahamCampbell
Copy link
Member Author

We just need the logic that if it does crash, it must be invalid.

@vlakoff
Copy link
Contributor

vlakoff commented Apr 6, 2016

You're possibly opening the door to server DoS by allowing to execute user-supplied special regex characters.

@vlakoff
Copy link
Contributor

vlakoff commented Apr 6, 2016

By the way, in Request.php there are 2 calls of matchesType:
one is $this->matchesType($accept, $type), the other is $this->matchesType($type, $accept).
(note the arguments order)

Apparently one is indeed incorrect. Have yet to figure out which one.

@GrahamCampbell
Copy link
Member Author

Not a bug. They are intentionally the other way around in one of them.

@vlakoff
Copy link
Contributor

vlakoff commented Apr 6, 2016

If you're really sure on this, fine.

The regex still needs escaping though.

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.

3 participants