Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ jobs:
run: pnpm run build
env:
CI: true
- name: Test dashboard credential isolation
env:
TINYBIRD_TOKEN: server-token-must-never-leave
TINYBIRD_HOST: http://127.0.0.1:1
TINYBIRD_ALLOWED_HOSTS: http://127.0.0.1:3098
DISABLE_AUTH: 'true'
run: |
node dashboard/tests/credentials.cjs
pnpm --filter @tinybirdco/analytics-dashboard exec next start -p 3097 &
server_pid=$!
trap 'kill "$server_pid"' EXIT
for attempt in $(seq 1 30); do
if curl --silent --fail http://localhost:3097/ > /dev/null; then break; fi
sleep 1
done
node dashboard/tests/token-auth.mjs

middleware:
runs-on: ubuntu-latest
Expand Down
33 changes: 0 additions & 33 deletions .github/workflows/tinybird-cd.yml

This file was deleted.

43 changes: 0 additions & 43 deletions .github/workflows/tinybird-ci.yml

This file was deleted.

6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased
### Security
- [Dashboard] Never send the server `TINYBIRD_TOKEN` to a host taken from the `X-Tinybird-Host` header; only accept Tinybird API hosts in token mode
- [Dashboard] Validate signed, expiring session cookies in middleware and API routes
- [Dashboard] Remove the `admin/admin` default credentials; login requires `DASHBOARD_PASSWORD`
- [Dashboard] Restrict token-mode upstreams to Tinybird API origins or explicitly configured allowed origins
- [Dashboard] Remove password/session authentication, including the development auth bypass; require caller-supplied Tinybird token and host headers
- [Dashboard] Remove deployment-token fallback while preserving the allowed-host policy
- [Dashboard] Remove the unused `/api/sql` route, which ran arbitrary SQL with the server `TINYBIRD_TOKEN`

- [Data project] Fix `top_devices` and `top_browsers` session count (#90)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Web Analytics template for Tinybird

> **Security update (2026-11-03):** Earlier dashboard versions allowed a request-controlled host to receive the deployment's Tinybird token. Upgrade and redeploy the dashboard, remove its `TINYBIRD_TOKEN` deployment variable, and revoke/rotate any token configured in an exposed deployment. Password/session authentication is removed; dashboard access now requires a caller-supplied Tinybird token and host. Updating the code does not revoke previously leaked credentials.


Build your own web analytics platform using [Tinybird](https://www.tinybird.co/)'s Events API and Endpoints. Built with privacy and speed as top priorities, this template lets you get real-time metrics in a pre-built dashboard in just a few minutes without any knowledge about Tinybird.

After you've finished the basic setup, expand your analytics with custom events tailored to your specific use cases (eCommerce, marketing, etc.), keeping the same real-time performance.
Expand Down
17 changes: 3 additions & 14 deletions dashboard/.env.example
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
# Tinybird Configuration (server-only, required)
TINYBIRD_TOKEN=your-tinybird-token
TINYBIRD_HOST=https://api.tinybird.co

# Dashboard URL (public)
NEXT_PUBLIC_TINYBIRD_DASHBOARD_URL=http://localhost:3000

# Tracker token for analytics (public, optional)
NEXT_PUBLIC_TINYBIRD_TRACKER_TOKEN=

# Dashboard Basic Auth (server-only). Login is disabled unless DASHBOARD_PASSWORD is set.
# DASHBOARD_USERNAME=admin
# DASHBOARD_PASSWORD=changeme

# Optional: extra Tinybird API hosts accepted in token mode (comma-separated).
# *.tinybird.co API hosts and TINYBIRD_HOST are always accepted.
# TINYBIRD_ALLOWED_HOSTS=

# Optional: Set to "true" to disable auth during development
DISABLE_AUTH=false
# Optional: extra API origins accepted for caller-supplied tokens (comma-separated)
# HTTPS Tinybird API origins are always accepted; localhost is accepted in development.
# TINYBIRD_ALLOWED_HOSTS=https://my-tinybird.example

# Optional: AI Chat
NEXT_PUBLIC_ASK_TINYBIRD_ENDPOINT="https://ask-tb.tinybird.live/api/chat"
24 changes: 6 additions & 18 deletions dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,40 +41,28 @@ You will find the app running at http://localhost:3000
Copy the .env.example file and rename it to .env.

```bash
# Tinybird Configuration (server-only, required)
TINYBIRD_TOKEN=your-tinybird-token
TINYBIRD_HOST=https://api.tinybird.co

# Dashboard URL (public)
NEXT_PUBLIC_TINYBIRD_DASHBOARD_URL=http://localhost:3000

# Tracker token for analytics (public, optional)
NEXT_PUBLIC_TINYBIRD_TRACKER_TOKEN=

# Dashboard Basic Auth (server-only). Login is disabled unless DASHBOARD_PASSWORD is set.
# DASHBOARD_USERNAME=admin
# DASHBOARD_PASSWORD=changeme

# Optional: extra Tinybird API hosts accepted in token mode (comma-separated).
# *.tinybird.co API hosts and TINYBIRD_HOST are always accepted.
# TINYBIRD_ALLOWED_HOSTS=

# Optional: Set to "true" to disable auth during development
DISABLE_AUTH=false
# Optional: extra API origins accepted for caller-supplied tokens (comma-separated)
# TINYBIRD_ALLOWED_HOSTS=https://my-tinybird.example

# Optional: AI Chat
NEXT_PUBLIC_ASK_TINYBIRD_ENDPOINT="https://ask-tb.tinybird.live/api/chat"
```

To develop locally, start [Tinybird Local](https://www.tinybird.co/docs/cli/local-container) and use `http://localhost:7181` as TINYBIRD_HOST.
To develop locally, start [Tinybird Local](https://www.tinybird.co/docs/cli/local-container) and use `http://localhost:7181` as the host in the token access form.

### Authentication

The dashboard includes built-in authentication. Set `DASHBOARD_PASSWORD` (and optionally `DASHBOARD_USERNAME`, defaults to `admin`) to enable username/password login; without `DASHBOARD_PASSWORD`, login is disabled. Sessions are signed and expire after 7 days; changing the password invalidates existing sessions.
The dashboard supports Tinybird token access only. Use the token form or open a dashboard link with `token` and `host` parameters. API requests must provide both `X-Tinybird-Token` and `X-Tinybird-Host`; Tinybird enforces the token's permissions.

The server-side `TINYBIRD_TOKEN` is only ever sent to `TINYBIRD_HOST`. When signing in with a Tinybird token, the host must be a Tinybird API host (`https://api.*.tinybird.co`), `TINYBIRD_HOST`, or listed in `TINYBIRD_ALLOWED_HOSTS`.
Password login, session cookies, and `DISABLE_AUTH` have been removed. The dashboard no longer uses `TINYBIRD_TOKEN`; remove it from dashboard deployments and use caller-supplied credentials. `TINYBIRD_HOST`, if set, only adds an allowed origin and never supplies request credentials. Credentials needed by the separate Tinybird deployment tooling or ingestion middleware remain separate.

For local development, you can disable authentication by setting `DISABLE_AUTH=true`.
The host restrictions introduced by the security fix remain: HTTPS Tinybird API origins are accepted, as are origins explicitly configured in `TINYBIRD_ALLOWED_HOSTS` or `TINYBIRD_HOST`. Localhost origins are also accepted during development. Both credential headers are required even when an allowed host is configured.

### Build for Production

Expand Down
59 changes: 0 additions & 59 deletions dashboard/app/api/auth/login/route.ts

This file was deleted.

11 changes: 0 additions & 11 deletions dashboard/app/api/auth/logout/route.ts

This file was deleted.

25 changes: 0 additions & 25 deletions dashboard/app/api/auth/route.ts

This file was deleted.

11 changes: 2 additions & 9 deletions dashboard/app/api/config/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,10 @@ export async function GET(request: NextRequest) {
const result = resolveTinybirdCredentials(request.headers)

if ('error' in result) {
if (result.missing) {
return NextResponse.json({
configured: false,
missing: result.missing,
workspace: null,
})
}
return NextResponse.json({ error: result.error }, { status: result.status })
}

const { token, host, fromHeaders } = result.credentials
const { token, host } = result.credentials
const regionInfo = await getRegionInfoFromHost(host)

// Use workspace name from header if provided (avoids permission issues with scoped JWT)
Expand All @@ -111,7 +104,7 @@ export async function GET(request: NextRequest) {
}

// If still no workspace name and we have a token, try to decode it
if (!workspaceName && fromHeaders) {
if (!workspaceName) {
workspaceName = extractWorkspaceNameFromToken(token)
}

Expand Down
7 changes: 2 additions & 5 deletions dashboard/app/api/endpoints/[name]/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { NextRequest, NextResponse } from 'next/server'
import {
createClientWithCredentials,
getServerClient,
resolveTinybirdCredentials,
} from '@/lib/server'

Expand Down Expand Up @@ -56,10 +55,8 @@ export async function GET(
)
}

const { token, host, fromHeaders } = credentialsResult.credentials
const client = fromHeaders
? createClientWithCredentials(token, host)
: getServerClient()
const { token, host } = credentialsResult.credentials
const client = createClientWithCredentials(token, host)
const searchParams = request.nextUrl.searchParams
const queryParams: Record<string, string> = {}

Expand Down
6 changes: 3 additions & 3 deletions dashboard/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import AuthDialog from '@/components/AuthDialog'
import { useLogin } from '@/lib/hooks/use-login'

export default function DashboardPage() {
const { isLoggedIn, isLoading: isLoginLoading, logout } = useLogin()
const { isLoggedIn, logout } = useLogin()
const {
value: timeRangeValue,
setValue: setTimeRangeValue,
Expand All @@ -34,12 +34,12 @@ export default function DashboardPage() {
const insights = createInsightsFromData(insightsData)
const currentVisitors = useCurrentVisitors()

const showLoginDialog = isLoginLoading || !isLoggedIn
const showLoginDialog = !isLoggedIn

return (
<AIChatProvider>
{/* Show login dialog overlay when not logged in */}
{showLoginDialog && <AuthDialog isLoading={isLoginLoading} />}
{showLoginDialog && <AuthDialog />}
<Suspense>
<>
{process.env.NODE_ENV === 'production' && (
Expand Down
Loading
Loading