Skip to content

Comments

[Fix]: Ensure JWT sub is a string#490

Merged
EspressoTrip-v2 merged 6 commits intomainfrom
stringify_jwt_sub
Feb 10, 2026
Merged

[Fix]: Ensure JWT sub is a string#490
EspressoTrip-v2 merged 6 commits intomainfrom
stringify_jwt_sub

Conversation

@EspressoTrip-v2
Copy link
Contributor

@EspressoTrip-v2 EspressoTrip-v2 commented Feb 5, 2026

Background

We previously assumed the JWT sub claim was always a string; however, it can also be a boolean, object, or array.

Issue

  • Client analytics fails when sub is not a string.
  • Other code paths that rely on context.user_id or token payload string semantics may also be affected.

Fix

Normalize sub immediately after JWT verification (in KeyStore.verifyJwt): keep strings as-is, use JSON.stringify for everything else, and use the normalized value for context.user_id and token_payload.

Impact of the fix

  • request.user_id() / auth.user_id() now consistently return a string.
  • String sub values are unchanged; non-string sub values are normalized with JSON.stringify.
  • Sync rules that expect string IDs continue to behave as before; rules that assume strict non-string typing should be reviewed.

@changeset-bot
Copy link

changeset-bot bot commented Feb 5, 2026

🦋 Changeset detected

Latest commit: e374a58

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@powersync/service-core Patch
@powersync/service-core-tests Patch
@powersync/service-module-core Patch
@powersync/service-module-mongodb-storage Patch
@powersync/service-module-mongodb Patch
@powersync/service-module-mssql Patch
@powersync/service-module-mysql Patch
@powersync/service-module-postgres-storage Patch
@powersync/service-module-postgres Patch
@powersync/service-image Patch
test-client Patch
@powersync/service-schema Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@EspressoTrip-v2 EspressoTrip-v2 merged commit 1a1a4cc into main Feb 10, 2026
25 checks passed
@EspressoTrip-v2 EspressoTrip-v2 deleted the stringify_jwt_sub branch February 10, 2026 14:42
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.

2 participants