Repository navigation
Fail CI on a new exec, eval or compile of a value that is not written out - #369
Conversation
… out A small replacement for the checker in the closed #365. That one grew to about ten thousand lines over seventy review rounds, and measured against the same tree the extra machinery bought a smaller baseline rather than a finding this misses. The rule: the first argument to the exec, eval or compile BUILTIN must be a written-out string. A name, a call, or an f-string with a placeholder is reported. Matching the bare name and not an attribute matters - counting re.compile and model.eval as sinks reported 69 false positives across the two library repositories. Notebooks are read as well, since they are the maintained source here. Magic and shell lines are blanked rather than dropped so reported line numbers still point at the cell. Four existing call sites are recorded with a justification each: three notebooks run the Studio chat module they have just downloaded, and the GRPO notebook runs a model-generated program through the sandbox added in unsloth-zoo#1105. An entry keeps the call's own text rather than its line number, so moving code does not churn it, and a count, so a new call cannot hide behind a removed one. The gate refuses to pass while any entry lacks a reason, and --update carries existing reasons across rather than resetting them. Worth recording: CodeQL default setup runs here with Python enabled and raises other injection findings on these repositories, py/path-injection among them, but has never once raised py/code-injection - including while exec of an HTTPS response body sat in unsloth. This class is not covered by what already runs.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9837bdda83
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # A notebook that does not parse as one module is ordinary: a cell may be | ||
| # mid-edit, or depend on an earlier `%%capture`. Nothing to check, and | ||
| # failing the build for it would be noise. | ||
| return [] |
There was a problem hiding this comment.
Scan parseable cells instead of skipping the whole notebook
When concatenating any notebook's cells produces a syntax error, this returns no findings for the entire file, including otherwise valid cells containing a new exec(download()). In the reviewed tree this silently skips 347 of 445 notebooks under nb, 17 of 113 under original_template, and both kaggle notebooks, largely because independently valid cells do not form one valid module when joined. Scan cells independently (using the repository's existing notebook-magic stripping) so one problematic cell cannot disable the security gate for every other cell.
Useful? React with 👍 / 👎.
| print("\nSay why the value is trusted in the entry's `reason` field.") | ||
| return 1 | ||
|
|
||
| stale = sorted(k for k in allowed if k not in observed) |
There was a problem hiding this comment.
Reject partially stale baseline counts
When a baseline key allows two identical calls and one is removed, the key remains present in observed, so this stale check passes while retaining an allowance of two. A later same-digest call can therefore be added without failing the gate, exactly the baseline-reuse scenario the count is intended to prevent. Treat observed.get(key, 0) < allowed[key] as stale rather than checking only key membership.
Useful? React with 👍 / 👎.
A small replacement for the checker in #365, which I closed. That one reached about ten thousand lines over roughly seventy review rounds, and measured against the same tree the extra machinery bought a smaller baseline, not a finding this one misses.
The rule
The first argument to the
exec,evalorcompilebuiltin must be a written-out string. A name, a call, or an f-string with a placeholder is reported.Matching the bare name rather than an attribute is what makes it usable: counting
re.compile(...)andmodel.eval()as sinks reported 69 false positives across the two library repositories.Notebooks are read too, since they are the maintained source here. Magic and shell lines are blanked rather than dropped, so a reported line number still points at the right line of the cell.
What it finds here
Four call sites, each recorded with a reason:
nb/AMD-Unsloth_Studio.ipynbnb/Kaggle-Unsloth_Studio.ipynboriginal_template/Unsloth_Studio.ipynboriginal_template/gpt_oss_(20B)_GRPO_BF16.ipynbBoth shapes are real, which is the point: this is not a gate over an empty set.
The baseline
An entry keys on the call's own text rather than its line number, so moving code does not churn it, and carries a count, so a new call cannot hide behind a removed one. The gate refuses to pass while any entry lacks a
reason, and--updatecarries existing reasons across instead of resetting them to nothing.Why this class needs a gate at all
CodeQL default setup runs on this org with Python enabled, and it works: unsloth has raised
py/stack-trace-exposure,py/incomplete-url-substring-sanitizationand fivepy/path-injectionalerts. But there has never been a singlepy/code-injectionalert on either library repository, in any state, whileexecof an HTTPS response body sat inunsloth/models/loader_utils.pyuntil unslothai/unsloth#9777. So this class is not covered by what already runs.Checks
--self-testpasses on 3.9 and 3.13, and runs in CI ahead of the gate--update, and an unjustified entry failing the gateSource lintjob; the scan is under a second here