Repository navigation
Supply chain: load-time deserialization win condition + hardened toggle - #35
Open
afshinlamei wants to merge 4 commits into
Open
afshinlamei wants to merge 4 commits into
afshinlamei wants to merge 4 commits into
Conversation
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
left a comment
Collaborator
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements item 2 of #32: the supply-chain lab had no win condition and no hardened comparison, and the saved
.pklfiles 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 ontodevelopmentso only the backend commit remains. Review the commitAdd load-time deserialization win condition to supply_chainfor the changes here.What this adds
SentimentModel_reduce_malicious— payload carried in__reduce__, sopickle.load/torch.loadexecute 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 workingos.systemgadget. The class and lab text note that a real attacker returns(os.system, (...)), which is what ModelScan / picklescan flag.load_saved_model(hardened)— unsafepickle.load(payload runs → solved) vs. aRestrictedUnpicklerthat 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.POST /save-reduce-malicious-model,POST /load-saved-model.docs/labs.md: objective and hint rewritten around the win condition.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.
ruffpasses on all changed files. Route-level functional tests require the full app stack (and only run in CI once PRs todevelopmenttrigger tests — see #34).Addresses #32 (item 2).
🤖 Generated with Claude Code