Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Conversation

@jasnell
Copy link
Member

@jasnell jasnell commented Jan 12, 2015

Add a check to make sure that the specified HTTP method is a valid
token per the spec. To do so, we look at the method string and check
that each character is valid per the token rule. The first violation
aborts the check and throws.

This check is necessary to avoid malicious http request header
injection. per #8947

Add a check to make sure that the specified HTTP method is a valid
token per the spec. To do so, we look at the method string and check
that each character is valid per the token rule. The first violation
aborts the check and throws.

This check is necessary to avoid malicious http request header
injection. per nodejs#8947
@trevnorris
Copy link

@misterdjules @cjihrig Thoughts?

@cjihrig
Copy link

cjihrig commented Jan 13, 2015

I'm +1 on fixing the problem. Does anyone know how much of a security risk do we face by not ensuring that the request method matches the token description precisely? In other words, could we safely get away with cheating and just detecting newlines?

@trevnorris trevnorris added this to the 0.10.36 milestone Jan 13, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check_is_token sounds a bit generic, even though this is in lib/http.js. Maybe check_is_http_token is more explicit?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think it would help to mention that this code is written to conform to the HTTP/1.1 RFC, and from which section comes the set of forbidden characters. Otherwise, it might look like it was chosen arbitrarily.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree we want to change the name, and I think general we're more camelCase style -- perhaps checkValidToken

@misterdjules
Copy link

Commented inline, I have a few additional comments:

  • The code does not pass make jslint.
  • I think the test provided could be more thorough. Among other things, it could:
    • Test that valid method options do not throw (using assert.doesNotThrow).
    • Test more invalid characters. If we're making this part of the API more RFC compliant and not just fixing the header injection issue, I think we should test what the RFC describes more thoroughly.

What do you think?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, I like to mention using comments what the goal of a given test is. We could mention the link to the given issue, and the rationale for this test (not only fixing the "header injection" issue, but also making the API more compliant with the HTTP RFCs). It helps when revisiting tests much later and trying to understand the intent of the author(s).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that a more thorough review of the RFC requirements is going to be necessary overall. I've marked that on my short list to do for v0.14. If folks think it's important enough to do sooner, let me know.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My opinion is that without more thorough tests, we won't be able to be confident that this set of changes does what it intends to do, so I would advocate for including them from the start.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm expanding the test case to check a wider range of valid and invalid characters in the method.

@jasnell
Copy link
Member Author

jasnell commented Jan 21, 2015

Ok, will refactor this one a bit based on the discussion and get it reworked. Target v0.12?

@misterdjules
Copy link

Targeting v0.10 still makes sense to me, as the preferred way to land changes is to do that in the oldest supported & affected branch.

jasnell added a commit to jasnell/node-joyent that referenced this pull request Jan 22, 2015
RFC 2616/7230 requires that http method conform to
the token rule. This adds a check to verify that there are
no invalid characters in the method. If there are, then
we throw, otherwise fall through and continue.

Replacement for nodejs#9017 based on
feedback.
Targeted at v0.10
@jasnell
Copy link
Member Author

jasnell commented Jan 22, 2015

Replaced by #9076

@jasnell jasnell closed this Jan 22, 2015
@misterdjules misterdjules removed this from the 0.10.36 milestone Jan 24, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants