security: mitigate cross-origin credential leaks, prevent CRLF header injection, and disable XML DTD processing#2170
Open
insaf021 wants to merge 2 commits into
Conversation
…F, and disable XML DTD processing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements security hardening improvements in the
google-http-java-clientlibrary to strengthen credential handling across redirects, improve HTTP header validation, and harden XML parsing.When handling redirects, the original request origin is recorded and compared against the redirected request. If a redirect targets a different origin (scheme, host, or port), sensitive headers such as
AuthorizationandCookieare removed after execution interceptors run, preventing credentials from being forwarded to cross-origin destinations while preserving existing behavior for same-origin redirects. Unit tests have been added to verify both same-origin and cross-origin redirect behavior.This PR also adds validation in
HttpHeaders#addHeaderto reject header names and serialized header values containing carriage return (\r) or line feed (\n) characters by throwing anIllegalArgumentException. Corresponding tests verify that invalid headers are rejected while valid headers continue to serialize correctly.Additionally,
Xml#createParser()now disables DTD processing usingXmlPullParser.FEATURE_PROCESS_DOCDECLwhere supported by the parser implementation, with a graceful fallback for implementations that do not support the feature. Tests have been added to verify that XML documents containing DTD declarations do not process external entities while maintaining normal XML parsing behavior.The implementation has been validated by running the relevant unit tests.
HttpRequestTest,HttpHeadersTest, andXmlTestall pass successfully, with no test failures or errors.