mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
deps: update llhttp to 9.1.2
PR-URL: https://github.com/nodejs/node/pull/48981 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
This commit is contained in:
1 parent
71b90faac0
commit
e9ff81016d
19 files changed
+2200
-10083
No files matched your search
@@ -0,0 +1 @@
|
||||
libllhttp.pc
|
||||
Vendored
+8
-6
@@ -1,7 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.5.1)
|
||||
cmake_policy(SET CMP0069 NEW)
|
||||
|
||||
project(llhttp VERSION 8.1.1)
|
||||
project(llhttp VERSION 9.1.2)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
@@ -47,8 +47,9 @@ configure_file(
|
||||
function(config_library target)
|
||||
target_sources(${target} PRIVATE ${LLHTTP_SOURCES} ${LLHTTP_HEADERS})
|
||||
|
||||
target_include_directories(${target} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
target_include_directories(${target} PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
|
||||
set_target_properties(${target} PROPERTIES
|
||||
@@ -72,9 +73,10 @@ function(config_library target)
|
||||
|
||||
# This is required to work with FetchContent
|
||||
install(EXPORT llhttp
|
||||
FILE llhttp-config.cmake
|
||||
NAMESPACE llhttp::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/llhttp)
|
||||
FILE llhttp-config.cmake
|
||||
NAMESPACE llhttp::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/llhttp
|
||||
)
|
||||
endfunction(config_library target)
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
|
||||
Vendored
+114
-30
@@ -61,33 +61,41 @@ checks could be performed to get even stricter verification of the llhttp.
|
||||
## Usage
|
||||
|
||||
```C
|
||||
#include "stdio.h"
|
||||
#include "llhttp.h"
|
||||
#include "string.h"
|
||||
|
||||
llhttp_t parser;
|
||||
llhttp_settings_t settings;
|
||||
int handle_on_message_complete(llhttp_t* parser) {
|
||||
fprintf(stdout, "Message completed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Initialize user callbacks and settings */
|
||||
llhttp_settings_init(&settings);
|
||||
int main() {
|
||||
llhttp_t parser;
|
||||
llhttp_settings_t settings;
|
||||
|
||||
/* Set user callback */
|
||||
settings.on_message_complete = handle_on_message_complete;
|
||||
/*Initialize user callbacks and settings */
|
||||
llhttp_settings_init(&settings);
|
||||
|
||||
/* Initialize the parser in HTTP_BOTH mode, meaning that it will select between
|
||||
* HTTP_REQUEST and HTTP_RESPONSE parsing automatically while reading the first
|
||||
* input.
|
||||
*/
|
||||
llhttp_init(&parser, HTTP_BOTH, &settings);
|
||||
/*Set user callback */
|
||||
settings.on_message_complete = handle_on_message_complete;
|
||||
|
||||
/* Parse request! */
|
||||
const char* request = "GET / HTTP/1.1\r\n\r\n";
|
||||
int request_len = strlen(request);
|
||||
/*Initialize the parser in HTTP_BOTH mode, meaning that it will select between
|
||||
*HTTP_REQUEST and HTTP_RESPONSE parsing automatically while reading the first
|
||||
*input.
|
||||
*/
|
||||
llhttp_init(&parser, HTTP_BOTH, &settings);
|
||||
|
||||
enum llhttp_errno err = llhttp_execute(&parser, request, request_len);
|
||||
if (err == HPE_OK) {
|
||||
/* Successfully parsed! */
|
||||
} else {
|
||||
fprintf(stderr, "Parse error: %s %s\n", llhttp_errno_name(err),
|
||||
parser.reason);
|
||||
/*Parse request! */
|
||||
const char* request = "GET / HTTP/1.1\r\n\r\n";
|
||||
int request_len = strlen(request);
|
||||
|
||||
enum llhttp_errno err = llhttp_execute(&parser, request, request_len);
|
||||
if (err == HPE_OK) {
|
||||
fprintf(stdout, "Successfully parsed!\n");
|
||||
} else {
|
||||
fprintf(stderr, "Parse error: %s %s\n", llhttp_errno_name(err), parser.reason);
|
||||
}
|
||||
}
|
||||
```
|
||||
For more information on API usage, please refer to [src/native/api.h](https://github.com/nodejs/llhttp/blob/main/src/native/api.h).
|
||||
@@ -279,7 +287,7 @@ protocol support to highly non-compliant clients/server.
|
||||
No `HPE_INVALID_HEADER_TOKEN` will be raised for incorrect header values when
|
||||
lenient parsing is "on".
|
||||
|
||||
**USE AT YOUR OWN RISK!**
|
||||
**Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION!**
|
||||
|
||||
### `void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled)`
|
||||
|
||||
@@ -292,23 +300,22 @@ conjunction with `Content-Length`.
|
||||
This error is important to prevent HTTP request smuggling, but may be less desirable
|
||||
for small number of cases involving legacy servers.
|
||||
|
||||
**USE AT YOUR OWN RISK!**
|
||||
**Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION!**
|
||||
|
||||
### `void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled)`
|
||||
|
||||
Enables/disables lenient handling of `Connection: close` and HTTP/1.0
|
||||
requests responses.
|
||||
|
||||
Normally `llhttp` would error on (in strict mode) or discard (in loose mode)
|
||||
the HTTP request/response after the request/response with `Connection: close`
|
||||
and `Content-Length`.
|
||||
Normally `llhttp` would error the HTTP request/response
|
||||
after the request/response with `Connection: close` and `Content-Length`.
|
||||
|
||||
This is important to prevent cache poisoning attacks,
|
||||
but might interact badly with outdated and insecure clients.
|
||||
|
||||
With this flag the extra request/response will be parsed normally.
|
||||
|
||||
**USE AT YOUR OWN RISK!**
|
||||
**Enabling this flag can pose a security issue since you will be exposed to poisoning attacks. USE WITH CAUTION!**
|
||||
|
||||
### `void llhttp_set_lenient_transfer_encoding(llhttp_t* parser, int enabled)`
|
||||
|
||||
@@ -323,7 +330,67 @@ avoid request smuggling.
|
||||
|
||||
With this flag the extra value will be parsed normally.
|
||||
|
||||
**USE AT YOUR OWN RISK!**
|
||||
**Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION!**
|
||||
|
||||
### `void llhttp_set_lenient_version(llhttp_t* parser, int enabled)`
|
||||
|
||||
Enables/disables lenient handling of HTTP version.
|
||||
|
||||
Normally `llhttp` would error when the HTTP version in the request or status line
|
||||
is not `0.9`, `1.0`, `1.1` or `2.0`.
|
||||
With this flag the extra value will be parsed normally.
|
||||
|
||||
**Enabling this flag can pose a security issue since you will allow unsupported HTTP versions. USE WITH CAUTION!**
|
||||
|
||||
### `void llhttp_set_lenient_data_after_close(llhttp_t* parser, int enabled)`
|
||||
|
||||
Enables/disables lenient handling of additional data received after a message ends
|
||||
and keep-alive is disabled.
|
||||
|
||||
Normally `llhttp` would error when additional unexpected data is received if the message
|
||||
contains the `Connection` header with `close` value.
|
||||
With this flag the extra data will discarded without throwing an error.
|
||||
|
||||
**Enabling this flag can pose a security issue since you will be exposed to poisoning attacks. USE WITH CAUTION!**
|
||||
|
||||
### `void llhttp_set_lenient_optional_lf_after_cr(llhttp_t* parser, int enabled)`
|
||||
|
||||
Enables/disables lenient handling of incomplete CRLF sequences.
|
||||
|
||||
Normally `llhttp` would error when a CR is not followed by LF when terminating the
|
||||
request line, the status line, the headers or a chunk header.
|
||||
With this flag only a CR is required to terminate such sections.
|
||||
|
||||
**Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION!**
|
||||
|
||||
### `void llhttp_set_lenient_optional_cr_before_lf(llhttp_t* parser, int enabled)`
|
||||
|
||||
Enables/disables lenient handling of line separators.
|
||||
|
||||
Normally `llhttp` would error when a LF is not preceded by CR when terminating the
|
||||
request line, the status line, the headers, a chunk header or a chunk data.
|
||||
With this flag only a LF is required to terminate such sections.
|
||||
|
||||
**Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION!**
|
||||
|
||||
### `void llhttp_set_lenient_optional_crlf_after_chunk(llhttp_t* parser, int enabled)`
|
||||
|
||||
Enables/disables lenient handling of chunks not separated via CRLF.
|
||||
|
||||
Normally `llhttp` would error when after a chunk data a CRLF is missing before
|
||||
starting a new chunk.
|
||||
With this flag the new chunk can start immediately after the previous one.
|
||||
|
||||
**Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION!**
|
||||
|
||||
### `void llhttp_set_lenient_spaces_after_chunk_size(llhttp_t* parser, int enabled)`
|
||||
|
||||
Enables/disables lenient handling of spaces after chunk size.
|
||||
|
||||
Normally `llhttp` would error when after a chunk size is followed by one or more spaces are present instead of a CRLF or `;`.
|
||||
With this flag this check is disabled.
|
||||
|
||||
**Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION!**
|
||||
|
||||
## Build Instructions
|
||||
|
||||
@@ -345,17 +412,34 @@ make
|
||||
|
||||
### Using with CMake
|
||||
|
||||
If you want to use this library in a CMake project you can use the snippet below.
|
||||
If you want to use this library in a CMake project as a shared library, you can use the snippet below.
|
||||
|
||||
```
|
||||
FetchContent_Declare(llhttp
|
||||
URL "https://github.com/nodejs/llhttp/archive/refs/tags/v6.0.5.tar.gz") # Using version 6.0.5
|
||||
URL "https://github.com/nodejs/llhttp/archive/refs/tags/release/v8.1.0.tar.gz")
|
||||
|
||||
FetchContent_MakeAvailable(llhttp)
|
||||
|
||||
target_link_libraries(${EXAMPLE_PROJECT_NAME} ${PROJECT_LIBRARIES} llhttp ${PROJECT_NAME})
|
||||
# Link with the llhttp_shared target
|
||||
target_link_libraries(${EXAMPLE_PROJECT_NAME} ${PROJECT_LIBRARIES} llhttp_shared ${PROJECT_NAME})
|
||||
```
|
||||
|
||||
If you want to use this library in a CMake project as a static library, you can set some cache variables first.
|
||||
|
||||
```
|
||||
FetchContent_Declare(llhttp
|
||||
URL "https://github.com/nodejs/llhttp/archive/refs/tags/release/v8.1.0.tar.gz")
|
||||
|
||||
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "")
|
||||
set(BUILD_STATIC_LIBS ON CACHE INTERNAL "")
|
||||
FetchContent_MakeAvailable(llhttp)
|
||||
|
||||
# Link with the llhttp_static target
|
||||
target_link_libraries(${EXAMPLE_PROJECT_NAME} ${PROJECT_LIBRARIES} llhttp_static ${PROJECT_NAME})
|
||||
```
|
||||
|
||||
_Note that using the git repo directly (e.g., via a git repo url and tag) will not work with FetchContent_Declare because [CMakeLists.txt](./CMakeLists.txt) requires string replacements (e.g., `_RELEASE_`) before it will build._
|
||||
|
||||
## Building on Windows
|
||||
|
||||
### Installation
|
||||
|
||||
Vendored
+95
-12
@@ -1,13 +1,10 @@
|
||||
|
||||
#ifndef INCLUDE_LLHTTP_H_
|
||||
#define INCLUDE_LLHTTP_H_
|
||||
|
||||
#define LLHTTP_VERSION_MAJOR 8
|
||||
#define LLHTTP_VERSION_MAJOR 9
|
||||
#define LLHTTP_VERSION_MINOR 1
|
||||
#define LLHTTP_VERSION_PATCH 1
|
||||
|
||||
#ifndef LLHTTP_STRICT_MODE
|
||||
# define LLHTTP_STRICT_MODE 0
|
||||
#endif
|
||||
#define LLHTTP_VERSION_PATCH 2
|
||||
|
||||
#ifndef INCLUDE_LLHTTP_ITSELF_H_
|
||||
#define INCLUDE_LLHTTP_ITSELF_H_
|
||||
@@ -33,7 +30,7 @@ struct llhttp__internal_s {
|
||||
uint8_t http_major;
|
||||
uint8_t http_minor;
|
||||
uint8_t header_state;
|
||||
uint8_t lenient_flags;
|
||||
uint16_t lenient_flags;
|
||||
uint8_t upgrade;
|
||||
uint8_t finish;
|
||||
uint16_t flags;
|
||||
@@ -50,6 +47,7 @@ int llhttp__internal_execute(llhttp__internal_t* s, const char* p, const char* e
|
||||
#endif
|
||||
#endif /* INCLUDE_LLHTTP_ITSELF_H_ */
|
||||
|
||||
|
||||
#ifndef LLLLHTTP_C_HEADERS_
|
||||
#define LLLLHTTP_C_HEADERS_
|
||||
#ifdef __cplusplus
|
||||
@@ -114,7 +112,12 @@ enum llhttp_lenient_flags {
|
||||
LENIENT_CHUNKED_LENGTH = 0x2,
|
||||
LENIENT_KEEP_ALIVE = 0x4,
|
||||
LENIENT_TRANSFER_ENCODING = 0x8,
|
||||
LENIENT_VERSION = 0x10
|
||||
LENIENT_VERSION = 0x10,
|
||||
LENIENT_DATA_AFTER_CLOSE = 0x20,
|
||||
LENIENT_OPTIONAL_LF_AFTER_CR = 0x40,
|
||||
LENIENT_OPTIONAL_CRLF_AFTER_CHUNK = 0x80,
|
||||
LENIENT_OPTIONAL_CR_BEFORE_LF = 0x100,
|
||||
LENIENT_SPACES_AFTER_CHUNK_SIZE = 0x200
|
||||
};
|
||||
typedef enum llhttp_lenient_flags llhttp_lenient_flags_t;
|
||||
|
||||
@@ -534,6 +537,7 @@ typedef enum llhttp_status llhttp_status_t;
|
||||
#endif
|
||||
#endif /* LLLLHTTP_C_HEADERS_ */
|
||||
|
||||
|
||||
#ifndef INCLUDE_LLHTTP_API_H_
|
||||
#define INCLUDE_LLHTTP_API_H_
|
||||
#ifdef __cplusplus
|
||||
@@ -759,7 +763,8 @@ const char* llhttp_status_name(llhttp_status_t status);
|
||||
* `HPE_INVALID_HEADER_TOKEN` will be raised for incorrect header values when
|
||||
* lenient parsing is "on".
|
||||
*
|
||||
* **(USE AT YOUR OWN RISK)**
|
||||
* **Enabling this flag can pose a security issue since you will be exposed to
|
||||
* request smuggling attacks. USE WITH CAUTION!**
|
||||
*/
|
||||
LLHTTP_EXPORT
|
||||
void llhttp_set_lenient_headers(llhttp_t* parser, int enabled);
|
||||
@@ -773,7 +778,8 @@ void llhttp_set_lenient_headers(llhttp_t* parser, int enabled);
|
||||
* request smuggling, but may be less desirable for small number of cases
|
||||
* involving legacy servers.
|
||||
*
|
||||
* **(USE AT YOUR OWN RISK)**
|
||||
* **Enabling this flag can pose a security issue since you will be exposed to
|
||||
* request smuggling attacks. USE WITH CAUTION!**
|
||||
*/
|
||||
LLHTTP_EXPORT
|
||||
void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled);
|
||||
@@ -788,7 +794,8 @@ void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled);
|
||||
* but might interact badly with outdated and insecure clients. With this flag
|
||||
* the extra request/response will be parsed normally.
|
||||
*
|
||||
* **(USE AT YOUR OWN RISK)**
|
||||
* **Enabling this flag can pose a security issue since you will be exposed to
|
||||
* poisoning attacks. USE WITH CAUTION!**
|
||||
*/
|
||||
LLHTTP_EXPORT
|
||||
void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled);
|
||||
@@ -802,14 +809,90 @@ void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled);
|
||||
* avoid request smuggling.
|
||||
* With this flag the extra value will be parsed normally.
|
||||
*
|
||||
* **(USE AT YOUR OWN RISK)**
|
||||
* **Enabling this flag can pose a security issue since you will be exposed to
|
||||
* request smuggling attacks. USE WITH CAUTION!**
|
||||
*/
|
||||
LLHTTP_EXPORT
|
||||
void llhttp_set_lenient_transfer_encoding(llhttp_t* parser, int enabled);
|
||||
|
||||
/* Enables/disables lenient handling of HTTP version.
|
||||
*
|
||||
* Normally `llhttp` would error when the HTTP version in the request or status line
|
||||
* is not `0.9`, `1.0`, `1.1` or `2.0`.
|
||||
* With this flag the invalid value will be parsed normally.
|
||||
*
|
||||
* **Enabling this flag can pose a security issue since you will allow unsupported
|
||||
* HTTP versions. USE WITH CAUTION!**
|
||||
*/
|
||||
LLHTTP_EXPORT
|
||||
void llhttp_set_lenient_version(llhttp_t* parser, int enabled);
|
||||
|
||||
/* Enables/disables lenient handling of additional data received after a message ends
|
||||
* and keep-alive is disabled.
|
||||
*
|
||||
* Normally `llhttp` would error when additional unexpected data is received if the message
|
||||
* contains the `Connection` header with `close` value.
|
||||
* With this flag the extra data will discarded without throwing an error.
|
||||
*
|
||||
* **Enabling this flag can pose a security issue since you will be exposed to
|
||||
* poisoning attacks. USE WITH CAUTION!**
|
||||
*/
|
||||
LLHTTP_EXPORT
|
||||
void llhttp_set_lenient_data_after_close(llhttp_t* parser, int enabled);
|
||||
|
||||
/* Enables/disables lenient handling of incomplete CRLF sequences.
|
||||
*
|
||||
* Normally `llhttp` would error when a CR is not followed by LF when terminating the
|
||||
* request line, the status line, the headers or a chunk header.
|
||||
* With this flag only a CR is required to terminate such sections.
|
||||
*
|
||||
* **Enabling this flag can pose a security issue since you will be exposed to
|
||||
* request smuggling attacks. USE WITH CAUTION!**
|
||||
*/
|
||||
LLHTTP_EXPORT
|
||||
void llhttp_set_lenient_optional_lf_after_cr(llhttp_t* parser, int enabled);
|
||||
|
||||
/*
|
||||
* Enables/disables lenient handling of line separators.
|
||||
*
|
||||
* Normally `llhttp` would error when a LF is not preceded by CR when terminating the
|
||||
* request line, the status line, the headers, a chunk header or a chunk data.
|
||||
* With this flag only a LF is required to terminate such sections.
|
||||
*
|
||||
* **Enabling this flag can pose a security issue since you will be exposed to
|
||||
* request smuggling attacks. USE WITH CAUTION!**
|
||||
*/
|
||||
LLHTTP_EXPORT
|
||||
void llhttp_set_lenient_optional_cr_before_lf(llhttp_t* parser, int enabled);
|
||||
|
||||
/* Enables/disables lenient handling of chunks not separated via CRLF.
|
||||
*
|
||||
* Normally `llhttp` would error when after a chunk data a CRLF is missing before
|
||||
* starting a new chunk.
|
||||
* With this flag the new chunk can start immediately after the previous one.
|
||||
*
|
||||
* **Enabling this flag can pose a security issue since you will be exposed to
|
||||
* request smuggling attacks. USE WITH CAUTION!**
|
||||
*/
|
||||
LLHTTP_EXPORT
|
||||
void llhttp_set_lenient_optional_crlf_after_chunk(llhttp_t* parser, int enabled);
|
||||
|
||||
/* Enables/disables lenient handling of spaces after chunk size.
|
||||
*
|
||||
* Normally `llhttp` would error when after a chunk size is followed by one or more
|
||||
* spaces are present instead of a CRLF or `;`.
|
||||
* With this flag this check is disabled.
|
||||
*
|
||||
* **Enabling this flag can pose a security issue since you will be exposed to
|
||||
* request smuggling attacks. USE WITH CAUTION!**
|
||||
*/
|
||||
LLHTTP_EXPORT
|
||||
void llhttp_set_lenient_spaces_after_chunk_size(llhttp_t* parser, int enabled);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
#endif /* INCLUDE_LLHTTP_API_H_ */
|
||||
|
||||
|
||||
#endif /* INCLUDE_LLHTTP_H_ */
|
||||
Vendored
+48
@@ -283,6 +283,54 @@ void llhttp_set_lenient_transfer_encoding(llhttp_t* parser, int enabled) {
|
||||
}
|
||||
}
|
||||
|
||||
void llhttp_set_lenient_version(llhttp_t* parser, int enabled) {
|
||||
if (enabled) {
|
||||
parser->lenient_flags |= LENIENT_VERSION;
|
||||
} else {
|
||||
parser->lenient_flags &= ~LENIENT_VERSION;
|
||||
}
|
||||
}
|
||||
|
||||
void llhttp_set_lenient_data_after_close(llhttp_t* parser, int enabled) {
|
||||
if (enabled) {
|
||||
parser->lenient_flags |= LENIENT_DATA_AFTER_CLOSE;
|
||||
} else {
|
||||
parser->lenient_flags &= ~LENIENT_DATA_AFTER_CLOSE;
|
||||
}
|
||||
}
|
||||
|
||||
void llhttp_set_lenient_optional_lf_after_cr(llhttp_t* parser, int enabled) {
|
||||
if (enabled) {
|
||||
parser->lenient_flags |= LENIENT_OPTIONAL_LF_AFTER_CR;
|
||||
} else {
|
||||
parser->lenient_flags &= ~LENIENT_OPTIONAL_LF_AFTER_CR;
|
||||
}
|
||||
}
|
||||
|
||||
void llhttp_set_lenient_optional_crlf_after_chunk(llhttp_t* parser, int enabled) {
|
||||
if (enabled) {
|
||||
parser->lenient_flags |= LENIENT_OPTIONAL_CRLF_AFTER_CHUNK;
|
||||
} else {
|
||||
parser->lenient_flags &= ~LENIENT_OPTIONAL_CRLF_AFTER_CHUNK;
|
||||
}
|
||||
}
|
||||
|
||||
void llhttp_set_lenient_optional_cr_before_lf(llhttp_t* parser, int enabled) {
|
||||
if (enabled) {
|
||||
parser->lenient_flags |= LENIENT_OPTIONAL_CR_BEFORE_LF;
|
||||
} else {
|
||||
parser->lenient_flags &= ~LENIENT_OPTIONAL_CR_BEFORE_LF;
|
||||
}
|
||||
}
|
||||
|
||||
void llhttp_set_lenient_spaces_after_chunk_size(llhttp_t* parser, int enabled) {
|
||||
if (enabled) {
|
||||
parser->lenient_flags |= LENIENT_SPACES_AFTER_CHUNK_SIZE;
|
||||
} else {
|
||||
parser->lenient_flags &= ~LENIENT_SPACES_AFTER_CHUNK_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Callbacks */
|
||||
|
||||
|
||||
|
||||
Vendored
+21
-3
@@ -39,13 +39,31 @@ int llhttp__after_headers_complete(llhttp_t* parser, const char* p,
|
||||
int hasBody;
|
||||
|
||||
hasBody = parser->flags & F_CHUNKED || parser->content_length > 0;
|
||||
if (parser->upgrade && (parser->method == HTTP_CONNECT ||
|
||||
(parser->flags & F_SKIPBODY) || !hasBody)) {
|
||||
if (
|
||||
(parser->upgrade && (parser->method == HTTP_CONNECT ||
|
||||
(parser->flags & F_SKIPBODY) || !hasBody)) ||
|
||||
/* See RFC 2616 section 4.4 - 1xx e.g. Continue */
|
||||
(
|
||||
parser->type == HTTP_RESPONSE &&
|
||||
(parser->status_code == 100 || parser->status_code == 101)
|
||||
)
|
||||
) {
|
||||
/* Exit, the rest of the message is in a different protocol. */
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (parser->flags & F_SKIPBODY) {
|
||||
/* See RFC 2616 section 4.4 */
|
||||
if (
|
||||
parser->flags & F_SKIPBODY || /* response to a HEAD request */
|
||||
(
|
||||
parser->type == HTTP_RESPONSE && (
|
||||
parser->status_code == 102 || /* Processing */
|
||||
parser->status_code == 103 || /* Early Hints */
|
||||
parser->status_code == 204 || /* No Content */
|
||||
parser->status_code == 304 /* Not Modified */
|
||||
)
|
||||
)
|
||||
) {
|
||||
return 0;
|
||||
} else if (parser->flags & F_CHUNKED) {
|
||||
/* chunked encoding - ignore Content-Length header, prepare for a chunk */
|
||||
|
||||
Vendored
+1731
-10004
File diff suppressed because it is too large.
Load diff
+17
-4
@@ -984,10 +984,23 @@ added:
|
||||
- v10.19.0
|
||||
-->
|
||||
|
||||
Use an insecure HTTP parser that accepts invalid HTTP headers. This may allow
|
||||
interoperability with non-conformant HTTP implementations. It may also allow
|
||||
request smuggling and other HTTP attacks that rely on invalid headers being
|
||||
accepted. Avoid using this option.
|
||||
Enable leniency flags on the HTTP parser. This may allow
|
||||
interoperability with non-conformant HTTP implementations.
|
||||
|
||||
When enabled, the parser will accept the following:
|
||||
|
||||
* Invalid HTTP headers values.
|
||||
* Invalid HTTP versions.
|
||||
* Allow message containing both `Transfer-Encoding`
|
||||
and `Content-Length` headers.
|
||||
* Allow extra data after message when `Connection: close` is present.
|
||||
* Allow extra trasfer encodings after `chunked` has been provided.
|
||||
* Allow `\n` to be used as token separator instead of `\r\n`.
|
||||
* Allow `\r\n` not to be provided after a chunk.
|
||||
* Allow spaces to be present after a chunk size and before `\r\n`.
|
||||
|
||||
All the above will expose your application to request smuggling
|
||||
or poisoning attack. Avoid using this option.
|
||||
|
||||
### `--jitless`
|
||||
|
||||
|
||||
+6
-6
@@ -3449,9 +3449,9 @@ changes:
|
||||
`readableHighWaterMark` and `writableHighWaterMark`. This affects
|
||||
`highWaterMark` property of both `IncomingMessage` and `ServerResponse`.
|
||||
**Default:** See [`stream.getDefaultHighWaterMark()`][].
|
||||
* `insecureHTTPParser` {boolean} Use an insecure HTTP parser that accepts
|
||||
invalid HTTP headers when `true`. Using the insecure parser should be
|
||||
avoided. See [`--insecure-http-parser`][] for more information.
|
||||
* `insecureHTTPParser` {boolean} If set to `true`, it will use a HTTP parser
|
||||
with leniency flags enabled. Using the insecure parser should be avoided.
|
||||
See [`--insecure-http-parser`][] for more information.
|
||||
**Default:** `false`.
|
||||
* `IncomingMessage` {http.IncomingMessage} Specifies the `IncomingMessage`
|
||||
class to be used. Useful for extending the original `IncomingMessage`.
|
||||
@@ -3742,9 +3742,9 @@ changes:
|
||||
request to. **Default:** `'localhost'`.
|
||||
* `hostname` {string} Alias for `host`. To support [`url.parse()`][],
|
||||
`hostname` will be used if both `host` and `hostname` are specified.
|
||||
* `insecureHTTPParser` {boolean} Use an insecure HTTP parser that accepts
|
||||
invalid HTTP headers when `true`. Using the insecure parser should be
|
||||
avoided. See [`--insecure-http-parser`][] for more information.
|
||||
* `insecureHTTPParser` {boolean} If set to `true`, it will use a HTTP parser
|
||||
with leniency flags enabled. Using the insecure parser should be avoided.
|
||||
See [`--insecure-http-parser`][] for more information.
|
||||
**Default:** `false`
|
||||
* `joinDuplicateHeaders` {boolean} It joins the field line values of
|
||||
multiple headers in a request with `, ` instead of discarding
|
||||
|
||||
@@ -19,7 +19,7 @@ This a list of all the dependencies:
|
||||
* [histogram 0.11.8][]
|
||||
* [icu-small 73.2][]
|
||||
* [libuv 1.46.0][]
|
||||
* [llhttp 8.1.0][]
|
||||
* [llhttp 9.1.2][]
|
||||
* [minimatch 9.0.3][]
|
||||
* [nghttp2 1.55.1][]
|
||||
* [nghttp3 0.7.0][]
|
||||
@@ -212,7 +212,7 @@ The [libuv](https://github.com/libuv/libuv) dependency is a
|
||||
multi-platform support library with a focus on asynchronous I/O.
|
||||
It was primarily developed for use by Node.js.
|
||||
|
||||
### llhttp 8.1.0
|
||||
### llhttp 9.1.2
|
||||
|
||||
The [llhttp](https://github.com/nodejs/llhttp) dependency is
|
||||
the http parser used by Node.js.
|
||||
@@ -330,7 +330,7 @@ performance improvements not currently available in standard zlib.
|
||||
[histogram 0.11.8]: #histogram-0118
|
||||
[icu-small 73.2]: #icu-small-732
|
||||
[libuv 1.46.0]: #libuv-1460
|
||||
[llhttp 8.1.0]: #llhttp-810
|
||||
[llhttp 9.1.2]: #llhttp-912
|
||||
[maintaining-V8]: ./maintaining-V8.md
|
||||
[maintaining-cjs-module-lexer]: ./maintaining-cjs-module-lexer.md
|
||||
[maintaining-http]: ./maintaining-http.md
|
||||
|
||||
+50
-2
@@ -84,8 +84,18 @@ const uint32_t kLenientNone = 0;
|
||||
const uint32_t kLenientHeaders = 1 << 0;
|
||||
const uint32_t kLenientChunkedLength = 1 << 1;
|
||||
const uint32_t kLenientKeepAlive = 1 << 2;
|
||||
const uint32_t kLenientAll = kLenientHeaders | kLenientChunkedLength |
|
||||
kLenientKeepAlive;
|
||||
const uint32_t kLenientTransferEncoding = 1 << 3;
|
||||
const uint32_t kLenientVersion = 1 << 4;
|
||||
const uint32_t kLenientDataAfterClose = 1 << 5;
|
||||
const uint32_t kLenientOptionalLFAfterCR = 1 << 6;
|
||||
const uint32_t kLenientOptionalCRLFAfterChunk = 1 << 7;
|
||||
const uint32_t kLenientOptionalCRBeforeLF = 1 << 8;
|
||||
const uint32_t kLenientSpacesAfterChunkSize = 1 << 9;
|
||||
const uint32_t kLenientAll =
|
||||
kLenientHeaders | kLenientChunkedLength | kLenientKeepAlive |
|
||||
kLenientTransferEncoding | kLenientVersion | kLenientDataAfterClose |
|
||||
kLenientOptionalLFAfterCR | kLenientOptionalCRLFAfterChunk |
|
||||
kLenientOptionalCRBeforeLF | kLenientSpacesAfterChunkSize;
|
||||
|
||||
inline bool IsOWS(char c) {
|
||||
return c == ' ' || c == '\t';
|
||||
@@ -930,6 +940,27 @@ class Parser : public AsyncWrap, public StreamListener {
|
||||
if (lenient_flags & kLenientKeepAlive) {
|
||||
llhttp_set_lenient_keep_alive(&parser_, 1);
|
||||
}
|
||||
if (lenient_flags & kLenientTransferEncoding) {
|
||||
llhttp_set_lenient_transfer_encoding(&parser_, 1);
|
||||
}
|
||||
if (lenient_flags & kLenientVersion) {
|
||||
llhttp_set_lenient_version(&parser_, 1);
|
||||
}
|
||||
if (lenient_flags & kLenientDataAfterClose) {
|
||||
llhttp_set_lenient_data_after_close(&parser_, 1);
|
||||
}
|
||||
if (lenient_flags & kLenientOptionalLFAfterCR) {
|
||||
llhttp_set_lenient_optional_lf_after_cr(&parser_, 1);
|
||||
}
|
||||
if (lenient_flags & kLenientOptionalCRLFAfterChunk) {
|
||||
llhttp_set_lenient_optional_crlf_after_chunk(&parser_, 1);
|
||||
}
|
||||
if (lenient_flags & kLenientOptionalCRBeforeLF) {
|
||||
llhttp_set_lenient_optional_cr_before_lf(&parser_, 1);
|
||||
}
|
||||
if (lenient_flags & kLenientSpacesAfterChunkSize) {
|
||||
llhttp_set_lenient_spaces_after_chunk_size(&parser_, 1);
|
||||
}
|
||||
|
||||
header_nread_ = 0;
|
||||
url_.Reset();
|
||||
@@ -1236,6 +1267,23 @@ void InitializeHttpParser(Local<Object> target,
|
||||
Integer::NewFromUnsigned(env->isolate(), kLenientChunkedLength));
|
||||
t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kLenientKeepAlive"),
|
||||
Integer::NewFromUnsigned(env->isolate(), kLenientKeepAlive));
|
||||
t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kLenientTransferEncoding"),
|
||||
Integer::NewFromUnsigned(env->isolate(), kLenientTransferEncoding));
|
||||
t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kLenientVersion"),
|
||||
Integer::NewFromUnsigned(env->isolate(), kLenientVersion));
|
||||
t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kLenientDataAfterClose"),
|
||||
Integer::NewFromUnsigned(env->isolate(), kLenientDataAfterClose));
|
||||
t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kLenientOptionalLFAfterCR"),
|
||||
Integer::NewFromUnsigned(env->isolate(), kLenientOptionalLFAfterCR));
|
||||
t->Set(
|
||||
FIXED_ONE_BYTE_STRING(env->isolate(), "kLenientOptionalCRLFAfterChunk"),
|
||||
Integer::NewFromUnsigned(env->isolate(), kLenientOptionalCRLFAfterChunk));
|
||||
t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kLenientOptionalCRBeforeLF"),
|
||||
Integer::NewFromUnsigned(env->isolate(), kLenientOptionalCRBeforeLF));
|
||||
t->Set(
|
||||
FIXED_ONE_BYTE_STRING(env->isolate(), "kLenientSpacesAfterChunkSize"),
|
||||
Integer::NewFromUnsigned(env->isolate(), kLenientSpacesAfterChunkSize));
|
||||
|
||||
t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kLenientAll"),
|
||||
Integer::NewFromUnsigned(env->isolate(), kLenientAll));
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ server.listen(0, common.mustCall(() => {
|
||||
const req = http.get(`http://localhost:${server.address().port}/`);
|
||||
req.end();
|
||||
req.on('error', common.mustCall((err) => {
|
||||
const reason = 'Content-Length can\'t be present with Transfer-Encoding';
|
||||
const reason = "Transfer-Encoding can't be present with Content-Length";
|
||||
assert.strictEqual(err.message, `Parse Error: ${reason}`);
|
||||
assert(err.bytesParsed < response.length);
|
||||
assert(err.bytesParsed >= response.indexOf('Transfer-Encoding'));
|
||||
assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH');
|
||||
assert.strictEqual(err.code, 'HPE_INVALID_TRANSFER_ENCODING');
|
||||
assert.strictEqual(err.reason, reason);
|
||||
assert.deepStrictEqual(err.rawPacket, response);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ server.listen(0, () => {
|
||||
const req = http.get({ port: server.address().port }, common.mustNotCall());
|
||||
req.on('error', common.mustCall((err) => {
|
||||
assert.match(err.message, /^Parse Error/);
|
||||
assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH');
|
||||
assert.strictEqual(err.code, 'HPE_INVALID_TRANSFER_ENCODING');
|
||||
server.close();
|
||||
}));
|
||||
});
|
||||
@@ -0,0 +1,90 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const http = require('http');
|
||||
const net = require('net');
|
||||
const assert = require('assert');
|
||||
|
||||
// Verify that arbitrary characters after a \r cannot be used to perform HTTP request smuggling attacks.
|
||||
|
||||
{
|
||||
const server = http.createServer(common.mustNotCall());
|
||||
|
||||
server.listen(0, common.mustCall(() => {
|
||||
const client = net.connect(server.address().port);
|
||||
let response = '';
|
||||
|
||||
client.on('data', common.mustCall((chunk) => {
|
||||
response += chunk;
|
||||
}));
|
||||
|
||||
client.setEncoding('utf8');
|
||||
client.on('error', common.mustNotCall());
|
||||
client.on('end', common.mustCall(() => {
|
||||
assert.strictEqual(
|
||||
response,
|
||||
'HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n'
|
||||
);
|
||||
server.close();
|
||||
}));
|
||||
|
||||
client.write('' +
|
||||
'GET / HTTP/1.1\r\n' +
|
||||
'Connection: close\r\n' +
|
||||
'Host: a\r\n\rZ\r\n' + // Note the Z at the end of the line instead of a \n
|
||||
'GET /evil: HTTP/1.1\r\n' +
|
||||
'Host: a\r\n\r\n'
|
||||
);
|
||||
|
||||
client.resume();
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
const server = http.createServer((request, response) => {
|
||||
// Since chunk parsing failed, none of this should be called
|
||||
|
||||
request.on('data', common.mustNotCall());
|
||||
request.on('end', common.mustNotCall());
|
||||
});
|
||||
|
||||
server.listen(0, common.mustCall(() => {
|
||||
const client = net.connect(server.address().port);
|
||||
let response = '';
|
||||
|
||||
client.on('data', common.mustCall((chunk) => {
|
||||
response += chunk;
|
||||
}));
|
||||
|
||||
client.setEncoding('utf8');
|
||||
client.on('error', common.mustNotCall());
|
||||
client.on('end', common.mustCall(() => {
|
||||
assert.strictEqual(
|
||||
response,
|
||||
'HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n'
|
||||
);
|
||||
server.close();
|
||||
}));
|
||||
|
||||
client.write('' +
|
||||
'GET / HTTP/1.1\r\n' +
|
||||
'Host: a\r\n' +
|
||||
'Connection: close \r\n' +
|
||||
'Transfer-Encoding: chunked \r\n' +
|
||||
'\r\n' +
|
||||
'5\r\r;ABCD\r\n' + // Note the second \r instead of \n after the chunk length
|
||||
'34\r\n' +
|
||||
'E\r\n' +
|
||||
'0\r\n' +
|
||||
'\r\n' +
|
||||
'GET / HTTP/1.1 \r\n' +
|
||||
'Host: a\r\n' +
|
||||
'Content-Length: 5\r\n' +
|
||||
'\r\n' +
|
||||
'0\r\n' +
|
||||
'\r\n'
|
||||
);
|
||||
|
||||
client.resume();
|
||||
}));
|
||||
}
|
||||
@@ -27,7 +27,7 @@ I AM A SMUGGLED REQUEST!!!
|
||||
const server = http.createServer(common.mustNotCall());
|
||||
|
||||
server.on('clientError', common.mustCall((err) => {
|
||||
assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH');
|
||||
assert.strictEqual(err.code, 'HPE_INVALID_TRANSFER_ENCODING');
|
||||
server.close();
|
||||
}));
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@ const assert = require('assert');
|
||||
const Countdown = require('../common/countdown');
|
||||
|
||||
// Response splitting example, credit: Amit Klein, Safebreach
|
||||
const str = '/welcome?lang=bar%c4%8d%c4%8aContentLength:%200%c4%8d%c4%8a%c' +
|
||||
'4%8d%c4%8aHTTP/1.1%20200%20OK%c4%8d%c4%8aContentLength:%202' +
|
||||
'0%c4%8d%c4%8aLastModified:%20Mon,%2027%20Oct%202003%2014:50:18' +
|
||||
'%20GMT%c4%8d%c4%8aContentType:%20text/html%c4%8d%c4%8a%c4%8' +
|
||||
const str = '/welcome?lang=bar%c4%8d%c4%8aContent-Length:%200%c4%8d%c4%8a%c' +
|
||||
'4%8d%c4%8aHTTP/1.1%20200%20OK%c4%8d%c4%8aContent-Length:%202' +
|
||||
'0%c4%8d%c4%8aLast-Modified:%20Mon,%2027%20Oct%202003%2014:50:18' +
|
||||
'%20GMT%c4%8d%c4%8aContent-Type:%20text/html%c4%8d%c4%8a%c4%8' +
|
||||
'd%c4%8a%3chtml%3eGotcha!%3c/html%3e';
|
||||
|
||||
// Response splitting example, credit: Сковорода Никита Андреевич (@ChALkeR)
|
||||
|
||||
@@ -12,7 +12,7 @@ const reqstr = 'POST / HTTP/1.1\r\n' +
|
||||
const server = http.createServer(common.mustNotCall());
|
||||
server.on('clientError', common.mustCall((err) => {
|
||||
assert.match(err.message, /^Parse Error/);
|
||||
assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH');
|
||||
assert.strictEqual(err.code, 'HPE_INVALID_TRANSFER_ENCODING');
|
||||
server.close();
|
||||
}));
|
||||
server.listen(0, () => {
|
||||
|
||||
@@ -81,7 +81,7 @@ server.listen(0, function() {
|
||||
console.log('server.close() called');
|
||||
});
|
||||
|
||||
client.stdin.write('GET /\n\n');
|
||||
client.stdin.write('GET /\r\n\r\n');
|
||||
|
||||
client.on('error', function(error) {
|
||||
throw error;
|
||||
|
||||
@@ -62,11 +62,11 @@ const http = require('http');
|
||||
|
||||
server.listen(0, () => {
|
||||
const req = http.request({
|
||||
method: 'POST',
|
||||
port: server.address().port,
|
||||
agent: new http.Agent()
|
||||
});
|
||||
|
||||
req.write('asd');
|
||||
req.on('response', (res) => {
|
||||
const buf = [];
|
||||
res.on('data', (data) => buf.push(data));
|
||||
@@ -78,6 +78,8 @@ const http = require('http');
|
||||
server.close();
|
||||
}));
|
||||
});
|
||||
|
||||
req.end('asd');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -97,11 +99,10 @@ const http = require('http');
|
||||
|
||||
server.listen(0, () => {
|
||||
const req = http.request({
|
||||
method: 'POST',
|
||||
port: server.address().port,
|
||||
agent: new http.Agent()
|
||||
});
|
||||
|
||||
req.write('asd');
|
||||
req.on('response', (res) => {
|
||||
const buf = [];
|
||||
res.on('data', (data) => buf.push(data));
|
||||
@@ -113,5 +114,7 @@ const http = require('http');
|
||||
server.close();
|
||||
}));
|
||||
});
|
||||
|
||||
req.end('asd');
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user