Skip to content

Restrict backend key unpickling#329

Open
dipeshbabu wants to merge 2 commits into
ekzhu:masterfrom
dipeshbabu:agent/restrict-backend-key-unpickling
Open

Restrict backend key unpickling#329
dipeshbabu wants to merge 2 commits into
ekzhu:masterfrom
dipeshbabu:agent/restrict-backend-key-unpickling

Conversation

@dipeshbabu

Copy link
Copy Markdown
Contributor

What

Route synchronous and asynchronous LSH key serialization through a restricted loader that rejects global construction opcodes, persistent IDs, and non-hashable results. Validate keys before insertion and document the supported key types and migration impact.

Why

Redis and other external backends can return tampered bytes. Passing those bytes to the standard pickle loader can invoke attacker-selected global callables during a query.

Impact

Primitive built-in keys continue to round-trip. Custom class keys now fail before insertion, and existing indexes using them must migrate to supported built-in values. Malicious or corrupt backend values raise an unpickling error without executing their payload.

Root cause

Backend data was treated as trusted and decoded with unrestricted pickle.loads calls.

Checks

  • uv run pytest -q test/test_lsh.py test/test_lshensemble.py test/test_integration.py test/aio/test_lsh.py (33 passed, 94 backend-service tests skipped locally)
  • executable-payload regression confirms no side effect occurs
  • uv run ruff check on changed Python files
  • uvx pyright (0 errors)
  • uv run python -m compileall -q datasketch
  • git diff --check

@codecov-commenter

codecov-commenter commented Jul 19, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (master@3da96a5). Learn more about missing BASE report.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #329   +/-   ##
=========================================
  Coverage          ?   72.94%           
=========================================
  Files             ?       22           
  Lines             ?     2828           
  Branches          ?        0           
=========================================
  Hits              ?     2063           
  Misses            ?      765           
  Partials          ?        0           
Flag Coverage Δ
unittests 72.94% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dipeshbabu
dipeshbabu force-pushed the agent/restrict-backend-key-unpickling branch from ccdc4e0 to a4cb2a7 Compare July 22, 2026 05:39
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