flawopen.com/Teardowns/cve-2021-22960-nodejs-llhttp-request-smuggling
vulnerabilidade に関する技術的なソースコード解析と堅牢化対策:脆弱性の根本原因と安全な実装パッチの詳細。
直感的な物理的アナロジー解説:Imagine a two-window ticket booth. Window 1 reads: 'One ticket for Alice'. Window 2 reads: 'Wait, there's another ticket for Bob glued to the back'. Because Window 1 ignored the extra ticket, Bob's ticket sits in the window until Charlie walks up. Charlie gets handed Bob's ticket and private receipt, allowing an attacker to steal user sessions.
llhttpHTTP Request SmugglingChunked Transfer-Encoding0\r\n\r\n chunk.Chunk Extensions0;extension=value\r\n).根本原因は、オープンソースシステムにおける未検証の境界パラメータに起因し、状態の非同期化とセキュリティ制御の迂回を可能にします。
技術的な脆弱性悪用メカニズムと実行フローの詳細:The attacker sends an HTTP request with chunk extensions containing unescaped control characters.
技術的な脆弱性悪用メカニズムと実行フローの詳細:The frontend proxy treats the entire payload as a single continuous request body.
技術的な脆弱性悪用メカニズムと実行フローの詳細:Node.js's llhttp stops parsing prematurely, leaving the smuggled second request in the TCP buffer.
技術的な脆弱性悪用メカニズムと実行フローの詳細:The next innocent user's request is prepended to the smuggled request, exfiltrating their session tokens.
// VULNERABLE: deps/llhttp/src/llhttp.c before patch
int llhttp__on_chunk_extension(llhttp_t *parser, const char *p, const char *end) {
// ROOT CAUSE:
// Does not enforce strict ASCII validation on chunk extension tokens!
// Tolerates invalid whitespace and carriage return sequences, desyncing from proxies!
while (p < end && *p != '\r' && *p != '\n') {
p++; // Skips unvetted extension bytes
}
return 0;
}
// SECURE: deps/llhttp/src/llhttp.c patch
int llhttp__on_chunk_extension(llhttp_t *parser, const char *p, const char *end) {
// 1. Strictly validate characters inside chunk extensions according to RFC 9112
while (p < end && *p != '\r' && *p != '\n') {
uint8_t ch = (uint8_t)*p;
// Disallow spaces, control codes, and invalid token bytes
if (ch <= 0x20 || ch >= 0x7F || ch == ';') {
return HPE_INVALID_CHUNK_SIZE; // Reject immediately!
}
p++;
}
return 0;
}