Skip to content

fix(auth): validate integer expiry before computing hmac signature in session_signer.py - #2

Open
Vishaaallll wants to merge 2 commits into
mainfrom
fix/session-signer-int-expiry-validation-order
Open

Vishaaallll wants to merge 2 commits into
mainfrom
fix/session-signer-int-expiry-validation-order

Conversation

@Vishaaallll

Copy link
Copy Markdown
Owner

Summary

Re-orders verification checks in session_signer.verify() in ods/extensions/services/dashboard-api/session_signer.py:

  • Parses and validates that expiry_str is a valid integer BEFORE computing the HMAC-SHA256 signature (_sign(payload)).
  • Returns (False, "malformed") immediately upon integer conversion failure.
  • Adds a unit test in test_session_signer.py asserting _sign() is never invoked when an invalid expiry token is passed.

Why It Is Useful

  • Optimizes Authentication Overhead: Avoids unnecessary CPU computation (hmac.new + SHA256 hashing) when processing invalid or corrupted session tokens.
  • Mitigates Denial-of-Service Risk: Prevents attackers from forcing repetitive cryptographic calculations using junk expiry values.
  • Defensive Execution Order: Ensures simple structural validation occurs prior to crypto operations.

Verification

  • Ran test suite pytest ods/extensions/services/dashboard-api/tests/test_session_signer.py -v (21 passed).

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.

3 participants