Skip to content

[Backend] Add iss/aud claims to JWT payload type, issuance, and verification #1097 - #1161

Open
abimbolaalabi wants to merge 4 commits into
LabsCrypt:mainfrom
abimbolaalabi:fix/issue-1097-jwt-iss-aud-claims
Open

[Backend] Add iss/aud claims to JWT payload type, issuance, and verification #1097#1161
abimbolaalabi wants to merge 4 commits into
LabsCrypt:mainfrom
abimbolaalabi:fix/issue-1097-jwt-iss-aud-claims

Conversation

@abimbolaalabi

Copy link
Copy Markdown

Overview

This PR adds issuer (iss) and audience (aud) claims to the SEP-10 JWT payload, ensuring tokens are bound to a specific issuer and audience. This prevents token replay across services sharing the same signing secret by adding defense-in-depth validation on verification.

Related Issue

Closes #1097

Changes

\
[MODIFY] backend/src/types/auth.types.ts

Added iss: string and aud: string fields to SEP10TokenPayload interface.
\\

\
[MODIFY] backend/src/middleware/auth.ts

Added JWT_ISSUER and JWT_AUDIENCE constants (configurable via env vars, defaults to 'flowfi-api').
Included iss and aud in token payload during issuance in verifyChallenge.
Added iss/aud validation in verifyJwt, rejecting tokens with mismatched claims.
\\

\
[MODIFY] backend/tests/auth-jwt.test.ts

Added tests for tokens with wrong audience and wrong issuer being rejected.
Updated existing token payloads to include iss/aud.
\\

Verification Results

\
npx vitest run tests/auth-jwt.test.ts tests/auth.middleware.test.ts
✅ 11/11 passed

  • auth-jwt.test.ts: 9/9 passed (including 2 new iss/aud rejection tests)
  • auth.middleware.test.ts: 2/2 passed
    \\

Acceptance Criteria

Status Criterion
iss and aud fields added to payload type
iss/aud included in token issuance
iss/aud verified on token verification, rejecting mismatches
Test for token with wrong audience being rejected
Test for token with wrong issuer being rejected

…fication

- Added iss and aud fields to SEP10TokenPayload in auth.types.ts
- Included iss/aud in token issuance at verifyChallenge
- Verified iss/aud in verifyJwt, rejecting mismatches
- Added tests for wrong audience and wrong issuer rejection
- Updated existing tests to include iss/aud in payloads

Closes LabsCrypt#1097
…x schema duplicate

Rebuild of the JWT iss/aud feature cleanly on current main:
- SEP10TokenPayload gains iss/aud; verifyJwt rejects mismatches; verifyChallenge issues them
- events-list and sse-subscribe integration tests sign tokens with iss/aud
- Remove duplicate @@unique([transactionHash, eventType]) in schema.prisma (P1012 blocker)
- indexer-state: drop nonexistent createdAt from IndexerStateRow
- health.routes: import isRedisAvailable/checkRpcHealth; fix indexerDegraded typo
- soroban-indexer: stringify startTime for BigInt; remove unused timestampBigInt
- soroban-event-worker: remove unused randomUUID/workerId/requestContext; coerce pausedAt for duration calc
- admin-rate-limiter: guard undefined split result
- tests: use bigint for streamId/startTime/lastUpdateTime; fix undefined array/object access
- stream.controller.test: restore TestRequest type
@abimbolaalabi
abimbolaalabi force-pushed the fix/issue-1097-jwt-iss-aud-claims branch from 06cdc0b to ae081ea Compare August 1, 2026 13:28
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.

[Backend] backend/src/types/auth.types.ts JWT payload type does not include an issuer or audience claim

1 participant