Fix cache poisoning vulnerability in IntermediateCache - #172
Closed
bhuvan-somisetty wants to merge 1 commit into
Closed
Fix cache poisoning vulnerability in IntermediateCache#172bhuvan-somisetty wants to merge 1 commit into
bhuvan-somisetty wants to merge 1 commit into
Conversation
IntermediateCache loaded its disk cache with allow_pickle=True from a predictable, shared path (tempfile.gettempdir()/osipy_cache), so on a shared machine another local user could plant a crafted .npz file that executed arbitrary code as soon as it was loaded via cache.get(). - Drop allow_pickle=True on load; cache entries are always plain ndarrays/JSON strings, so pickle support was unnecessary attack surface. - Scope the default cache directory per user instead of one shared name. - Refuse to use a cache directory that's a symlink or owned by another user, and restrict it to 0700 (POSIX only; no-op on Windows). - Write cache entries to a temp file and rename into place atomically. Fixes OSIPI#171
Contributor
Author
|
cc @ltorres6 @MohamedNasser8 for review |
Collaborator
|
Thanks for your contribution. I don't think we use the caching mechanism anymore and it should simply be removed. You are welcome to take on that issue #177 if you would like. |
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.
Fixes #171
IntermediateCacheloaded its disk cache withnp.load(cache_file, allow_pickle=True)from a path that's fully predictable (tempfile.gettempdir()/osipy_cache/<md5 hash>.npz, shared by every user on the box). On a shared machine that means another local user could plant a crafted.npzfile there and get arbitrary code executed the moment your process calledcache.get(...).Changes
allow_pickle=False. Cache entries only ever contain plain ndarrays and JSON-encoded strings, so pickle was never actually needed here, it was just unused attack surface.osipy_cache_<username>) instead of one name shared by everyone.0700. No-op on Windows (noos.getuid/POSIX permission bits there).Testing
TestCachePoisoningRegressionintests/unit/common/test_caching.py: plants a malicious.npzat the exact predictable path and confirmsget()returnsNonewithout executing the payload, checks the default dir is per-user scoped, and (POSIX-only, skipped on Windows) checks directory permissions, symlink rejection, and cross-user ownership rejection.pytest→ 777 passed, 43 skipped (GPU/data-dependent), 6 xfailed, same as onmain(verified the 8 pre-existingcli/test_config.py/cli/test_wizard.pyfailures are unrelated to this change, they fail identically onmaintoo, looks like a local package-metadata issue unrelated to caching).ruff check/ruff format --checkclean on the changed files.mypy osipy/common/caching.py: no new errors introduced (verified againstmainbefore this change); pre-existing strict-mode findings elsewhere in the file are untouched.