Skip to content

Add comprehensive test coverage for attack vectors and CVE patterns#221

Open
dguido wants to merge 2 commits intomasterfrom
add-picklescan-test-patterns
Open

Add comprehensive test coverage for attack vectors and CVE patterns#221
dguido wants to merge 2 commits intomasterfrom
add-picklescan-test-patterns

Conversation

@dguido
Copy link
Member

@dguido dguido commented Jan 23, 2026

Summary

  • Adopt test patterns from picklescan for improved detection coverage
  • Add 362 new tests covering malicious patterns, CVEs, and benign edge cases
  • Document known limitations in fickling's detection

New Test Files

test_attack_vectors.py (150+ tests)

Tests malicious pickle patterns across all protocols (0-5):

  • OS module attacks (os.system, os.popen, os.execv)
  • Subprocess attacks (subprocess.call, subprocess.Popen, subprocess.run)
  • Builtins attacks (eval, exec, compile, __import__, getattr)
  • Network attacks (socket.create_connection, socket.socket)
  • Code execution (runpy.run_path, cProfile.run, code.InteractiveInterpreter)
  • Import manipulation (importlib.import_module)
  • Code object creation (marshal.loads, types.FunctionType)
  • System access (ctypes.CDLL, pty.spawn, pydoc.locate)

test_cve_patterns.py (20+ tests)

Tests for three CVEs found in picklescan:

test_archive_scanning.py (30+ tests)

Tests malicious pickles in archive formats:

  • ZIP archives with malicious pickles
  • TAR archives with malicious pickles
  • Nested archive paths (PyTorch-style structures)
  • Protocol version matrix (0-5) in archives

test_benign_edge_cases.py (165 tests)

Tests benign patterns to prevent false positives:

  • Pure data structures (should be LIKELY_SAFE)
  • Standard library objects (datetime, uuid, decimal, etc.)
  • Collections (OrderedDict, Counter)
  • Custom classes (enum, dataclass, namedtuple)
  • NumPy arrays (optional)
  • False positive prevention (strings containing "exec", "eval", etc.)
  • Documented known limitations:
    • builtins module imports (range, slice) flagged as malicious (conservative approach)
    • Set parsing issues at protocols 4-5

Test plan

  • All 427 tests pass (362 new + 65 existing)
  • No regressions in existing tests
  • Linting passes

🤖 Generated with Claude Code

@dguido dguido requested a review from ESultanik as a code owner January 23, 2026 03:24
dguido and others added 2 commits February 20, 2026 14:47
Adopt test patterns from picklescan for improved detection coverage:

- test_attack_vectors.py: 150+ tests covering malicious pickle patterns
  across all protocols (0-5) including OS, subprocess, builtins, network,
  code execution, and import manipulation attacks

- test_cve_patterns.py: Tests for CVE-2025-10157 (submodule bypass),
  CVE-2025-10156 (ZIP CRC bypass), CVE-2025-10155 (file extension bypass)

- test_archive_scanning.py: Tests for malicious pickles in ZIP/TAR
  archives with protocol version matrix

- test_benign_edge_cases.py: 165 tests for safe patterns to prevent
  false positives, including pure data structures, stdlib objects,
  custom classes, and NumPy arrays. Documents known limitations where
  builtins module imports (range, slice) are conservatively flagged.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Extract shared helpers into test/_helpers.py to remove duplication
- Tighten ~25 severity assertions from > LIKELY_SAFE to >= LIKELY_OVERTLY_MALICIOUS
- Fix test_corrupted_zip_still_scanned: remove outer try/except that swallowed failures
- Fix test_submodule_bypass_os_path: use raw opcodes to preserve dotted module path
- Fix 3 tests broken after rebase (range, slice, set) with protocol-aware thresholds
- Parametrize 25 attack vector tests into ATTACK_VECTORS data table
- Parametrize 5 extension detection tests into EXTENSION_CASES data table
- Add EmptyTuple + Reduce opcodes to test_types_functiontype
- Use pytest.importorskip for numpy/sklearn, tmp_path for temp files
- Remove test_empty_zip_with_no_pickles (tested zipfile, not fickling)
- Narrow pytest.raises in test_zip_with_non_pickle_binary to ValueError

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dguido dguido force-pushed the add-picklescan-test-patterns branch from 3937128 to c53dd58 Compare February 20, 2026 22:04
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.

1 participant