Skip to content
Closed
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
47 changes: 47 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Python bytecode / caches
__pycache__/
*.py[cod]

# Virtual environments
.venv/
venv/
env/
ENV/

# Build / distribution artifacts
build/
dist/
*.egg-info/
.eggs/

# Test / lint / type-check caches
.pytest_cache/
.mypy_cache/
.ruff_cache/
.pyre/
.pyrefly/
.coverage
htmlcov/

# IDE / OS
.vscode/
.idea/
*.swp
.DS_Store

# NOTE: pyproject.toml, uv.lock, and .python-version are intentionally NOT
# ignored — commit them for reproducible uv-based development.
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ You can use the `security_scan` function to scan a pickle file and get a report
of the findings.

```py
import safer_pickle
import saferpickle
import pickle

class MyObject:
Expand All @@ -46,7 +46,7 @@ class MyObject:
my_object = MyObject("some data")
pickle_bytes = pickle.dumps(my_object)

scan_results = safer_pickle.security_scan(pickle_bytes)
scan_results = saferpickle.security_scan(pickle_bytes)

if scan_results["unsafe"] > 0:
print("Unsafe content found!")
Expand All @@ -67,47 +67,47 @@ security scan to all the standard pickle-like libraries (`pickle`, `_pickle`,
application from unsafe pickles.

```py
import safer_pickle
import saferpickle
import pickle

safer_pickle.hook_pickle()
saferpickle.hook_pickle()

# Now, any call to pickle.load() or pickle.loads() will be protected.
# For example, if you try to load a malicious pickle file, it will raise
# a safer_pickle.UnsafePickleDetectedError.
# a saferpickle.UnsafePickleDetectedError.

try:
# malicious_pickle_bytes is a pickle file that contains malicious code
pickle.loads(malicious_pickle_bytes)
except safer_pickle.UnsafePickleDetectedError as e:
except saferpickle.UnsafePickleDetectedError as e:
print(f"Blocked malicious pickle file: {e}")
```

### 3. Use `safer_pickle.load()` and `safer_pickle.loads()`
### 3. Use `saferpickle.load()` and `saferpickle.loads()`

You can also use `safer_pickle.load()` and `safer_pickle.loads()` as direct
You can also use `saferpickle.load()` and `saferpickle.loads()` as direct
replacements for `pickle.load()` and `pickle.loads()`. These functions provide
more control over the security scan.

```py
import safer_pickle
import saferpickle

# This will raise a safer_pickle.UnsafePickleDetectedError if the pickle is unsafe
# This will raise a saferpickle.UnsafePickleDetectedError if the pickle is unsafe
try:
obj = safer_pickle.loads(malicious_pickle_bytes)
except safer_pickle.UnsafePickleDetectedError as e:
obj = saferpickle.loads(malicious_pickle_bytes)
except saferpickle.UnsafePickleDetectedError as e:
print(f"Blocked malicious pickle file: {e}")

# You can also use a strict check, which is more aggressive in detecting
# potentially malicious content.
try:
obj = safer_pickle.loads(malicious_pickle_bytes, strict_check=True)
except safer_pickle.StrictCheckError as e:
obj = saferpickle.loads(malicious_pickle_bytes, strict_check=True)
except saferpickle.StrictCheckError as e:
print(f"Blocked by strict check: {e}")

# If you trust the source of the pickle file, you can bypass the security scan.

obj = safer_pickle.loads(pickle_bytes, allow_unsafe=True)
obj = saferpickle.loads(pickle_bytes, allow_unsafe=True)
```

### 4. Command-Line Interface (CLI)
Expand Down
1 change: 0 additions & 1 deletion __init__.py

This file was deleted.

Loading