| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7e1dee3 commit daca078
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -419,6 +419,16 @@ added: v9.0.0 | |||
| 419 | 419 | Specify the `module` of a custom [experimental ECMAScript Module loader][]. | |
| 420 | 420 | `module` may be either a path to a file, or an ECMAScript Module name. | |
| 421 | 421 | ||
| 422 | + ### `--insecure-http-parser` | ||
| 423 | + <!-- YAML | ||
| 424 | + added: REPLACEME | ||
| 425 | + --> | ||
| 426 | + | ||
| 427 | + Use an insecure HTTP parser that accepts invalid HTTP headers. This may allow | ||
| 428 | + interoperability with non-conformant HTTP implementations. It may also allow | ||
| 429 | + request smuggling and other HTTP attacks that rely on invalid headers being | ||
| 430 | + accepted. Avoid using this option. | ||
| 431 | + | ||
| 422 | 432 | ### `--max-http-header-size=size` | |
| 423 | 433 | <!-- YAML | |
| 424 | 434 | added: v11.6.0 | |
@@ -1064,6 +1074,7 @@ Node.js options that are allowed are: | |||
| 1064 | 1074 | * `--http-parser` | |
| 1065 | 1075 | * `--icu-data-dir` | |
| 1066 | 1076 | * `--input-type` | |
| 1077 | + * `--insecure-http-parser` | ||
| 1067 | 1078 | * `--inspect-brk` | |
| 1068 | 1079 | * `--inspect-port`, `--debug-port` | |
| 1069 | 1080 | * `--inspect-publish-uid` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -213,6 +213,12 @@ Specify the | |||
| 213 | 213 | .Ar module | |
| 214 | 214 | to use as a custom module loader. | |
| 215 | 215 | . | |
| 216 | + .It Fl -insecure-http-parser | ||
| 217 | + Use an insecure HTTP parser that accepts invalid HTTP headers. This may allow | ||
| 218 | + interoperability with non-conformant HTTP implementations. It may also allow | ||
| 219 | + request smuggling and other HTTP attacks that rely on invalid headers being | ||
| 220 | + accepted. Avoid using this option. | ||
| 221 | + . | ||
| 216 | 222 | .It Fl -max-http-header-size Ns = Ns Ar size | |
| 217 | 223 | Specify the maximum size of HTTP headers in bytes. Defaults to 8KB. | |
| 218 | 224 | . | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,6 +39,7 @@ const { | |||
| 39 | 39 | freeParser, | |
| 40 | 40 | parsers, | |
| 41 | 41 | HTTPParser, | |
| 42 | + isLenient, | ||
| 42 | 43 | prepareError, | |
| 43 | 44 | } = require('_http_common'); | |
| 44 | 45 | const { OutgoingMessage } = require('_http_outgoing'); | |
@@ -669,7 +670,8 @@ function tickOnSocket(req, socket) { | |||
| 669 | 670 | req.socket = socket; | |
| 670 | 671 | parser.initialize(HTTPParser.RESPONSE, | |
| 671 | 672 | new HTTPClientAsyncResource('HTTPINCOMINGMESSAGE', req), | |
| 672 | - req.maxHeaderSize || 0); | ||
| 673 | + req.maxHeaderSize || 0, | ||
| 674 | + isLenient()); | ||
| 673 | 675 | parser.socket = socket; | |
| 674 | 676 | parser.outgoing = req; | |
| 675 | 677 | req.parser = parser; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,6 +28,8 @@ const { | |||
| 28 | 28 | const { setImmediate } = require('timers'); | |
| 29 | 29 | ||
| 30 | 30 | const { methods, HTTPParser } = internalBinding('http_parser'); | |
| 31 | + const { getOptionValue } = require('internal/options'); | ||
| 32 | + const insecureHTTPParser = getOptionValue('--insecure-http-parser'); | ||
| 31 | 33 | ||
| 32 | 34 | const FreeList = require('internal/freelist'); | |
| 33 | 35 | const incoming = require('_http_incoming'); | |
@@ -237,6 +239,16 @@ function prepareError(err, parser, rawPacket) { | |||
| 237 | 239 | err.message = `Parse Error: ${err.reason}`; | |
| 238 | 240 | } | |
| 239 | 241 | ||
| 242 | + let warnedLenient = false; | ||
| 243 | + | ||
| 244 | + function isLenient() { | ||
| 245 | + if (insecureHTTPParser && !warnedLenient) { | ||
| 246 | + warnedLenient = true; | ||
| 247 | + process.emitWarning('Using insecure HTTP parsing'); | ||
| 248 | + } | ||
| 249 | + return insecureHTTPParser; | ||
| 250 | + } | ||
| 251 | + | ||
| 240 | 252 | module.exports = { | |
| 241 | 253 | _checkInvalidHeaderChar: checkInvalidHeaderChar, | |
| 242 | 254 | _checkIsHttpToken: checkIsHttpToken, | |
@@ -249,5 +261,6 @@ module.exports = { | |||
| 249 | 261 | parsers, | |
| 250 | 262 | kIncomingMessage, | |
| 251 | 263 | HTTPParser, | |
| 264 | + isLenient, | ||
| 252 | 265 | prepareError, | |
| 253 | 266 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,6 +39,7 @@ const { | |||
| 39 | 39 | chunkExpression, | |
| 40 | 40 | kIncomingMessage, | |
| 41 | 41 | HTTPParser, | |
| 42 | + isLenient, | ||
| 42 | 43 | _checkInvalidHeaderChar: checkInvalidHeaderChar, | |
| 43 | 44 | prepareError, | |
| 44 | 45 | } = require('_http_common'); | |
@@ -410,7 +411,8 @@ function connectionListenerInternal(server, socket) { | |||
| 410 | 411 | parser.initialize( | |
| 411 | 412 | HTTPParser.REQUEST, | |
| 412 | 413 | new HTTPServerAsyncResource('HTTPINCOMINGMESSAGE', socket), | |
| 413 | - server.maxHeaderSize || 0 | ||
| 414 | + server.maxHeaderSize || 0, | ||
| 415 | + isLenient(), | ||
| 414 | 416 | ); | |
| 415 | 417 | parser.socket = socket; | |
| 416 | 418 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -486,11 +486,13 @@ class Parser : public AsyncWrap, public StreamListener { | |||
| 486 | 486 | ||
| 487 | 487 | static void Initialize(const FunctionCallbackInfo<Value>& args) { | |
| 488 | 488 | Environment* env = Environment::GetCurrent(args); | |
| 489 | + bool lenient = args[3]->IsTrue(); | ||
| 489 | 490 | ||
| 490 | 491 | uint64_t max_http_header_size = 0; | |
| 491 | 492 | ||
| 492 | 493 | CHECK(args[0]->IsInt32()); | |
| 493 | 494 | CHECK(args[1]->IsObject()); | |
| 495 | + | ||
| 494 | 496 | if (args.Length() > 2) { | |
| 495 | 497 | CHECK(args[2]->IsNumber()); | |
| 496 | 498 | max_http_header_size = args[2].As<Number>()->Value(); | |
@@ -515,7 +517,7 @@ class Parser : public AsyncWrap, public StreamListener { | |||
| 515 | 517 | ||
| 516 | 518 | parser->set_provider_type(provider); | |
| 517 | 519 | parser->AsyncReset(args[1].As<Object>()); | |
| 518 | - parser->Init(type, max_http_header_size); | ||
| 520 | + parser->Init(type, max_http_header_size, lenient); | ||
| 519 | 521 | } | |
| 520 | 522 | ||
| 521 | 523 | template <bool should_pause> | |
@@ -762,8 +764,9 @@ class Parser : public AsyncWrap, public StreamListener { | |||
| 762 | 764 | } | |
| 763 | 765 | ||
| 764 | 766 | ||
| 765 | - void Init(llhttp_type_t type, uint64_t max_http_header_size) { | ||
| 767 | + void Init(llhttp_type_t type, uint64_t max_http_header_size, bool lenient) { | ||
| 766 | 768 | llhttp_init(&parser_, type, &settings); | |
| 769 | + llhttp_set_lenient(&parser_, lenient); | ||
| 767 | 770 | header_nread_ = 0; | |
| 768 | 771 | url_.Reset(); | |
| 769 | 772 | status_message_.Reset(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -375,6 +375,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | |||
| 375 | 375 | &EnvironmentOptions::heap_snapshot_signal, | |
| 376 | 376 | kAllowedInEnvironment); | |
| 377 | 377 | AddOption("--http-parser", "", NoOp{}, kAllowedInEnvironment); | |
| 378 | + AddOption("--insecure-http-parser", | ||
| 379 | + "use an insecure HTTP parser that accepts invalid HTTP headers", | ||
| 380 | + &EnvironmentOptions::insecure_http_parser, | ||
| 381 | + kAllowedInEnvironment); | ||
| 378 | 382 | AddOption("--input-type", | |
| 379 | 383 | "set module type for string input", | |
| 380 | 384 | &EnvironmentOptions::module_type, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -158,6 +158,8 @@ class EnvironmentOptions : public Options { | |||
| 158 | 158 | bool print_eval = false; | |
| 159 | 159 | bool force_repl = false; | |
| 160 | 160 | ||
| 161 | + bool insecure_http_parser = false; | ||
| 162 | + | ||
| 161 | 163 | bool tls_min_v1_0 = false; | |
| 162 | 164 | bool tls_min_v1_1 = false; | |
| 163 | 165 | bool tls_min_v1_2 = false; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments