app: runCmd: Do not run the command when consent is denied - #7295
Open
utkarshalpha wants to merge 1 commit into
Open
app: runCmd: Do not run the command when consent is denied#7295utkarshalpha wants to merge 1 commit into
utkarshalpha wants to merge 1 commit into
Conversation
The consent dialog saved the user's answer but the function then returned true regardless, so denying a command still let it run that one time. The denial only took effect from the next invocation onwards, which is not what "Allow this local command to be executed?" implies. Return the answer the user actually gave, and log the refusal the same way the already-denied branch above does. checkCommandConsent had no test coverage, which is how this survived. The new tests go through handleRunCommand so they check what a user sees rather than a private function.
Contributor
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: utkarshalpha The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
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.
Summary
In the desktop app, denying a plugin's
runCommandrequest does not stop the command the first time. The consent dialog says "Allow this local command to be executed? Your choice will be saved.", but clicking Deny still lets the command run once. The denial only takes effect from the next invocation onwards.checkCommandConsentinapp/electron/runCmd.tsasks for consent, saves the answer, and then falls through to an unconditionalreturn true, so the answer is ignored for that call.Related Issue
Fixes #6558
Changes
app/electron/runCmd.ts: return the answer the user actually gave instead of always returningtrue, and log the refusal the same way the already-denied branch above it does.app/electron/runCmd.test.ts: add tests for the consent path, which had no coverage. They go through the exportedhandleRunCommand, so they check what a user sees rather than a private function.Steps to Test
npm run app:test:unitcommand consent: denying the dialog meansspawnis never called, allowing it means it is.Without the fix,
does not run the command when the user denies consentfails because the command is spawned anyway.Notes for the Reviewer
The tests need
vi.mock('electron', ...)because this is the first test in the file that reachesdialog.showMessageBoxSync. Outside the Electron runtimerequire('electron')returns the path to the binary rather than the API, sodialogis undefined and cannot be called without mocking it.Nothing outside the consent path changes. Commands that were already allowed or already denied behave exactly as before.
This PR was written in part with the assistance of generative AI. I have reviewed and tested the change myself.