Skip to content

fix(fri): validate build/clear query args before they reach cmd.exe - #725

Open
SahilKumar965 wants to merge 1 commit into
ControlCore-Project:devfrom
SahilKumar965:fix/fri-shell-injection
Open

SahilKumar965 wants to merge 1 commit into
ControlCore-Project:devfrom
SahilKumar965:fix/fri-shell-injection

Conversation

@SahilKumar965

@SahilKumar965 SahilKumar965 commented Nov 29, 2026 •

Copy link
Copy Markdown

On Windows, /build and /clear in fri/server/main.py pass query parameters into call(..., shell=True). Python's list2cmdline doesn't escape & | > ^, so POST /clear/x?maxtime=100%26calc reaches cmd.exe as maxtime 100&calc and runs calc.

Change

  • New validate_run_args(): maxtime must be a number; on Windows, params can't contain & | < > ^ % ! " or newlines. Normal params like a=1;b=[1,2] still work.
  • /build now validates fetch, outdir, apikey, maxtime, params (apikey also goes into the makestudy command).
  • /clear validates maxtime and params.
  • Invalid input returns 400, same as /library.

Tests
tests/test_fri_input_validation.py makes the server think it's on Windows and records shell calls instead of running them. 9 of the new tests fail without the fix and all pass with it. The full suite passes and ruff is clean.

Notes

  • Flask isn't in requirements-ci.txt, so CI skips the FRI tests (this one and test_openjupyter_security.py). I ran them locally with Flask installed. Should I add Flask to CI?
  • Not in this PR: outdir can still contain ../, and the build/run endpoints still have no require_api_key(), since that would need concore-editor to send the key.
  • On Windows, params values can't use "; single quotes still work.
  • Tested on Linux only; I don't have a Windows machine.

AI use: I used Claude (AI assistant) while working on this; I reviewed the changes and ran all tests myself.

On Windows, /build and /clear pass maxtime, params, fetch, outdir and
apikey into call(..., shell=True). list2cmdline does not escape & | > ^,
so maxtime=100&calc runs calc. Validate these args and return 400.
@github-actions

Copy link
Copy Markdown

🎉 Welcome aboard, @SahilKumar965! Thank you for your first pull request in concore.

Please ensure that you are contributing to the dev branch.

Your contribution means a lot to us. We'll review it shortly.

Please ensure you have reviewed our:

If you have any questions, feel free to ask. Happy coding!

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.

1 participant