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

http: improve invalid character in header error message #9010

Closed
wants to merge 1 commit into from

Conversation

evanlucas
Copy link
Contributor

@evanlucas evanlucas commented Oct 10, 2016

Checklist
  • make -j8 test (UNIX), or vcbuild test nosign (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

http

Description of change

This commit includes the header name in the error message when invalid
characters are in the value.

@nodejs-github-bot nodejs-github-bot added the http Issues or PRs related to the http subsystem. label Oct 10, 2016
@evanlucas evanlucas added the semver-major PRs that contain breaking changes and should be released in the next major version. label Oct 10, 2016
Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

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

LGTM with a nit.

'use strict';
var common = require('../common');
var assert = require('assert');
var http = require('http');
Copy link
Member

Choose a reason for hiding this comment

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

const

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack, not sure what I was thinking.

Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

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

LGTM pending @jasnell's nits.

Copy link
Member

@lpinca lpinca left a comment

Choose a reason for hiding this comment

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

LGTM

@lpinca
Copy link
Member

lpinca commented Oct 12, 2016

Tiny nit: commit subject line is a bit too long (55 chars) but I honestly have not idea how to make it shorter.

@Fishrock123
Copy link
Contributor

@ChALkeR could you search for The header content contains invalid characters

@ChALkeR ChALkeR self-assigned this Oct 12, 2016
@Fishrock123 Fishrock123 added this to the 7.0.0 milestone Oct 12, 2016
@jasnell
Copy link
Member

jasnell commented Oct 17, 2016

Ping ... @evanlucas @Fishrock123 @ChALkeR ... as a semver-major this needs to be landed ASAP if it's going to make it into v7.0.0. We're a week out from the release and I do not want to land a semver-major last minute.

@evanlucas
Copy link
Contributor Author

Commit message title has been updated.

@@ -355,7 +355,8 @@ OutgoingMessage.prototype.setHeader = function(name, value) {
if (this._header)
throw new Error('Can\'t set headers after they are sent.');
if (common._checkInvalidHeaderChar(value) === true) {
throw new TypeError('The header content contains invalid characters');
throw new TypeError(
`The header content for "${name}" contains invalid characters`);
Copy link
Member

Choose a reason for hiding this comment

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

Style: a line continuation should have four spaces of indent.

@bnoordhuis
Copy link
Member

Anyone have opinions on whether this could be used in information leaks or, if the header name is attacker-controlled, inserting tainted data in logs or terminals? It seems farfetched but it's good to think about such things.

@evanlucas
Copy link
Contributor Author

@bnoordhuis that is a good point. Thanks for bringing it up. We are already throwing if the header name is not valid with a message like 'Header name must be a valid HTTP Token ["' + name + '"]'. We also include the header name in the error message if the value is undefined. Is there an alternative that you suggest that would make this less concerning to you?

@addaleax
Copy link
Member

How about ${JSON.stringify(name)} instead of "${name}"? That might be a bit simplistic but at least it escapes anything there is to escape.

@rvagg rvagg force-pushed the master branch 2 times, most recently from c133999 to 83c7a88 Compare October 18, 2016 17:02
This commit includes the header name in the error message when invalid
characters are in the value.
@evanlucas
Copy link
Contributor Author

Updated with @addaleax's suggestion.

@ChALkeR
Copy link
Member

ChALkeR commented Oct 19, 2016

@Fishrock123 @evanlucas Sorry for the delay on this one — still catching up and finishing unfinished stuff =).

All matches for header content contains (from August, I have not yet updated the dataset since then):

http-node-1.2.0.tgz/_http_outgoing.js:309:    throw new TypeError('The header content contains invalid characters');
http-node-1.2.0.tgz/_http_outgoing.js:348:    throw new TypeError('The header content contains invalid characters');
http-node-1.2.0.tgz/_http_outgoing.js:522:      throw new TypeError('The header content contains invalid characters');

Note that 7bef1b7 is relatively new, so I might need to sync the dataset today and re-check another time.

@jasnell
Copy link
Member

jasnell commented Oct 20, 2016

@evanlucas ... I will be running the v7.0.0 RC1 build this afternoon. If this should get in to v7, then it needs to land this morning.

@Trott
Copy link
Member

Trott commented Oct 20, 2016

This was discussed at yesterday's CTC meeting and a resolution was arrived at, so I'm going to remove the ctc-agenda label.

@Trott Trott removed the ctc-agenda label Oct 20, 2016
@evanlucas evanlucas modified the milestones: 8.0.0, 7.0.0 Oct 20, 2016
@ChALkeR
Copy link
Member

ChALkeR commented Oct 23, 2016

Ok, I updated the dataset to 2016-10-22, the results for header content contains are pretty much the same the same as they were in #9010 (comment):

frida-http-1.0.1.tgz/lib/_http_outgoing.js:313:    throw new TypeError('The header content contains invalid characters');
frida-http-1.0.1.tgz/lib/_http_outgoing.js:353:    throw new TypeError('The header content contains invalid characters');
http-node-1.2.0.tgz/_http_outgoing.js:309:    throw new TypeError('The header content contains invalid characters');
http-node-1.2.0.tgz/_http_outgoing.js:348:    throw new TypeError('The header content contains invalid characters');
http-node-1.2.0.tgz/_http_outgoing.js:522:      throw new TypeError('The header content contains invalid characters');
rapx-win-1.4.2.tgz/ruff_modules/http/src/_http_outgoing.js:312:        throw new TypeError('The header content contains invalid characters');
rapx-win-1.4.2.tgz/ruff_modules/http/src/_http_outgoing.js:351:        throw new TypeError('The header content contains invalid characters');

Only copies of _http_outgoing.js that were added to packages for whatever reason contain that string, It doesn't look like anyone currently depends on the exact error message.

Note that delaying this until v8.0 will give the package authors more time to introduce dependencies on the error message, so this would have to be re-checked later.

Upd: I performed another search for content contains to be more sure, as this PR just inserts more words between «content» and «contains». Same results (and some unrelated stuff that I discarded):

> ./search.code.sh 'content contains' | grep -vE '(that|the|text|new|HTML|node|tab|window|loaded|provided) content contains' | grep -vE '(fb|interaction|res|resultObj).content contains' | grep -vE 'content contains (the|HTML|myCoolFramework)'
frida-http-1.0.1.tgz/lib/_http_outgoing.js:313:    throw new TypeError('The header content contains invalid characters');
frida-http-1.0.1.tgz/lib/_http_outgoing.js:353:    throw new TypeError('The header content contains invalid characters');
frida-http-1.0.1.tgz/lib/_http_outgoing.js:527:      throw new TypeError('The trailer content contains invalid characters');
http-node-1.2.0.tgz/_http_outgoing.js:309:    throw new TypeError('The header content contains invalid characters');
http-node-1.2.0.tgz/_http_outgoing.js:348:    throw new TypeError('The header content contains invalid characters');
http-node-1.2.0.tgz/_http_outgoing.js:522:      throw new TypeError('The header content contains invalid characters');
rapx-win-1.4.2.tgz/ruff_modules/http/src/_http_outgoing.js:312:        throw new TypeError('The header content contains invalid characters');
rapx-win-1.4.2.tgz/ruff_modules/http/src/_http_outgoing.js:351:        throw new TypeError('The header content contains invalid characters');
rapx-win-1.4.2.tgz/ruff_modules/http/src/_http_outgoing.js:522:            throw new TypeError('The trailer content contains invalid characters');

@ChALkeR ChALkeR removed their assignment Oct 23, 2016
@ChALkeR
Copy link
Member

ChALkeR commented Oct 23, 2016

Btw, what about The trailer content contains invalid characters error? Shouldn't it be also changed?

@evanlucas
Copy link
Contributor Author

@ChALkeR thanks, I'll add one for trailers too.

@evanlucas
Copy link
Contributor Author

Closing as we landed the debug messages instead (#9195)

@evanlucas evanlucas closed this Nov 2, 2016
@evanlucas evanlucas deleted the hcmoreinfo branch November 2, 2016 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants