-
Notifications
You must be signed in to change notification settings - Fork 0
fix: harden API key hashing with HMAC-SHA256 and clean up legacy changelog #292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,9 @@ class AuthConfig(BaseModel): | |
| before the first request is served. | ||
|
|
||
| Attributes: | ||
| jwt_secret: HMAC signing key (resolved at startup, repr-hidden). | ||
| jwt_secret: HMAC signing key for JWT tokens and API key | ||
| hashing (resolved at startup, repr-hidden). Rotating | ||
| this invalidates all stored API key hashes. | ||
| jwt_algorithm: JWT signing algorithm (HMAC family only). | ||
| jwt_expiry_minutes: Token lifetime in minutes. | ||
| min_password_length: Minimum password length for setup/change. | ||
|
|
@@ -52,7 +54,11 @@ class AuthConfig(BaseModel): | |
| jwt_secret: str = Field( | ||
| default="", | ||
| repr=False, | ||
| description="JWT signing secret (resolved at startup)", | ||
| description=( | ||
| "JWT signing secret (resolved at startup). " | ||
| "Also used as the HMAC key for API key hash computation — " | ||
| "rotating this secret invalidates all stored API key hashes." | ||
| ), | ||
| ) | ||
|
Comment on lines
54
to
62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JWT secret rotation silently breaks all API key authentication
Consider raising a startup warning (or at minimum a Prompt To Fix With AIThis is a comment left during a code review.
Path: src/ai_company/api/auth/config.py
Line: 54-62
Comment:
**JWT secret rotation silently breaks all API key authentication**
`jwt_secret` now serves two distinct security purposes: JWT signing/verification and HMAC key for API key hashing. The field description documents this, but the operational consequence is a sharp footgun: a developer who rotates `jwt_secret` specifically to invalidate all active JWT sessions (a routine post-incident response) will also silently invalidate every stored API key hash in the database — without any warning at startup or rotation time.
Consider raising a startup warning (or at minimum a `logger.warning`) when the secret changes relative to the previously persisted value, so operators are aware that API keys will need to be regenerated. Alternatively, a separate `api_key_hmac_secret` field would fully decouple the two rotation lifecycles.
How can I resolve this? If you propose a fix, please make it concise. |
||
| jwt_algorithm: Literal["HS256", "HS384", "HS512"] = Field( | ||
| default="HS256", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using jwt_secret as the HMAC key only protects API key hashes if that secret is stored separately from the leaked data. In the default setup, the JWT secret is persisted in the same persistence backend (settings table), so a full DB dump would still enable offline guessing. Consider introducing a separate, non-persisted API-key hashing secret (env/KMS) or explicitly documenting the threat model/assumptions here.