Skip to content

feat: Implement HttpOnly cookies for access and refresh tokens in authentication routes#1

Merged
kemalcalak merged 6 commits into
mainfrom
token
Mar 8, 2026
Merged

feat: Implement HttpOnly cookies for access and refresh tokens in authentication routes#1
kemalcalak merged 6 commits into
mainfrom
token

Conversation

@kemalcalak
Copy link
Copy Markdown
Owner

@kemalcalak kemalcalak commented Mar 8, 2026

Note

Medium Risk
Changes authentication token transport (response bodies/headers to HttpOnly cookies) and request authentication behavior, which can break existing clients and impacts security assumptions (cookie handling/CSRF posture). Scope is contained to auth routes, auth dependency, and tests.

Overview
Authentication now primarily uses HttpOnly cookies instead of returning access_token in JSON responses.

POST /auth/login and POST /auth/refresh set/rotate the access_token cookie (and login still sets refresh_token scoped to the refresh path), while responses switch to CookieLoginResponse/CookieRefreshResponse that omit the access token. POST /auth/logout now clears both access_token and refresh_token cookies.

Request authentication (get_current_user) now reads the JWT from the access_token cookie first and falls back to an Authorization: Bearer header (via OAuth2PasswordBearer(auto_error=False)), and tests are updated to assert cookies and rely on the client cookie jar rather than manually setting auth headers.

Written by Cursor Bugbot for commit 4f1a664. This will update automatically on new commits. Configure here.

@kemalcalak
Copy link
Copy Markdown
Owner Author

@cursor review

1 similar comment
@kemalcalak
Copy link
Copy Markdown
Owner Author

@cursor review

Comment thread app/api/deps.py
@kemalcalak
Copy link
Copy Markdown
Owner Author

@cursor review

Comment thread app/api/deps.py
@kemalcalak
Copy link
Copy Markdown
Owner Author

@cursor review

Comment thread app/api/routes/auth.py
@kemalcalak
Copy link
Copy Markdown
Owner Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment thread app/schemas/token.py
message: str | None = None


class CookieLoginResponse(BaseModel):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LoginResponse class is now unused dead code

Low Severity

The LoginResponse class was replaced by CookieLoginResponse in the auth routes, but its definition was left behind in token.py. A grep confirms it is no longer imported or referenced anywhere in the codebase, making it dead code.

Fix in Cursor Fix in Web

@kemalcalak kemalcalak merged commit 64a8ea6 into main Mar 8, 2026
1 check 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.

1 participant