Skip to content

studio: harden lockfile audit followups for #5604 - #5695

Merged
oobabooga merged 6 commits into
mainfrom
followup-lockfile-audit-regressions
Aug 25, 2026
Merged

oobabooga merged 6 commits into
mainfrom
followup-lockfile-audit-regressions

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Followup to #5604. Three regressions surfaced in the reviewer rounds after that PR landed; all addressed here with matching pytest coverage.

  • unsupported-lockfile-version is now blocking again. Default mode previously exited 0 on a v1 lockfile because the structural walk only runs on v2/v3, so blocked-known-malicious / known-ioc-string findings could not be produced. A checked-in package-lock.json could be downgraded to v1 and silently bypass the audit. Restored to BLOCKING_KINDS.
  • UNSLOTH_LOCKFILE_AUDIT_SKIP warnings now route through _gha_escape(). Both the invalid-skip branch (raw _skip_raw echoed) and the accepted-skip branch (_skip echoed) interpolated user-controlled text into ::warning:: workflow commands. A value containing \n::error::... produced a second physical workflow-command line. The new _gha_escape() helper added by ci: advisory lockfile supply-chain audit (no install-script changes) #5604 already covers finding annotations; just wiring it in here closes the same surface for the skip path.
  • studio-tauri-smoke.yml and release-desktop.yml now run the lockfile audit before npm install. Both consume studio/package-lock.json (added as a default audit target in ci: advisory lockfile supply-chain audit (no install-script changes) #5604) but ran npm install before any audit step, defeating the "pre-install" guarantee. release-desktop.yml additionally has contents: write, so the gap had real publish-attacker blast radius.

Default-mode audit still rc=0 on the three real lockfiles. No behaviour change for users not under attack.

Test plan

  • python -m pytest tests/security/test_lockfile_supply_chain_audit.py -v — 16/16 pass (4 new):
    • test_unsupported_lockfile_version_blocks_default — v1 lockfile must exit 1 in default mode
    • test_blocking_kinds_contains_unsupported_lockfile_version — module-level pin against future regressions
    • test_skip_env_warning_escapes_workflow_command_injection — both skip branches must escape \n / % so no injected ::-prefixed physical line appears
    • test_audit_runs_before_npm_install_in_consumer_workflows — regex-based ordering check on run: lines in both consumer workflows
  • python scripts/lockfile_supply_chain_audit.py on real repo lockfiles → rc=0, 0 findings
  • CI: lockfile-audit.yml, studio-tauri-smoke.yml, release-desktop.yml workflows green on this branch

Three regressions surfaced after #5604 landed. All addressed here with
matching pytest coverage.

1. Default mode no longer blocks on `unsupported-lockfile-version`. A
   lockfile downgraded to v1 (or bumped to an unsupported future
   version) silently passes default CI because the auditor's structural
   walk only runs on v2/v3, so `blocked-known-malicious` /
   `known-ioc-string` findings cannot be produced. v1 downgrade is a
   documented supply-chain attack shape; restoring it to BLOCKING_KINDS.

2. `UNSLOTH_LOCKFILE_AUDIT_SKIP` warnings interpolated the raw env var
   value into `::warning::` workflow commands without `_gha_escape()`,
   so a value containing `\n::error::...` was emitted as a second
   physical workflow-command line (GH Actions parses workflow commands
   per physical line). Routing both branches through `_gha_escape()`
   collapses any control char onto a single annotation line.

3. The two workflows that consume `studio/package-lock.json` --
   `studio-tauri-smoke.yml` and `release-desktop.yml` -- did not invoke
   `scripts/lockfile_supply_chain_audit.py` before their `npm install`
   steps. Lifecycle scripts in a compromised lockfile would run before
   the audit could refuse the lockfile, defeating the script's
   "pre-install" guarantee. `release-desktop.yml` additionally has
   `contents: write`, so the gap had real publish-attacker blast
   radius. Both workflows now run the audit before any `npm install`
   or `npm ci`.

Tests
-----
- test_unsupported_lockfile_version_blocks_default: v1 lockfile must
  exit 1 in default mode.
- test_blocking_kinds_contains_unsupported_lockfile_version: direct
  module-level pin against future regressions.
- test_skip_env_warning_escapes_workflow_command_injection: both
  skip-env branches must escape `\n` / `%` so no injected physical
  workflow-command line is produced.
- test_audit_runs_before_npm_install_in_consumer_workflows: regex
  ordering check on the `run:` lines in the two consumer workflows so
  a future reorder cannot silently bring back the pre-install gap.

16/16 pytest pass; default-mode audit still rc=0 on real lockfiles.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the lockfile supply chain audit script by making unsupported lockfile versions a blocking finding to prevent downgrade attacks. It also hardens the script against GitHub Actions workflow-command injection by escaping user-supplied environment variables in warning messages. Additionally, new regression tests were added to verify these security improvements and ensure the audit runs before package installation in CI workflows. I have no feedback to provide.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 70a090fd26

ℹ️ 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".

# Tauri CLI install or frontend install below could publish
# attacker-controlled binaries through the release. The audit
# refuses the run before any npm lifecycle script executes.
run: python3 scripts/lockfile_supply_chain_audit.py

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Use cross-platform Python launcher for audit step

In .github/workflows/release-desktop.yml (checked the build matrix in this file), the job runs on windows-latest but this new step invokes python3 directly before any interpreter fallback is applied; later in the same job, another step explicitly falls back from python3 to python, which indicates python3 is not assumed everywhere. If the Windows runner lacks a python3 command in Git Bash, this step fails early and blocks the Windows desktop release build even though Python is otherwise available.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked this against the runner rather than the convention, and python3 does resolve under shell: bash on windows-latest.

desktop-app-clean-machine-ci.yml's desktop windows job runs python3 .github/scripts/resolve-desktop-release.py from a step whose shell line is C:\Program Files\Git\bin\bash.EXE --noprofile --norc -e -o pipefail, whose only preceding step is actions/checkout, and which has no actions/setup-python. It printed resolved release tag: v0.1.803-beta in run 32856918209 earlier today. The tool-cache Python the image puts on PATH ships a python3.exe: actions/python-versions creates it in installers/win-setup-template.ps1 with New-Item -Path "$PythonArchPath\python3.exe" -ItemType SymbolicLink -Value "$PythonArchPath\python.exe".

The two command -v python3 || python fallbacks elsewhere in this job were introduced defensively along with their own steps in #5341 and #7172, not after an observed failure, and the python rather than python3 comment in studio-tauri-smoke.yml sits on a job that pins setup-python regardless. The Windows leg is not blocked by this step, so I am leaving it as it is.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request May 22, 2026
Each PR ran the same staged source files before, which went stale when
the upstream PR commits advanced. Refactor to one job per PR with an
actions/checkout of that PR's head ref, so cross-OS validation
always uses the latest commit:

  - PR unslothai#5603 sandbox            -> studio-sandbox-hardening
  - PR unslothai#5620 parser parity      -> studio-tools-multi-format-v2
  - PR unslothai#5696 mtp reload guards  -> followup-mtp-reload-guards (unslothai#5582 followup)
  - PR unslothai#5695 lockfile audit     -> followup-lockfile-audit-regressions (unslothai#5604 followup)

4 jobs x 3 OSes = 12 runs; Windows = 4 (below the 5-concurrent cap).
cancel-in-progress per (workflow, ref) keeps iteration cheap.

All tests stay CPU-only and rely on the CUDA spoof harness in
tests/conftest.py + tests/_zoo_aggressive_cuda_spoof.py, so no real GPU
is required on any runner.
@danielhanchen

Copy link
Copy Markdown
Member Author

Confirmed against main: unsupported-lockfile-version is still missing from BLOCKING_KINDS in scripts/lockfile_supply_chain_audit.py, the skip warnings still echo the raw env value unescaped, and release-desktop.yml runs both npm installs with no audit step ahead of them. Will get this reviewed.

@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c230bd7b1e

ℹ️ 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".

Comment on lines +557 to +559
install_re = re.compile(
r"^\s*run:\s*(?:.*&&\s*)?npm\s+(?:install|ci)\b", re.MULTILINE
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check block-scalar installs within each workflow job

This regex only matches commands written on the same line as run:, so it ignores the npm ci commands inside run: | blocks in studio-tauri-smoke.yml. Moreover, audit_re.search() selects the first audit in the entire file rather than the audit in the install's job. Consequently, deleting the Windows or macOS audit steps—or moving either after its block-scalar install—would still leave the earlier Linux audit and make this regression test pass, allowing the pre-install guarantee it claims to enforce to regress unnoticed.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed, both halves. Deleting the whole windows-unit-tests audit step from studio-tauri-smoke.yml, or moving the macos-unit-tests one after its npm ci, left this test green. install_re never matches a run: | block scalar, and audit_re.search() only ever matched the Linux job's python3 invocation, since the Windows and macOS jobs pin setup-python and call python. The guard was checking 3 of the 6 npm install / npm ci steps across the two files, and none of the ones in the Windows and macOS jobs.

Fixed in fea770e. The check now parses each workflow with yaml.safe_load and walks steps per job, comparing (step index, offset within the run block) so an audit and an install sharing one run: block are still ordered against each other. It matches python as well as python3, and fails when a workflow yields no install step at all rather than passing vacuously. Deleting either audit step, moving either one after its block-scalar npm ci, and moving the release-desktop.yml audit after the Tauri CLI install all fail the test now; tests/security is 397 passed, 26 skipped.

@oobabooga

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fea770e1f8

ℹ️ 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".

# Branch B -- short skip value with embedded injection.
# The PRE-strip raw value is also interpolated in the rejected
# branch's warning, so it MUST be escaped too.
injected_short = "1\n::error::short-bad"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exercise the rejected skip branch

The supposed second branch still takes the accepted-skip path: after stripping, "1\n::error::short-bad" is longer than five characters and is not an invalid token, as the following comment acknowledges. Thus both cases only protect the accepted warning, and a regression that removes _gha_escape() from the rejected warning would remain green even though values such as "1\n" reach that branch and interpolate the raw newline-bearing value. Use an invalid value whose raw form contains a control character but whose stripped form remains invalid, and assert that the audit runs as well as that the warning is escaped.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right on both counts, and the second one is the load-bearing half: "1\n::error::short-bad" strips to itself, which is neither booleanish nor under the 5-char floor, so it took the accepted path exactly like branch A. The rejected branch, the one that interpolates the pre-strip _skip_raw, had no coverage at all. test_skip_env_var_with_short_value_rejected reaches it but only with a plain "1", which carries no control character and so cannot distinguish escaped from unescaped output.

Verified by removing _gha_escape() from the rejected branch alone: the suite stayed at 19 passed.

Fixed in 0e98598. Branch B is now "1\n%", which strips to "1\n%" and is under the 5-char floor, so it lands on the rejected path, and it asserts the audit actually ran ([lockfile-audit] npm: plus rc 0 on the clean fixture) alongside %0A / %25 in the raw value and the warning staying on one physical line. The same mutation now fails, a mutation on the accepted branch still fails through branch A, and tests/security is 397 passed, 26 skipped.

On the payload shape: any value long enough to carry a complete ::command:: is at least five characters and therefore routes to the accepted branch, and the token path only admits whitespace around a booleanish word. So the rejected branch cannot be made to emit a second ::-prefixed workflow command; what escaping buys there is that the raw value cannot break the annotation into extra physical lines. Branch A keeps the full injection case.

@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0e98598fb3

ℹ️ 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".

Comment on lines +593 to +595
audit = audit_re.search(run)
if audit is not None and audited_at is None:
audited_at = (index, audit.start())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject commented-out audit commands

When an audit step is changed to a no-op such as run: "# python3 scripts/lockfile_supply_chain_audit.py", PyYAML still returns that comment as the step's run string and this regex sets audited_at, so the guard passes while the subsequent npm install executes without an audit. Fresh evidence beyond the earlier per-job/block-scalar issue is that the YAML-based rewrite still searches raw shell text without distinguishing executable commands from shell comments.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this one. Every run: line the audit and install patterns match in these two workflows is an executable command; none is a shell comment, so the failure is not reproducible without first authoring the broken workflow.

Beyond that, # is one of several ways to turn the step into a no-op that a static check cannot tell apart, and not the likeliest: if: false, continue-on-error: true and run: true leave the guard just as green, and none of them is text a matcher could filter out. Special-casing the comment form would read as tamper-resistance this check does not have. What it is for is ordering under ordinary edits, an audit step moved after an install or dropped from a job, which is what the per-job rewrite in fea770e made it catch.

# Tauri CLI install or frontend install below could publish
# attacker-controlled binaries through the release. The audit
# refuses the run before any npm lifecycle script executes.
run: python3 scripts/lockfile_supply_chain_audit.py

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Set up a TOML-capable Python before the release audit

On the ubuntu-22.04 release matrix leg, this invokes the image's unconfigured Python 3.10 without first installing tomli or selecting Python 3.11+, while the default audit also scans studio/src-tauri/Cargo.lock. audit_cargo_lockfile() therefore cannot import either tomllib or tomli, emits the blocking missing-toml-parser finding, and exits 1 before every Linux desktop release build; add setup-python before this step or otherwise provide the parser.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That invocation already runs on that image today and parses the Cargo.lock.

desktop-app-clean-machine-ci.yml's Build PR AppImage and studio-tauri-smoke.yml's Tauri Linux debug build are both runs-on: ubuntu-22.04 with no actions/setup-python, both reach a bare python3 scripts/lockfile_supply_chain_audit.py after the same checkout / apt deps / setup-node prelude the release build job has, and both print:

[lockfile-audit] cargo: .../studio/src-tauri/Cargo.lock
[lockfile-audit] OK: 0 findings across 3 npm + 1 cargo lockfile(s)

The Tauri one is run 32869635258 on this branch at 16:06 today. audit_cargo_lockfile() imports a parser there, so there is no missing-toml-parser finding and no rc 1. I did not pin down whether that is tomllib on a newer interpreter than the image README documents or a tomli in the image's site-packages, but the release leg runs the same command on the same label behind the same prelude, so the Linux desktop release build is not blocked by this step.

@oobabooga

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 0e98598fb3

ℹ️ 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".

@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 0e98598fb3

ℹ️ 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".

@oobabooga

Copy link
Copy Markdown
Member

This closes the three lockfile-audit regressions: unsupported lockfile formats now fail closed, audit-skip text is escaped before it reaches GitHub annotations, and the affected desktop workflows audit dependencies before npm lifecycle scripts can run.

I validated the result through:

  • 19 focused lockfile-audit tests and the broader security suite, with 397 passed and 26 skipped.
  • A cross-platform GitHub Actions run on Ubuntu 22.04, Windows latest, and macOS latest. Every leg passed the native audit, focused tests, pinned Tauri CLI installation, npm ci, and the production frontend build.
  • Direct before-and-after simulations confirming that unsupported v1 lockfiles now stop the build and crafted skip reasons can no longer create a second workflow-command line.

The remaining red repository test is a pre-existing source-encoding failure in an unchanged file, unrelated to this PR.

@oobabooga
oobabooga merged commit 61a6bc5 into main Aug 25, 2026
35 of 36 checks passed
@oobabooga
oobabooga deleted the followup-lockfile-audit-regressions branch August 25, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants