Replace SHA256 with PBKDF2-HMAC-SHA256 for key derivation#283
Merged
Conversation
Replace the single-round SHA-256 key derivation in get_key() with PBKDF2-HMAC-SHA256, a computationally expensive KDF resistant to brute-force attacks. Addresses CodeQL alert py/weak-sensitive-data-hashing (CWE-327/328/916). The salt is overridable via S3_LOG_EXTRACTION_SALT and key derivation stays deterministic so existing decrypt flows are unchanged. https://claude.ai/code/session_01BFG3smk8JoaTouHg69j7Ja
Add a password strength gate to get_key(): the value of S3_LOG_EXTRACTION_PASSWORD must meet a minimum length, distinct-character count, and estimated-entropy threshold, otherwise a ValueError is raised before any encryption runs. The thresholds accept randomly generated high-entropy secrets while rejecting short or low-variety human-chosen passwords. Exposes validate_password_strength for reuse. https://claude.ai/code/session_01BFG3smk8JoaTouHg69j7Ja
for more information, see https://pre-commit.ci
Add tests/test_encryption.py covering password strength validation, get_key behavior (missing env var, weak password rejection, deterministic Fernet key, salt override), and encrypt/decrypt and file round-trips. Tests are marked ai_generated and import only the public API. Also bump the version, add a CHANGELOG entry, switch the cryptography imports to the generic full-import style, and make the new single-argument helpers positional-only per the project conventions. https://claude.ai/code/session_01BFG3smk8JoaTouHg69j7Ja Co-Authored-By: Claude Code / Claude Opus 4.8 (1M context) <noreply@anthropic.com>
CodyCBakerPhD
commented
Jun 16, 2026
CodyCBakerPhD
commented
Jun 16, 2026
Consolidate the encryption tests into parametrized cases per review feedback, covering the non-ASCII and empty-password branches so the module is fully covered. Remove the trailing __all__ from encryption.py. Backfill the missing changelog entry for the stats CLI command (#224). https://claude.ai/code/session_01BFG3smk8JoaTouHg69j7Ja Co-Authored-By: Claude Code / Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Describe the stats CLI command and get_log_bucket_stats helper directly, as the entry would have read on its original PR. https://claude.ai/code/session_01BFG3smk8JoaTouHg69j7Ja Co-Authored-By: Claude Code / Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Replace the placeholder #N link with #273 for the IPInfo quota fallback fix. Add a changelog entry for the IP address classification statistics in the stats command and get_ip_stats helper (#274). https://claude.ai/code/session_01BFG3smk8JoaTouHg69j7Ja Co-Authored-By: Claude Code / Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #283 +/- ##
==========================================
+ Coverage 73.96% 76.62% +2.66%
==========================================
Files 40 40
Lines 1571 1660 +89
==========================================
+ Hits 1162 1272 +110
+ Misses 409 388 -21
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Summary
Improved the encryption key derivation mechanism by replacing a simple SHA256 hash with PBKDF2-HMAC-SHA256, a deliberately expensive key derivation function that provides better resistance to brute-force attacks.
Key Changes
hashlib.sha256()withPBKDF2HMACusing SHA256 algorithmS3_LOG_EXTRACTION_SALTenvironment variable with a stable default salt (b"s3_log_extraction")Implementation Details
S3_LOG_EXTRACTION_SALTenvironment variable for stronger separation when neededhttps://claude.ai/code/session_01BFG3smk8JoaTouHg69j7Ja