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

Move HTTP response header validation to node #3065

Closed
tomyam1 opened this issue Feb 28, 2016 · 8 comments
Closed

Move HTTP response header validation to node #3065

tomyam1 opened this issue Feb 28, 2016 · 8 comments
Assignees
Labels
bug Bug or defect
Milestone

Comments

@tomyam1
Copy link

tomyam1 commented Feb 28, 2016

I recently got a Header value cannot contain or convert into non-ascii characters: content-disposition error after sending an attachment response for a file named café.pdf.

The error is thrown in here because the ASCII code of é is 233 and only codes smaller than 127 are allowed.

This is not coherent with the content-disposition module which allows up to code 255.

I opened the issue here. If you feel hapi is doing the correct thing, I'll open it with content-disposition.

This check was added in this commit. @jefflembeck since it's your commit, could you please have a look?

@tomyam1
Copy link
Author

tomyam1 commented Mar 4, 2016

For reference: since 4.3.0 node's http module checks for invalid headers characters (itroduced in this commit) and it allows characters in the range of: 9, [32-127], [128-255].

@jefflembeck
Copy link
Contributor

This commit was originally introduced to prevent HTTP Response splitting in hapi apps on node 0.12 and 4 before 4.3. node originally did some bit shifting that turned out to cause a problem in this regard. I haven't investigated to see if that particular problem has been fixed, but I can see if this likely can be cleaned up by grabbing the same range that 4.3.0 allows.

@davidkaminsky
Copy link

Is there a work-around at all for this? I'm running into it on hapi 13.4.0 and node 6.2.0.

@mtharrison
Copy link
Contributor

mtharrison commented Jun 6, 2016

@hueniverse would you support changing the header key/value character range to match what node does?

There are 2 issues when our validation differs to what happens in res.setHeader():

  1. We disallow valid characters (see original comment)
  2. We allow some invalid characters (such as [ and ])
server.route({
    method: 'GET',
    path: '/',
    handler: function (request, reply) {

        return reply().header('[header]', 'value');
    }
});

hapi won't throw on the above, but it will throw once it gets to node:

Debug: internal, implementation, error
    TypeError: Header name must be a valid HTTP Token ["[header]"]
    at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:339:11)
    ...

@kanongil
Copy link
Contributor

kanongil commented Jun 6, 2016

If #3178 is merged, this can be handled by simply removing the check from hapi, trusting node to throw on these headers. Given that all supported versions of node already make this check, this should be fine, right? Or do we support all v4.x implementations?

@hueniverse
Copy link
Contributor

I Rather leave this up to node. If the security issue is not longer there, we can remove it from hapi.

@mtharrison
Copy link
Contributor

The strict validation wasn't added to node until 4.3.0. @kanongil not sure about your question regarding which 4.x.x versions we support (I just assumed all).

@jefflembeck are you able to confirm if the underlying security issue that prompted you to add the check has been fixed in node core >= 4.0.0?

@hueniverse
Copy link
Contributor

We only support latest 4.x and 6.x. We can reflect that in the package.json file

@hueniverse hueniverse changed the title HTTP response header validation is too strict? Move HTTP response header validation to node Aug 22, 2016
@hueniverse hueniverse added the bug Bug or defect label Aug 22, 2016
@hueniverse hueniverse added this to the 15.0.0 milestone Aug 22, 2016
@hueniverse hueniverse self-assigned this Aug 22, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

6 participants