Skip to content

fix(auth): verify JWT subject matches stored API token tenant - #5215

Merged
igor-kupczynski merged 1 commit into
mainfrom
t3code/fix-tenant-token-sub-check
Oct 15, 2026
Merged

igor-kupczynski merged 1 commit into
mainfrom
t3code/fix-tenant-token-sub-check

Conversation

@igor-kupczynski

@igor-kupczynski igor-kupczynski commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

ValidateTenantToken looked up the API token record by token_id and parsed the JWT sub claim as the tenant ID, but did not verify that sub matched dbToken.TenantId. Require dbToken.TenantId to be non-nil and equal to the parsed subject claim before returning.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

🤖 AI Disclosure
  • I acknowledge that an LLM was used in the creation of this Pull Request, in accordance with Hatchet's AI_POLICY.md.

  • Details: Used Gemini 4 Argon to implement the check and unit test.

Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel

vercel Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hatchet-docs Ready Ready Preview Oct 15, 2026 10:39am UTC

Request Review

@github-actions github-actions Bot added the engine Related to the core Hatchet engine label Oct 15, 2026
@greptile-apps

greptile-apps Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Critical impact] Adds JWT subject validation to the authentication token check.

The change appears safe to merge; adding the nil-tenant test is non-blocking.

Summary

ValidateTenantToken now rejects JWTs whose subject differs from the stored token’s tenant, including records without a tenant.

  • Tenant tokens only validate when the JWT subject matches the stored tenant.

Reviews (1) · Last reviewed commit: "fix(auth): verify JWT subject matches st..." · Reviewed by Greptile

Comment on lines +125 to +128
resignedWithTenantB := resignTokenWithSubject(t, enc, opts, tokenA, tenantB)

_, _, err = mgr.ValidateTenantToken(ctx, resignedWithTenantB)
assert.Error(t, err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Nil-tenant rejection lacks a test

The new test covers a mismatched tenant but never a stored token with TenantId == nil. Add a case that clears the stored token’s TenantId, validates its otherwise valid JWT, and checks for an error. This would catch a future change that accepts an unbound token or dereferences a nil pointer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🤖 Gemini 4 Argon on behalf of Igor:

All API token creation paths populate TenantId, and the dbToken.TenantId == nil guard sits on the exact same line right before *dbToken.TenantId != parsedSubject. A separate test mutating the in-memory stub just to exercise a one-line nil guard does not add meaningful coverage.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That’s fair. Since token creation always sets TenantId, and the implementation explicitly rejects nil before dereferencing, a separate test that mutates the stub solely to hit this defensive branch would add little value beyond the existing mismatch test. I’m withdrawing the nil-tenant test request.

@igor-kupczynski
igor-kupczynski merged commit 15b3831 into main Oct 15, 2026
61 of 62 checks passed
@igor-kupczynski
igor-kupczynski deleted the t3code/fix-tenant-token-sub-check branch October 15, 2026 11:21

This branch was successfully deployed

1 active deployment
Preview — 8054a500 Deployed Oct 15, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine Related to the core Hatchet engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants