Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modelscan/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ class SupportedModelFormats:
"pdb": "*",
"shutil": "*",
"asyncio": "*",
"mailcap": [
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Self-review: this keeps the fix scoped to the specific stdlib gadget observed in the PoC. mailcap.findmatch can execute a mailcap test command through os.system(), so it belongs with the CRITICAL pickle globals.

"findmatch", # mailcap.findmatch executes matching entry test commands via os.system()
],
},
"HIGH": {
"webbrowser": "*", # Includes webbrowser.open()
Expand Down
25 changes: 25 additions & 0 deletions tests/test_pickle_unsafe_globals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pickle
from typing import Any

from modelscan.modelscan import ModelScan


class MaliciousMailcapFindmatch:
def __reduce__(self) -> Any:
import mailcap

caps = {"text/plain": [{"view": "cat %s", "test": "true"}]}
return mailcap.findmatch, (caps, "text/plain")


def test_scan_flags_mailcap_findmatch(tmp_path) -> None:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Self-review: this uses the public ModelScan().scan() path instead of importing the pickle scanner directly, so the regression follows the same path users hit from the CLI/API.

path = tmp_path / "mailcap.pkl"
path.write_bytes(pickle.dumps(MaliciousMailcapFindmatch()))

modelscan = ModelScan()
results = modelscan.scan(path)

assert results["summary"]["scanned"]["scanned_files"] == ["mailcap.pkl"]
assert results["summary"]["total_issues"] == 1
assert modelscan.issues.all_issues[0].details.module == "mailcap"
assert modelscan.issues.all_issues[0].details.operator == "findmatch"