Skip to content

Scope Tinybird tokens per tenant and close SSRF in AI routes - #53

Merged
pei-tinybird merged 3 commits into
mainfrom
fix/token-scoping-security
Nov 4, 2026
Merged

pei-tinybird merged 3 commits into
mainfrom
fix/token-scoping-security

Conversation

@pei-tinybird

@pei-tinybird pei-tinybird commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the open code-scan findings for this repo.

What changes

High

  • Empty org read every org. Signed-in users with no org permission got a JWT with organization: '', which the pipes treat as no filter. They now get no JWT and are treated like logged-out visitors.
  • Anonymous visitors got read_pipes in multi-tenant mode. When TINYBIRD_JWT_SECRET is set, logged-out users get no x-tinybird-token. Without it (single-tenant mode), everyone gets the read token and no JWT is signed, since there is no secret to sign it with. The ?token= bring-your-own-token flow is unchanged.

Medium

  • SSRF. x-custom-tinybird-api-url must match https://api.*.tinybird.co (plus localhost outside production). Otherwise the AI routes return 400.

Low

  • Server token sent to a caller URL. extract-cost-parameters only uses the env token with the env URL.
  • Admin token for llm_events writes. The AI routes now use a new TINYBIRD_EVENTS_TOKEN (append-only, llm_events_append, defined in llm_events.datasource). If it isn't set, logging is skipped. There is no fallback to the admin token. The onboarding snippet is updated too.
  • Token logging. Removed the logs of the signed JWT and Clerk session claims, plus the debugger statements.
  • No limits. 1000-character input caps on search, cost extraction and embeddings, plus a 30 req/min per-IP limit in middleware. The limit is per instance, as noted in the code.

⚠️ Deploy order (merging deploys ai.tinybird.app via live)

  1. In Vercel ai-analytics-template, remove TINYBIRD_JWT_SECRET before merging. Otherwise the public demo shows an empty dashboard to logged-out visitors.
  2. Merge. Tinybird CD creates the llm_events_append token.
  3. Set TINYBIRD_EVENTS_TOKEN in Vercel to that token and redeploy.

Checks

  • npm run lint passes (4 existing warnings in untouched files). npm run build passes.
  • Not run: the manual Clerk flows (logged out, signed in with no org, signed in with an org) and the SSRF 400. Run these on the preview.

🤖 Generated with Claude Code

- Don't sign a JWT for users without an org (empty org read every org)
- In multi-tenant mode, give logged-out users no shared read token
- Allowlist x-custom-tinybird-api-url to Tinybird API hosts
- Never send the server token to a caller-chosen URL
- Log llm_events with a new append-only TINYBIRD_EVENTS_TOKEN, not the admin token
- Remove token and session logging from middleware
- Add input caps and a per-IP rate limit to the AI routes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pei-tinybird pei-tinybird self-assigned this Nov 4, 2026
@vercel

vercel Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
ai-analytics-template Ready Ready Preview Nov 4, 2026 9:39am UTC

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tinybird flags it as no longer needed: the current schema is compatible
with the live one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pei-tinybird
pei-tinybird merged commit 0bc8633 into main Nov 4, 2026
4 checks passed

This branch was successfully deployed

1 active deployment
Preview — 9861415a Deployed Nov 4, 2026 by vercel[bot]
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.

1 participant