fix(cli_mcp_server): handle start launcher prefix in allow-list validation#308
Open
david-built-by-dc wants to merge 1 commit intomicrosoft:mainfrom
Open
Conversation
…ow-list check `start msedge https://...` was blocked because `start` is a Windows shell built-in and is not in ALLOWED_CLI_COMMANDS. The fix adds two helpers: - `_strip_start_prefix` — removes `start`/`start.exe`, any optional window title, and all `/flag` arguments, leaving just the real executable + its args. - `_resolve_launch_args` — uses the same stripping logic to build the argument list passed to subprocess.Popen, so we never need shell=True. `_is_cli_command_allowed` now normalises through `_strip_start_prefix` before checking the base command, so `start msedge ...` is treated identically to `msedge ...` for security purposes. Fixes: TEH-213"
|
@david-built-by-dc please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
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.
Problem
When an agent issues
run_shell(bash_command='start msedge https://...'), the server blocks it with:startis a Windows CMD shell built-in used to launch applications. It is not an executable in its own right and therefore cannot appear inALLOWED_CLI_COMMANDS. However,msedge(and other apps the agent may want to open) is already in the allow-list — the validation just never reaches it becausestartis parsed as the base command.A secondary issue: even if
startwere added to the allow-list,subprocess.Popen(["start", ...], shell=False)would fail becausestartis not a standalone executable.Fix
Two new helpers:
_strip_start_prefix(tokens)— if the token list begins withstart/start.exe, removes the launcher, any optional window title, and all/flagarguments, leaving only the real executable and its arguments._resolve_launch_args(command_str)— uses the same stripping logic when building the argument list forsubprocess.Popen, soshell=Falsecontinues to hold._is_cli_command_allowednow normalises through_strip_start_prefixbefore checking the base command, sostart msedge https://...is treated identically tomsedge https://...for security purposes. All existing dangerous-pattern checks still run against the full original command string.Behaviour
msedge https://example.comstart msedge https://example.comstartnot in list)start /d C:\tmp msedge https://example.comstart cmd.exe /c whoaminotepadstart powershell -enc ...Testing
Manually verified with the token-level logic. No existing tests were broken; a targeted unit test can be added to
tests/if the maintainers prefer.