Skip to content

A modern and elegant dashboard for network traffic visualization and analysis.

fix(security): deny cross-origin by default and stop leaking backend tokens

luoleie5dad35e8f33
diff --git a/apps/collector/src/modules/app/app.ts b/apps/collector/src/modules/app/app.ts
index e5aaacf..3e2a31a 100644
--- a/apps/collector/src/modules/app/app.ts
+++ b/apps/collector/src/modules/app/app.ts
@@ -250,9 +250,16 @@ export async function createApp(options: AppOptions) {
.split(',')
.map((s) => s.trim())
.filter(Boolean);
+ // Security: when CORS_ORIGIN is unset, deny cross-origin requests instead of
+ // reflecting any Origin with credentials — that combination let any website
+ // read a logged-in user's data cross-site. Same-origin deployments (the
+ // dashboard and API served from one origin, the default Docker setup) are
+ // unaffected because browsers do not apply CORS to same-origin requests.
+ // To allow a separate dashboard origin, set CORS_ORIGIN explicitly.
+ const hasExplicitOrigins = corsOrigins.length > 0;
await app.register(cors, {
- origin: corsOrigins.length > 0 ? corsOrigins : true,
- credentials: true,
+ origin: hasExplicitOrigins ? corsOrigins : false,
+ credentials: hasExplicitOrigins,
});
app.addHook('onSend', async (_request, reply) => {
diff --git a/apps/collector/src/modules/backend/backend.service.ts b/apps/collector/src/modules/backend/backend.service.ts
index 9c32010..3337fde 100644
--- a/apps/collector/src/modules/backend/backend.service.ts
+++ b/apps/collector/src/modules/backend/backend.service.ts
@@ -237,6 +237,11 @@ export class BackendService {
this.attachHealthStatus({
...backend,
url: isShowcase ? maskUrl(backend.url) : backend.url,
+ // Never expose the stored upstream/agent token in list/read responses.
+ // The edit form treats an empty token as "unchanged" on submit, so
+ // blanking it here does not break editing but stops leaking every
+ // backend's plaintext secret to any authenticated dashboard load.
+ token: '',
})
);
}
@@ -251,9 +256,11 @@ export class BackendService {
}
const isShowcase = this.authService.isShowcaseMode();
- return this.attachHealthStatus({
+ return this.attachHealthStatus({
...backend,
url: isShowcase ? maskUrl(backend.url) : backend.url,
+ // See getAllBackends: never expose the stored token in read responses.
+ token: '',
});
}
@@ -268,6 +275,11 @@ export class BackendService {
this.attachHealthStatus({
...backend,
url: isShowcase ? maskUrl(backend.url) : backend.url,
+ // Never expose the stored upstream/agent token in list/read responses.
+ // The edit form treats an empty token as "unchanged" on submit, so
+ // blanking it here does not break editing but stops leaking every
+ // backend's plaintext secret to any authenticated dashboard load.
+ token: '',
})
);
}