Potential fix for code scanning alert no. 10: Incomplete URL substring sanitization#1
Draft
flynnjustin24 wants to merge 1 commit intomainfrom
Draft
Potential fix for code scanning alert no. 10: Incomplete URL substring sanitization#1flynnjustin24 wants to merge 1 commit intomainfrom
flynnjustin24 wants to merge 1 commit intomainfrom
Conversation
…g sanitization Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
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.
Potential fix for https://github.com/gh-codespace-create/packaging.python.org/security/code-scanning/10
In general, instead of checking whether an allowed hostname appears as a substring of a URL string, you should parse the URL and compare its
hostname(and optionallyscheme) against the expected value(s). This ensures that embedded occurrences of the hostname (in the path, query, or as part of a longer domain) do not cause false positives.For this specific case,
RTD_CANONICAL_BUILDshould beTrueonly when we are on a ReadTheDocs build that is not a PR build and whose canonical URL’s host is exactlypackaging.python.org(or, if you want to be more flexible, a clearly defined set of allowed hosts). We can achieve this by:RTD_URLusingurllib.parse.urlparse.hostnamefrom the parsed result."packaging.python.org"instead of using"... in RTD_URL".Concretely, in
source/conf.py:from urllib.parse import urlparsealongside the existing imports.RTD_CANONICAL_BUILDexpression with logic that:RTD_URLbeingNoneor empty.RTD_URLand checks thatparsed.hostname == "packaging.python.org".This will preserve the intended meaning (“canonical build when the canonical URL is packaging.python.org, not a PR build, and on RTD”) while avoiding the incomplete substring sanitization.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.