bug: RBAC adapter makes distinct one-time public JWTs share an environment-key fingerprint

Aperta
#5,080 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Start by reading internal-packages/rbac/src/bearerCredentials.ts where the public JWT result and oneTimeUse are produced, then apps/webapp/app/services/routeBuilders/apiBuilder.server.ts where authentication.apiKey is populated, and apps/webapp/app/services/apiAuth.server.ts where getOneTimeUseToken hashes it. Follow the trigger route apps/webapp/app/routes/api.v1.tasks.$taskId.trigger.ts to see how the token reaches the run service. A fix is done when distinct public JWTs produce distinct one-time-use identifiers while private-key and non-one-time paths stay unchanged, backed by regression tests.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

At current main commit ba9448974f4b026efa62f2cb447c076d9a25b04f, authenticateRequestForApiBuilder() sets authentication.apiKey to result.environment.apiKey, including for an authenticated public JWT. The task trigger route then calls getOneTimeUseToken(authentication), which hashes authentication.apiKey.

Consequently, distinct one-time JWTs for the same environment produce the same one-time-use identifier: the environment key is hashed instead of the presented JWT. Once that identifier is present on a run, a fresh JWT can be rejected as already used.

Source path

  1. Bearer resolver returns the authenticated environment plus oneTimeUse for a public JWT.
  2. apiBuilder adapter places the environment key in authentication.apiKey.
  3. One-time-use helper hashes that field.
  4. Trigger route passes the resulting value to the run service. The engine converts a oneTimeUseToken uniqueness conflict to the already-used-token error.

Minimal illustration

This dependency-free example illustrates the collision; the source-extracted regression harness described below additionally executes the real functions.

const assert = require('node:assert/strict');
const { createHash } = require('node:crypto');
const environment = { apiKey: 'NONSECRET_OFFLINE_ENVIRONMENT_KEY' };

// Models the adapter after successful authentication of each distinct JWT.
function bridge(presentedJwt) {
  return { type: 'PUBLIC_JWT', oneTimeUse: true, apiKey: environment.apiKey };
}
function oneUseId(auth) {
  return createHash('sha256').update(auth.apiKey).digest('hex');
}

const jwtA = 'synthetic-distinct-jwt-a';
const jwtB = 'synthetic-distinct-jwt-b';
assert.notEqual(jwtA, jwtB);
// Fails: these must be distinct, but both hash the environment key.
assert.notEqual(oneUseId(bridge(jwtA)), oneUseId(bridge(jwtB)));

Source-extracted verification

Using Node 22.22.3 and TypeScript 5.9.3, an offline harness extracts the actual authenticateRequestForApiBuilder, getOneTimeUseToken and presentedBearerToken functions from that pinned commit and strips their types. Successful RBAC authentication is the fixture; the adapter and hashing functions are real upstream code. Two differently signed synthetic JWTs for one synthetic environment collide with the pristine adapter. No provider requests or real credentials are involved.

A proposed adapter correction passes eight checks: the baseline collision; distinct fresh-token fingerprints; identical-token replay identity; a minimal uniqueness model; non-one-time behavior; unchanged private-key behavior; forwarded RBAC denial; and fail-closed handling of an absent bearer token. The uniqueness model uses a Set, not the full run-engine database; full upstream integration testing remains necessary.

Suggested correction

Preserve the presented bearer JWT in authentication.apiKey for a successfully authenticated publicJWT subject, while leaving other subject types unchanged. The existing presentedBearerToken(request) helper can supply it after RBAC succeeds. Fail closed if that value is absent. Do not remove one-time protection or widen scopes.

const publicJwt = result.subject.type === "publicJWT"
  ? presentedBearerToken(request)
  : undefined;
if (result.subject.type === "publicJWT" && !publicJwt) {
  return { ok: false, status: 401, error: "Invalid or missing public JWT" };
}
// In the existing authentication object:
apiKey: publicJwt ?? result.environment.apiKey,

Alternatively, carry the presented-token identity in a dedicated field and hash that explicitly. The candidate has not been deployed, and all authentication paths need maintainer review before accepting it.

Hosted symptom and limits

A separate isolated Development check using SDK/CLI 4.8.1 and a verified V2 worker returned HTTP 422 with the one-time-token-used error on a fresh one-use token's only recorded caller submission. No new run appeared in the subsequent task/time-filtered read. Connection validation used a different read-only token. The caller stopped and did not retry.

This is consistent with the source defect, but we cannot attest which backend build processed that hosted request or its database state. We are not treating the local test as proof of a deployed fix. Related symptom report: #3780; a shared cause is not assumed.

Could you confirm whether the cloud task-trigger route uses this adapter and review the token identity passed to getOneTimeUseToken? The reproduction, regression tests and proposed patch are ready to share. No credentials, customer data, project IDs or run IDs are included here.

Lingua principale
TypeScript
Stelle
16.5k
Fork
1.5k
Merge medio
1g 15h
PR unite (30g)
17

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di triggerdotdev/trigger.dev

Tutte le issue di triggerdotdev/trigger.dev

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.