Fix incomplete URL substring sanitization in test_custom_url_logged #5
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.
Summary
This PR fixes a security vulnerability in the
test_custom_url_loggedtest case where URL validation was performed using substring matching, which could lead to false positives when validating URLs in log messages.The Problem
The original test used substring matching to verify that a URL appears in log messages:
This approach is vulnerable to incomplete URL substring sanitization. A malicious URL like
https://test.api.com.evil.comwould incorrectly pass the test because"https://test.api.com"is a substring of the malicious URL. This is a common security issue when sanitizing URLs, as substring matching doesn't validate the actual URL structure or hostname.The Solution
The fix implements proper URL validation using
urlparse()to extract and validate the hostname:This approach:
test.api.com) from the URL usingurlparse()r"https?://[^\s]+"Security Impact
With this fix:
https://test.api.com→ Accepted (correct hostname)https://test.api.com.evil.com→ Rejected (hostname istest.api.com.evil.com)https://evil.test.api.com→ Rejected (hostname isevil.test.api.com)Testing
test_config_util.pypassResolves code scanning alert #1: Incomplete URL substring sanitization
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.