googleapis / googleapis/google-http-java-client
Core: Validate header names and values to prevent CRLF injection
- 主要语言
- Java
- 星标
- 1.4k
- 派生
- 473
- PR 合并指标
- 30 天内没有已合并 PR
描述
Environment details
1. Core - HttpHeaders in google-http-client
2. OS type and version: Any
3. Java version: Any (Java 8+)
4. google-http-client version: 2.1.1 and earlier
---
Problem Statement
HttpHeaders does not validate header names or values for carriage return (\r) or line feed (\n) characters. If untrusted input is passed into header names or values, an attacker can inject CRLF sequences leading to HTTP Response Splitting or Header Injection.
---
Steps to reproduce
1. Create a HttpHeaders instance with a header name or value containing \r\n.
2. Serialize headers into a low-level HTTP request using HttpHeaders.serializeHeaders(...).
3. Observe that the injected header line is accepted without error.
---
Proposed Fix
Reject header names or values containing CRLF in HttpHeaders.addHeader():
if (name.contains("\r") || name.contains("\n") || stringValue.contains("\r") || stringValue.contains("\n")) {
throw new IllegalArgumentException("Header name or value contains CRLF characters.");
}
Regression tests (testSerializeHeaders_crlfInjectionInName and testSerializeHeaders_crlfInjectionInValue) are included in the accompanying PR.
贡献指南
调研方向
Start in HttpHeaders.addHeader() and trace how headers reach HttpHeaders.serializeHeaders(...). Run the named regression tests, testSerializeHeaders_crlfInjectionInName and testSerializeHeaders_crlfInjectionInValue, or add them if they are not present. Done means CRLF-containing names and values are rejected while valid headers still serialize successfully.
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java
- 领域
- security
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 78/100