Core: Validate header names and values to prevent CRLF injection
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
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.
Written by the indexing model from the issue text.
Description
Environment details
- Core - HttpHeaders in google-http-client
- OS type and version: Any
- Java version: Any (Java 8+)
- 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
- Create a HttpHeaders instance with a header name or value containing \r\n.
- Serialize headers into a low-level HTTP request using HttpHeaders.serializeHeaders(...).
- 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.
- Dominant language
- Java
- Stars
- 1.4k
- Forks
- 473
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from googleapis/google-http-java-client
-
GenericData.containsKey() returns true for unset (null) declared fields, violating Map contract Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
googleapis/google-http-java-client#2187 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Core: LowLevelHttpResponse not disconnected when HttpResponse construction throws RuntimeException Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
type: cleanup
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
priority: p2 type: cleanup
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
All issues in googleapis/google-http-java-client
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100