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

Detect urlencoded form data header via regex #1314

Merged
merged 2 commits into from Dec 14, 2014

Conversation

simov
Copy link
Member

@simov simov commented Dec 12, 2014

Fixes #1313 related to #1310

@nylen
Copy link
Member

nylen commented Dec 12, 2014

I can think of a couple ways to break this:

Content-Type: not-really-application/x-www-form-urlencoded
Content-Type: application/x-www-form-urlencoded-not-really

Not sure how much we care about this, but you could fix it by using /^application\/x-www-form-urlencoded\b/ as the regex intead.

@simov
Copy link
Member Author

simov commented Dec 12, 2014

Yeah, I though about that as well, I can easily switch to the same check used in the code

self.getHeader('content-type').slice(0, 'application/x-www-form-urlencoded'.length) ===
        'application/x-www-form-urlencoded'

@nylen
Copy link
Member

nylen commented Dec 12, 2014

👍

@rlidwka
Copy link

rlidwka commented Dec 12, 2014

This should be more strict:

!/^application\/x-www-form-urlencoded(;|$)/.test(...)

.slice() still doesn't protect against application/x-www-form-urlencoded-but-not-really thing.

@simov
Copy link
Member Author

simov commented Dec 12, 2014

Even this

!/^application\/x-www-form-urlencoded(?:;|$)/.test(...)

slight performance increase :)

Btw is it valid to have an empty space between the urlencoded and the ; like this urlencoded ; ?

@rlidwka
Copy link

rlidwka commented Dec 12, 2014

rfc7231:

media-type = type "/" subtype *( OWS ";" OWS parameter )

Oops... my bad. It can have any combination of spaces and tabs there.

@nylen is right, it's easier to use \b and get it over with.

@simov
Copy link
Member Author

simov commented Dec 13, 2014

Btw, I pushed the fixed regex yesterday, no idea if notification was sent about it.

nylen added a commit that referenced this pull request Dec 14, 2014
Detect urlencoded form data header via regex
@nylen nylen merged commit 0ffa30b into request:master Dec 14, 2014
@nylen
Copy link
Member

nylen commented Dec 14, 2014

Thanks!

@simov simov mentioned this pull request Dec 15, 2014
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.

Twitter oauth POST fails when content-type includes '; charset=UTF-8'
3 participants