Skip to content

app: runCmd: Do not run the command when consent is denied - #7295

Open
utkarshalpha wants to merge 1 commit into
kubernetes-sigs:mainfrom
utkarshalpha:fix-runcmd-consent-deny
Open

app: runCmd: Do not run the command when consent is denied#7295
utkarshalpha wants to merge 1 commit into
kubernetes-sigs:mainfrom
utkarshalpha:fix-runcmd-consent-deny

Conversation

@utkarshalpha

Copy link
Copy Markdown

Summary

In the desktop app, denying a plugin's runCommand request 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.

checkCommandConsent in app/electron/runCmd.ts asks for consent, saves the answer, and then falls through to an unconditional return 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 returning true, 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 exported handleRunCommand, so they check what a user sees rather than a private function.

Steps to Test

  1. npm run app:test:unit
  2. The two new tests are under command consent: denying the dialog means spawn is never called, allowing it means it is.

Without the fix, does not run the command when the user denies consent fails 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 reaches dialog.showMessageBoxSync. Outside the Electron runtime require('electron') returns the path to the binary rather than the API, so dialog is 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.

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.
@kubernetes-prow kubernetes-prow Bot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 16, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: utkarshalpha
Once this PR has been reviewed and has the lgtm label, please assign sniok for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow kubernetes-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 16, 2026
@kubernetes-prow
kubernetes-prow Bot requested review from kahirokunn and skoeva August 16, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

app: runCommand consent dialog runs the command once even when the user clicks Deny

1 participant