PR 11 — Auth hardening phase 1: unified security module - #45
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a0653da939
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| hash_password, | ||
| token_subject_as_user_id, | ||
| verify_password, | ||
| verify_token, |
There was a problem hiding this comment.
Preserve the legacy utils verifier contract
Because this module is still presented as a compatibility layer, directly re-exporting the canonical verify_token changes the old app.utils.security.verify_token behavior: it now defaults to requiring an access-token type claim and returns the raw payload with sub, whereas the previous helper accepted tokens without an access type and returned {"user_id": ...}. Any existing code that kept importing this compatibility path and reads payload["user_id"] (or verifies refresh tokens from create_refresh_token() without passing a token type) will start failing at runtime; keep a small wrapper here if the old import path is meant to remain compatible.
Useful? React with 👍 / 👎.
Motivation
subis stored as a string in tokens and converted to an integer only at the authentication boundary to centralize validation.Userobject so authorization checks live at the same boundary.Description
app/security.py, adding_token_expiration, string-normalization ofsubincreate_token, a robustverify_token, and a boundary helpertoken_subject_as_user_idthat parses/validates the subject to an integer.app/utils/security.pywith compatibility wrappers that delegate to the canonicalapp.securityhelpers (create_access_token,create_refresh_token, etc.).get_current_userinapp/dependencies.pywhich usesverify_tokenandtoken_subject_as_user_idand returns an activeUserinstance or raises a 401.auth,links,analytics,users) to depend onget_current_userand acceptcurrent_user: User(instead of rawuser_id), and updated refresh flow to parse the refresh token subject viatoken_subject_as_user_id.tests/test_security.pyexercising subject normalization, token type enforcement, invalid subject handling, and the compatibility wrappers.Testing
pytest -qwhich executed the application tests including the newtests/test_security.pyand completed successfully (13 passed).utcnow()usage; no test failures occurred.black/ruffduring the change and all automated tests continued to pass after refactors.Codex Task