Potential fix for code scanning alert no. 1: Incomplete URL substring sanitization#1
Draft
Potential fix for code scanning alert no. 1: Incomplete URL substring sanitization#1
Conversation
… 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/Matiasxth/capability-os/security/code-scanning/1
General fix: Instead of checking
url.includes("groq.com")and similar substring conditions, parse the URL with the built-inURLclass and inspect itshostname. Then compare the hostname (or its suffix) to known domains and hosts in a controlled way. This keeps behavior predictable and removes the possibility of matching tokens in the path, query, fragment, or userinfo sections.Concrete change in this file:
_detectPreset(url)inControlCenter.jsxto:"ollama"whenurlis falsy as before.urlusingnew URL(...)inside atry/catch. If parsing fails, fall back to"custom".hostname(e.g.,api.groq.com) and match:.groq.comor equalsgroq.com.localhostor127.0.0.1and port equals"11434"(or, to stay close to existing logic, accept host:port combinations equivalent to the oldlocalhost:11434/127.0.0.1:11434checks)..openai.comor equalsopenai.com."custom"if none match.This keeps the intended behavior (auto-detect known providers by host) while being robust and avoiding substring-based misclassification. No new imports are required;
URLis a standard global in modern browsers and React environments.Only the
_detectPresetfunction (line 143) needs to be replaced; the rest of the logic using_PRESETSandllmPresetremains unchanged.Suggested fixes powered by Copilot Autofix. Review carefully before merging.