Repository navigation
Potential fix for code scanning alert no. 16: Incomplete URL substring sanitization - #10
Merged
Merged
Conversation
…g sanitization Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Snapshot WarningsEnsure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice. Scanned FilesNone |
There was a problem hiding this comment.
Pull request overview
This PR addresses code scanning alert #16 by replacing an unsafe substring match on a documentation base URL with a parsed-URL hostname check, preventing unintended matches where docs.python.org appears outside the host component.
Changes:
- Replaced
baseUrl?.includes('docs.python.org')withnew URL(baseUrl).hostname === 'docs.python.org'. - Added explicit handling for missing/invalid
baseUrlvalues (returningundefinedas before).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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/KiidxAtlas/python-hover/security/code-scanning/16
In general, the problem should be fixed by parsing the URL and examining its
hostorhostnamecomponent instead of doing a plain substring match on the full URL string. The host comparison should be explicit, ideally against an allowlist, and allow for exact host matches (and, if desired, specific known subdomains) instead of any occurrence of the string anywhere in the URL.For this specific case, we should replace
baseUrl?.includes('docs.python.org')with a check that parsesbaseUrlusing Node’s standardURLclass and inspects the hostname. Since the code appears to want to detect the official Python documentation, we should treat URLs whose hostname is exactlydocs.python.orgor a known subdomain likedocs.python.org(and possiblydocs.python.org.but that’s unusual). To avoid changing surrounding behavior, we only adjust the condition: compute a booleanisPythonStdlibDocsby attempting to construct aURLfrombaseUrl. If parsing fails, orbaseUrlis falsy, we returnundefined(current behavior). If parsing succeeds, we checkurl.hostname === 'docs.python.org'. This yields the same true results for properly formed official-docs URLs and avoids accidental matches wheredocs.python.orgis in some other part of the URL string.Concretely, in
docs-engine/src/docResolver.ts, insidegetCorpusGroupForIndexedSymbol, replace the line using.includes('docs.python.org')with a small parsed-URL based check. We can safely use the globalURLconstructor available in modern Node without adding imports. No other functions or files need changes.Suggested fixes powered by Copilot Autofix. Review carefully before merging.