fix: reject empty HMAC keys in audit sign/verify#554
Merged
maziyarpanahi merged 2 commits intoJun 22, 2026
Conversation
_audit_report.sign/verify previously accepted empty strings and b'' as valid HMAC keys, producing worthless signatures with no warning. Added validation in _key_bytes to raise ValueError when the key is empty, ensuring a non-empty key is always required. Fixes maziyarpanahi#529
maziyarpanahi
approved these changes
Jun 22, 2026
maziyarpanahi
left a comment
Owner
There was a problem hiding this comment.
Thank you @muhamedfazalps. I reviewed this against #529 / OM-339 and added one maintainer follow-up commit: test: cover missing audit HMAC keys.
What I changed:
- made
None, empty string, and empty bytes all raise the same clearValueErrorfor audit signing and verification; - validated the verification key before comparing signatures so missing/empty verification keys are rejected distinctly from a wrong key;
- documented the non-empty HMAC key requirement in
AuditReport.sign()andAuditReport.verify(); - added regression coverage for signing with missing/empty keys, verifying with missing/empty keys, and unsigned-report verification with a valid key.
Verification on the current PR checkout:
PYTHONPATH=/private/tmp/openmed-pr-554 /Users/maziyar/Developer/openmed/.venv/bin/python -m pytest tests/unit/core/test_audit_report.py -q-> 10 passed/Users/maziyar/Developer/openmed/.venv/bin/ruff check openmed/core/audit.py tests/unit/core/test_audit_report.py-> passed/Users/maziyar/Developer/openmed/.venv/bin/ruff format --check openmed/core/audit.py tests/unit/core/test_audit_report.py-> passed
I also copied the labels from #529 onto the PR. The branch is mergeable with no conflicts; GitHub has not attached hosted checks to the new head commit yet, so I verified the touched behavior locally.
Contributor
Author
|
Thanks for merging! 🎉 If this fix helped, consider supporting: https://buymeacoffee.com/muhamedfazalps |
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.
Problem
AuditReport.sign/verify accepts empty strings and b'' as valid HMAC keys, producing worthless signatures with no warning. This is a silent security weakness for a signed-audit feature.
Fix
Added validation in
_key_bytesto raiseValueErrorwhen the key is empty. This ensures a non-empty key is always required for signing and verification.Fixes #529
If this helps, consider buying me a coffee! https://buymeacoffee.com/muhamedfazalps