Skip to content

feat: validate user agent for admin access token#118

Merged
think-in-universe merged 23 commits intomainfrom
user-agent-authentication
Nov 20, 2025
Merged

feat: validate user agent for admin access token#118
think-in-universe merged 23 commits intomainfrom
user-agent-authentication

Conversation

@alexplash
Copy link
Contributor

@alexplash alexplash commented Oct 28, 2025

Made it so admin access tokens can only be used with the same User-Agent as when the token was initialized.


Note

Enforces User-Agent matching for admin access tokens by storing UA on creation and validating on use; updates middleware, routes, DB schema/repo, and adds e2e tests.

  • Auth/Middleware:
    • Admin tokens (adm_ prefix) validated only as admin tokens (no session fallback) and now require matching User-Agent.
    • Extracts User-Agent from requests and passes to authenticate_admin_access_token.
  • Routes:
    • POST /v1/admin/access-tokens captures request User-Agent and persists it with the token.
  • Database:
    • Adds user_agent column to admin_access_token (migration V0024__...).
    • Extends models::AdminAccessToken with optional user_agent.
  • Repositories (AdminAccessTokenRepository):
    • create(...) now stores user_agent.
    • validate(token, user_agent) checks token is active, not expired, and UA matches (or token has no UA); updates last_used_at.
  • Tests:
    • New e2e tests for UA match (200) and mismatch (401); existing tests updated to use new behavior.

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

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@think-in-universe
Copy link
Contributor

I think we can also add user agent validation for refreshing access tokens as mentioned in #106

@PierreLeGuen PierreLeGuen self-requested a review October 30, 2025 23:46
@PierreLeGuen PierreLeGuen self-requested a review October 30, 2025 23:48
@alexplash alexplash force-pushed the user-agent-authentication branch from 383be56 to 18b5424 Compare October 31, 2025 20:18
@alexplash alexplash linked an issue Oct 31, 2025 that may be closed by this pull request
@PierreLeGuen PierreLeGuen self-requested a review November 1, 2025 00:00
cursor[bot]

This comment was marked as outdated.

Copy link

@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.

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on December 9

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

name: String,
creation_reason: String,
expires_at: chrono::DateTime<Utc>,
user_agent: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why keeping user_agent optional if we enforce it in #131?

Copy link
Contributor

@think-in-universe think-in-universe Nov 20, 2025

Choose a reason for hiding this comment

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

It's preferred to enforce user agent for security reason, so we did that in #130.

The reason to keep the user agent optional for #118 is to avoid payment service abortion before we can create a new admin access token with user-agent.

@PierreLeGuen PierreLeGuen self-requested a review November 20, 2025 00:32
@think-in-universe think-in-universe merged commit 974ee01 into main Nov 20, 2025
2 checks passed
@think-in-universe think-in-universe deleted the user-agent-authentication branch November 20, 2025 02:08
henrypark133 added a commit that referenced this pull request Nov 20, 2025
* feat: implement batch conversation retrieval endpoint

Add GET /v1/conversations/batch endpoint to fetch multiple conversations
in a single request using SQL ANY() queries instead of N individual calls.

Changes:
- Add batch_get_by_ids() to ConversationRepository trait and implement
  with efficient WHERE id = ANY($1) SQL query
- Add batch_get_conversations() to service trait and implement
- Create BatchConversationsRequest and ConversationBatchResponse models
- Implement route handler with:
  * JSON body input (no URL length limits)
  * Validation: 1-1000 IDs per request
  * Returns found conversations + missing_ids list (AWS DynamoDB pattern)
- Register GET /v1/conversations/batch route (before /{id} to avoid conflicts)
- Add comprehensive integration test verifying:
  * Batch retrieval of 5 IDs (3 found, 2 missing)
  * Correct response structure
  * Missing IDs properly tracked

Performance: Reduces N individual API calls to 1 batch call (100x faster)

* fix: only include model providers with valid attestation report (#187)

* feat: validate user agent for admin access token (#118)

* feat: rotate refresh token and access token with user agent check (#131)

Co-authored-by: Robert Yan <46699230+think-in-universe@users.noreply.github.com>

* Updated GET to POST and updated response structure

* remove the order by and simplified the logic

---------

Co-authored-by: Robert Yan <46699230+think-in-universe@users.noreply.github.com>
Co-authored-by: alexplash <131205674+alexplash@users.noreply.github.com>
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.

Issue: admin session_token does not validate User-Agent

4 participants