Skip to content

Conversation

@orhanrauf
Copy link
Contributor

@orhanrauf orhanrauf commented Oct 28, 2025

Summary

Fixes timing attack vulnerabilities in API key and OAuth1 token validation by replacing plain string comparisons with constant-time comparison functions.

Changes

  • API Key Validation (crud_api_key.py): Use secrets.compare_digest() instead of == for API key comparison
  • OAuth1 Token Validation (crud_connection_init_session.py): Use secrets.compare_digest() for OAuth token comparison

Security Impact

  • Risk Level: Medium
  • CASA Requirement: CASA-45 - Constant-time cryptographic operations
  • Attack Vector: Timing side-channel attacks that could enumerate valid credentials
  • Remediation: Simple drop-in replacements with no behavioral changes

Testing

  • Existing E2E tests cover API key authentication flows
  • No breaking changes - secrets.compare_digest() is functionally identical to ==
  • GitHub Actions will run full test suite

Closes #ENG-183


Summary by cubic

Hardens auth by using constant-time comparisons for API keys and OAuth1 tokens, and moves the Donke function key from URL query params to the x-functions-key header. Mitigates timing and credential leakage risks and meets CASA-45 and CASA-11.

  • Bug Fixes
    • Use secrets.compare_digest() for API key and OAuth1 token validation to prevent timing attacks.
    • Send the Donke function key in the x-functions-key header instead of ?code= to avoid key exposure in logs and history.

Replace ?code= query parameter with x-functions-key header in all Donke
API calls to comply with CASA-11 security requirements.

Changes:
- webhook_handler.py: Update notify-subscription and send-team-welcome-email calls
- organizations.py: Update notify-signup call

Azure Functions with AuthLevel.FUNCTION natively support both query param
and header authentication. This change prevents API key exposure in server
logs, browser history, and network monitoring tools.

Fixes: ENG-165
…validation

- Replace plain string comparison with secrets.compare_digest() in API key validation
- Replace plain string comparison with secrets.compare_digest() in OAuth1 token validation
- Prevents timing side-channel attacks that could leak credentials character-by-character

Fixes CASA-45 compliance requirement for constant-time cryptographic operations.
Addresses ENG-183.
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Copy link
Collaborator

@felixschmetz felixschmetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, but needs rebase

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