Skip to content

Potential fix for code scanning alert no. 10: Incomplete URL substring sanitization#1

Draft
flynnjustin24 wants to merge 1 commit intomainfrom
alert-autofix-10
Draft

Potential fix for code scanning alert no. 10: Incomplete URL substring sanitization#1
flynnjustin24 wants to merge 1 commit intomainfrom
alert-autofix-10

Conversation

@flynnjustin24
Copy link
Copy Markdown

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 optionally scheme) 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_BUILD should be True only when we are on a ReadTheDocs build that is not a PR build and whose canonical URL’s host is exactly packaging.python.org (or, if you want to be more flexible, a clearly defined set of allowed hosts). We can achieve this by:

  1. Parsing RTD_URL using urllib.parse.urlparse.
  2. Extracting hostname from the parsed result.
  3. Comparing that hostname to "packaging.python.org" instead of using "... in RTD_URL".

Concretely, in source/conf.py:

  • Add an import from urllib.parse import urlparse alongside the existing imports.
  • Replace the RTD_CANONICAL_BUILD expression with logic that:
    • Safely handles RTD_URL being None or empty.
    • Parses RTD_URL and checks that parsed.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.

…g sanitization

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@flynnjustin24 flynnjustin24 added bug Something isn't working documentation Improvements or additions to documentation duplicate This issue or pull request already exists enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed invalid This doesn't seem right question Further information is requested wontfix This will not be worked on labels Feb 8, 2026
@flynnjustin24 flynnjustin24 self-assigned this Feb 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation duplicate This issue or pull request already exists enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed invalid This doesn't seem right question Further information is requested wontfix This will not be worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant