Potential fix for code scanning alert no. 2: Uncontrolled command line#17
Draft
TheInfamousToTo wants to merge 1 commit intomainfrom
Draft
Potential fix for code scanning alert no. 2: Uncontrolled command line#17TheInfamousToTo wants to merge 1 commit intomainfrom
TheInfamousToTo wants to merge 1 commit intomainfrom
Conversation
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/TheInfamousToTo/PiHoleVault/security/code-scanning/2
In general, this should be fixed by eliminating shell interpretation of the user-controlled
hostvalue. Instead of constructing a single command string forexecSync, use a function such aschild_process.execFileSyncthat takes the program and its arguments as an array, so thehostvalue is passed as a literal argument and not parsed by a shell. Optionally, add simple validation (e.g. allow only typical hostname/IP characters) to further reduce risk, but the primary requirement is to stop feeding user input to a shell.The single best fix here, without changing existing behavior, is to replace the
execSynccall on line 235 withexecFileSync('ping', ['-c', '1', '-W', '3', host], { timeout: 5000 }). This preserves the same command semantics (ping -c 1 -W 3 <host>), but runspingdirectly without going through a shell, so characters like;,&&, or backticks inhostcan no longer trigger additional commands. SinceexecSyncfromchild_processis already imported at the top and re-required inside the function, we can either (a) keep the innerrequirebut swap toexecFileSync, or (b) rely on the top-level import. To keep the change as local and minimal as possible, we will adjust the inner require fromexecSynctoexecFileSyncand update the call accordingly. No change to routing, logging, or response structure is necessary.Concretely:
backend/routes/ssh.js, in the/debugroute’s "Test 1: Basic network connectivity" block, changeconst { execSync } = require('child_process');toconst { execFileSync } = require('child_process');.execSync(\ping -c 1 -W 3 ${host}`, { timeout: 5000 })withexecFileSync('ping', ['-c', '1', '-W', '3', host], { timeout: 5000 })`..toString()conversion, etc.) unchanged.This fix uses only Node’s built-in
child_processmodule and does not require any new dependencies.Suggested fixes powered by Copilot Autofix. Review carefully before merging.