Skip to content

[BugFix] Prevent shell injection in cache manager launch commands - #8131

Open
kaltsit-10 wants to merge 1 commit into
PaddlePaddle:developfrom
kaltsit-10:fix/quote-cache-launch-cmd
Open

kaltsit-10 wants to merge 1 commit into
PaddlePaddle:developfrom
kaltsit-10:fix/quote-cache-launch-cmd

Conversation

@kaltsit-10

@kaltsit-10 kaltsit-10 commented Oct 16, 2026 •

Copy link
Copy Markdown

Motivation

launch_cache_manager / launch_cache_messager assemble a shell command by interpolating configuration-derived values (model path, cache protocol/dtype, splitwise role, the speculative-config JSON, ...) and run it via subprocess.Popen(..., shell=True).

If any interpolated value contains shell metacharacters (space, ;, &&, quotes), the command is re-parsed by the shell:

  • an argument is corrupted (e.g. a model path containing a space breaks the launch),
  • a single quote inside the --speculative_config / --default_dtype values breaks the manually added quoting,
  • a crafted value (...; cmd) is executed as a separate shell command (CWE-78, command injection).

Modifications

fastdeploy/cache_manager/prefix_cache_manager.py

  • Quote every string-valued argument interpolated into the two launch commands with shlex.quote(), including the executable path (sys.executable, py_path).
  • Remove the manual single quotes around --speculative_config / --default_dtype; shlex.quote() escapes them correctly even when the JSON contains quotes.
  • Numeric arguments (int(...) conversions), the environment-variable prefixes and the trailing log redirection are unchanged.
  • The change is behavior-preserving for values without metacharacters - shlex.quote() returns such values unchanged - so this is a minimal hardening rather than a refactor of the command assembly (env prefixes and the > redirection are intentionally untouched).

tests/cache_manager/test_prefix_cache_manager.py

  • Add two unit tests that capture the launch command and assert, via shlex.split(), that values carrying shell metacharacters (model dir; touch ..., zmq && ...) arrive as single, unmodified argv elements for both the cache-manager and cache-messager launch paths.

Usage or Command

No new usage. To run the new tests:

python -m pytest tests/cache_manager/test_prefix_cache_manager.py -k quotes_source_values -v

Accuracy Tests

Not applicable - this change does not touch model computation, kernels or outputs.

Checklist

  • Add at least a tag in the PR title. ([BugFix])
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results. (N/A - see above)
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag. (N/A - this PR targets develop)

Config-derived values are interpolated into shell commands executed with
shell=True; quote string values with shlex.quote() so arguments are not
re-parsed by the shell. Adds unit tests for both launch paths.
@CLAassistant

CLAassistant commented Oct 16, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants