flawopen.com/Teardowns/cve-2022-31150-undici-crlf-injection-ssrf
vulnerabilidade に関する技術的なソースコード解析と堅牢化対策:脆弱性の根本原因と安全な実装パッチの詳細。
郵便局を通じて「リンゴを10箱発送せよ」という手紙を送る場面を想像してください。しかし、その封筒の中に「停止。前の指示は無効。全資金を悪意ある組織へ送金せよ」という偽の2枚目の公的書類を密かに紛れ込ませます。郵便局の窓口係が順番に書類を読み、2枚目をまったく新しい正式な手紙として処理してしまい、資金が攻撃者に送金されてしまいます。
Undicifetch() implementation.CRLF Injection\r) and Line Feed (\n) characters into HTTP headers to create a new header or a whole new request.HTTP Request SplittingSSRF (Server-Side Request Forgery)169.254.169.254).根本原因は、オープンソースシステムにおける未検証の境界パラメータに起因し、状態の非同期化とセキュリティ制御の迂回を可能にします。
技術的な脆弱性悪用メカニズムと実行フローの詳細:An attacker supplies a crafted header value: Admin\r\nHost: 169.254.169.254.
技術的な脆弱性悪用メカニズムと実行フローの詳細:The Node.js backend calls fetch(url, { headers: { 'X-User': input } }).
技術的な脆弱性悪用メカニズムと実行フローの詳細:Undici serializes the headers without sanitizing \r\n, injecting the forged Host header.
技術的な脆弱性悪用メカニズムと実行フローの詳細:The internal proxy directs the request to the cloud metadata service, exposing AWS/GCP credentials.
// VULNERABLE: lib/core/request.js before patch
function addHeader(headers, key, value) {
// ROOT CAUSE:
// Does not sanitize or reject carriage return (\r) and line feed (\n) in values!
// Allows attackers to split headers and inject arbitrary HTTP directives!
headers[key] = value;
}
// SECURE: lib/core/request.js patch
function addHeader(headers, key, value) {
// 1. Strict regex checking for dangerous control characters
const INVALID_HEADER_CHAR_REGEX = /[\r\n]/;
if (INVALID_HEADER_CHAR_REGEX.test(key) || INVALID_HEADER_CHAR_REGEX.test(value)) {
throw new TypeError(`Invalid character in header content: ["${key}": "${value}"]`);
}
headers[key] = value;
}
\r and \n characters from HTTP request header keys and values。169.254.169.254, 10.0.0.0/8, 127.0.0.1) using egress firewall rules を無効化または制限してください。undici and Node.js dependencies updated to latest patch releases。