Skip to content

Supply chain: load-time deserialization win condition + hardened toggle - #35

Open
afshinlamei wants to merge 4 commits into
OWASP:developmentfrom
afshinlamei:fix/supply-chain-deserialization
Open

afshinlamei wants to merge 4 commits into
OWASP:developmentfrom
afshinlamei:fix/supply-chain-deserialization

Conversation

@afshinlamei

Copy link
Copy Markdown

Implements item 2 of #32: the supply-chain lab had no win condition and no hardened comparison, and the saved .pkl files were inert on load (both existing payloads sit in __init__, which pickle does not call).

Depends on #30

This is stacked on #30 (fix/supply-chain-content), so the diff currently includes #30's two content commits. Please merge #30 first; I'll then rebase this onto development so only the backend commit remains. Review the commit Add load-time deserialization win condition to supply_chain for the changes here.

What this adds

  • SentimentModel_reduce_malicious — payload carried in __reduce__, so pickle.load / torch.load execute it while restoring the file, not on construction. The payload is deliberately benign (writes a marker file) so the lab proves code ran on load without shipping a working os.system gadget. The class and lab text note that a real attacker returns (os.system, (...)), which is what ModelScan / picklescan flag.
  • load_saved_model(hardened) — unsafe pickle.load (payload runs → solved) vs. a RestrictedUnpickler that allows only safe data types (weights-only stand-in; payload refused → not solved).
  • evaluate_supply_chain_solve — a solve counts only when the payload ran via the unsafe loader; hardened mode never counts.
  • Routes: POST /save-reduce-malicious-model, POST /load-saved-model.
  • UI: "Win Condition: Load-Time Deserialization" panel with a Hardened-mode toggle and a solved/blocked banner.
  • docs/labs.md: objective and hint rewritten around the win condition.
  • Tests: unit + functional coverage for the solve matrix, construct-vs-load timing, and the hardened block.

Testing

Backend functions exercised against the real module in a Python 3.12 venv: construction does not fire the payload; unsafe load fires it and solves; hardened load blocks it and does not solve; missing-file handled. ruff passes on all changed files. Route-level functional tests require the full app stack (and only run in CI once PRs to development trigger tests — see #34).

Addresses #32 (item 2).

🤖 Generated with Claude Code

afshinlamei and others added 3 commits October 4, 2026 22:49
Re-checked the previous content corrections against the code:

- Both payloads live in __init__ and fire when the class is constructed.
  The XSS class has no __getattribute__ and the demo route never calls
  predict, so the "fires at inference time" text and code sample were
  wrong. Code samples now show the real classes.
- pickle.load does not call __init__ and the classes define no
  __reduce__, so the saved .pkl files are inert on load. The page no
  longer says loading them runs the payload.
- Manual: fix the supply-chain objective, hint and table row anchor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Addresses issue OWASP#32 (item 2): the existing demos hide their payload in
__init__, so unpickling the saved .pkl files runs nothing and the lab has
no objective to complete or hardened comparison.

- SentimentModel_reduce_malicious carries its payload in __reduce__, so
  pickle.load executes it while restoring the FILE (not on construction).
  The payload is deliberately benign (writes a marker file) so the lab can
  prove code ran on load without shipping a weaponised os.system gadget.
- load_saved_model(hardened) loads the saved file either with an unsafe
  pickle.load (payload runs -> solved) or a RestrictedUnpickler that allows
  only safe data types (weights-only stand-in; payload refused -> not solved).
- evaluate_supply_chain_solve: solve counts only when the payload ran via the
  unsafe loader; hardened mode never counts.
- Routes: POST /save-reduce-malicious-model, POST /load-saved-model.
- supply_chain.html: "Win Condition: Load-Time Deserialization" panel with a
  Hardened mode toggle and a solved/blocked banner.
- docs/labs.md: objective and hint rewritten around the win condition.
- Unit + functional tests for the solve matrix, construct-vs-load timing,
  and the hardened block.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@maryammouzarani2024 maryammouzarani2024 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you very much!

It is better to revise the current demonstrated vulnerability and add the payload to the reduce function, instead of creating a new variant.

Please do not add a new section to the main layout of description, demonstration and mitigation strategies.

Try to make the text as short as possible and add long text to the description section.

… feedback)

Addresses maintainer review on OWASP#35:
- Instead of a new class + section, the existing SentimentModel_bash_malicious
  now defines __reduce__, so loading its saved .pkl executes code on load. The
  payload stays a benign marker (_record_load_proof), not a shell gadget.
- Removed SentimentModel_reduce_malicious, save_reduce_malicious_model, the
  /save-reduce-malicious-model route, and the standalone "Win Condition" panel.
- Hardened load is an inline checkbox in the existing OS Command demonstration,
  cross-referenced from the Mitigation section (weights-only fix).
- Updated intro/How-It-Works copy, docs/labs.md hint, and unit + functional
  tests to drive the win condition through the bash model's saved file.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

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