Skip to content

fix(auth): add JWT expiration, issued-at claims, and token validation - #96

Open
Lakshya-2440 wants to merge 4 commits into
alphaonelabs:mainfrom
Lakshya-2440:fix/jwt-token-expiry
Open

Lakshya-2440 wants to merge 4 commits into
alphaonelabs:mainfrom
Lakshya-2440:fix/jwt-token-expiry

Conversation

@Lakshya-2440

Copy link
Copy Markdown
Contributor

Resolves #34 (JWT expiry portion)

Summary

  • Add RFC 7519 compliant iat and exp claims to auth tokens generated by create_token().
  • Add strict expiration and future-dated token checks in verify_token() with configurable clock-skew leeway (leeway_seconds=60).
  • Add DEFAULT_JWT_TTL_SECONDS = 604800 (7 days) with environment override support via env.JWT_TTL_SECONDS.
  • Add return type annotation Optional[Dict[str, Any]] to verify_token().
  • Rename shadowed exp signature variable in verify_token() to expected_sig.
  • Add comprehensive unit test coverage in tests/test_tokens.py.

What was wrong

  1. Tokens lived forever: create_token() encoded no exp or iat claims, and verify_token() never validated token timestamps. Leaked tokens remained valid indefinitely.
  2. Variable shadowing: exp in verify_token() shadowed the expiration concept with HMAC signature hex string.

Verification

  • python3 -m py_compile src/worker.py (syntax passes cleanly)
  • pytest tests/test_tokens.py -v: 23 passed in 0.11s
  • Regression check across auth, sessions, profile, and dashboard suites: 180 passed in 0.88s

Checklist

  • Code compiled without syntax/type errors
  • New unit tests added covering expiry, missing exp, bad types, and clock skew
  • All existing tests pass cleanly without regression

Copilot AI balanced review requested due to automatic review settings October 13, 2026 20:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML; Path: .coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: e76e317b-f5a3-4a34-be0f-74c1d6716c24
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Security: JWT tokens have no expiry and admin page bypasses authentication

2 participants