Skip to content

Fix service token generation#1731

Merged
MarceloRGonc merged 1 commit intomainfrom
mg/OPS-3197
Dec 4, 2025
Merged

Fix service token generation#1731
MarceloRGonc merged 1 commit intomainfrom
mg/OPS-3197

Conversation

@MarceloRGonc
Copy link
Copy Markdown
Contributor

Fixes OPS-3197.

Copilot AI review requested due to automatic review settings December 4, 2025 14:37
@linear
Copy link
Copy Markdown

linear Bot commented Dec 4, 2025

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 4, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mg/OPS-3197

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

Copy link
Copy Markdown
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

This PR fixes service token generation by filtering out JWT-specific metadata fields before creating new service tokens. The issue (OPS-3197) was likely caused by including exp, iat, and iss fields from an existing principal when generating a new token, which could lead to invalid or expired tokens.

Key changes:

  • Destructures and excludes JWT metadata fields (exp, iat, iss) from the principal before token signing
  • Preserves all other principal properties in the new service token payload

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

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Dec 4, 2025

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Dec 4, 2025

Greptile Overview

Greptile Summary

Fixed JWT claim double-encoding bug in generateServiceToken by filtering out standard JWT claims (exp, iat, iss) before re-signing.

  • When converting a user JWT to a service JWT, the decoded principal included JWT metadata fields (exp, iat, iss)
  • These fields were being passed directly to jwtUtils.sign(), which adds its own fresh JWT claims
  • This resulted in nested or conflicting JWT claims in the service JWT
  • The fix destructures the principal to exclude these three standard JWT claims before signing
  • The jwtUtils.sign() function now correctly adds fresh exp, iat, and iss values without conflicts

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix correctly addresses JWT claim conflicts by filtering standard claims before re-signing, uses proper TypeScript destructuring, and follows JWT best practices by letting the library manage claim generation
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/server/api/src/app/authentication/context/access-token-manager.ts 5/5 Fixed service token generation by excluding JWT standard claims (exp, iat, iss) from being re-encoded in the new token, preventing double-encoding issues

Sequence Diagram

sequenceDiagram
    participant Client
    participant generateServiceToken
    participant extractPrincipal
    participant jwtUtils

    Client->>generateServiceToken: user JWT
    generateServiceToken->>extractPrincipal: decode user JWT
    extractPrincipal->>jwtUtils: decodeAndVerify
    jwtUtils-->>extractPrincipal: Principal with exp iat iss
    extractPrincipal-->>generateServiceToken: return Principal
    
    Note over generateServiceToken: Fix applied here:<br/>Destructure to exclude exp iat iss<br/>before re-signing
    
    generateServiceToken->>jwtUtils: sign clean payload
    jwtUtils-->>generateServiceToken: new service JWT
    generateServiceToken-->>Client: return service JWT
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@MarceloRGonc MarceloRGonc merged commit 0159b02 into main Dec 4, 2025
24 checks passed
@MarceloRGonc MarceloRGonc deleted the mg/OPS-3197 branch December 4, 2025 14:56
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.

3 participants