Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

More tests

Blue Mousec6b26ed80462
diff --git a/backend/apps/cloud/src/api-key/api-key.spec.ts b/backend/apps/cloud/src/api-key/api-key.spec.ts
index 694ed5b30..f33ff14f7 100644
--- a/backend/apps/cloud/src/api-key/api-key.spec.ts
+++ b/backend/apps/cloud/src/api-key/api-key.spec.ts
@@ -352,6 +352,33 @@ describe('API key authorization', () => {
ForbiddenException,
)
})
+ it('requires both warehouse scopes and authorizes the project in the path', async () => {
+ const policy: ApiKeyPolicy = {
+ scope: 'analytics:read',
+ requires: ['events:read'],
+ source: 'params',
+ field: 'projectId',
+ }
+ const key = {
+ ...scoped(),
+ scopes: ['analytics:read', 'events:read'],
+ }
+ expect(
+ (await run(policy, key, { params: { projectId: projectA } })).result,
+ ).toBe(true)
+ for (const scopes of [['analytics:read'], ['events:read'], []]) {
+ await expect(
+ run(policy, { ...key, scopes }, { params: { projectId: projectA } }),
+ ).rejects.toThrow(ForbiddenException)
+ }
+ await expect(
+ run(policy, key, {
+ params: { projectId: projectB },
+ query: { projectId: projectA, pid: projectA },
+ body: { projectId: projectA },
+ }),
+ ).rejects.toThrow(ForbiddenException)
+ })
it('validates every project in JSON and array batch queries', async () => {
expect(
(
diff --git a/backend/apps/cloud/src/data-export/bigquery.service.spec.ts b/backend/apps/cloud/src/data-export/bigquery.service.spec.ts
index da7bf0fc7..d35946c63 100644
--- a/backend/apps/cloud/src/data-export/bigquery.service.spec.ts
+++ b/backend/apps/cloud/src/data-export/bigquery.service.spec.ts
@@ -39,6 +39,31 @@ describe('BigQueryService', () => {
schema: { fields: WAREHOUSE_SCHEMA },
})
+ it.each([
+ { projectId: "' OR 1=1 --" },
+ { gcpProjectId: 'example-project` UNION SELECT 1 --' },
+ { datasetId: 'analytics`; DROP TABLE other; --' },
+ { tablePrefix: 'events` WHERE TRUE; --' },
+ { location: 'EU&projectId=other-project' },
+ ])(
+ 'rejects injected destination settings %j before authentication',
+ async (invalid) => {
+ const auth = jest.spyOn(service, 'auth')
+ await expect(
+ service.validate({ ...config, ...invalid }, {}),
+ ).rejects.toThrow('Invalid BigQuery destination settings')
+ await expect(
+ service.exportDay(
+ { ...config, ...invalid },
+ {},
+ '2026-10-26',
+ 'run-id',
+ ),
+ ).rejects.toThrow('Invalid BigQuery destination settings')
+ expect(auth).not.toHaveBeenCalled()
+ },
+ )
+
it.each([
{ description: 'An unrelated table' },
{ timePartitioning: { type: 'MONTH', field: 'event_date' } },
diff --git a/backend/apps/cloud/src/data-export/warehouse-source.service.spec.ts b/backend/apps/cloud/src/data-export/warehouse-source.service.spec.ts
index e0c8ca116..8cd49edb0 100644
--- a/backend/apps/cloud/src/data-export/warehouse-source.service.spec.ts
+++ b/backend/apps/cloud/src/data-export/warehouse-source.service.spec.ts
@@ -52,6 +52,8 @@ describe('WarehouseSourceService', () => {
expect(options.query).toContain('toString(psid) AS visitor_id')
expect(options.query).toContain('toString(sid) AS session_id')
expect(options.query).toContain('importID IS NULL')
+ expect(options.query).toContain('WHERE pid = {projectId:FixedString(12)}')
+ expect(options.query).not.toContain(projectId)
expect(options.query).toContain(
"created < toDateTime({day:Date}, 'UTC') + INTERVAL 1 DAY",
)
@@ -104,4 +106,26 @@ describe('WarehouseSourceService', () => {
expect(query).not.toHaveBeenCalled()
},
)
+
+ it.each([
+ "' OR 1=1 --",
+ 'abcdefghijkl\u0000',
+ 'abc--defghij',
+ '../abcdefghi',
+ ])('rejects invalid project %s before querying', async (invalid) => {
+ await expect(
+ service.rows(invalid, day, 'pageviews').next(),
+ ).rejects.toThrow('Invalid export selection')
+ expect(query).not.toHaveBeenCalled()
+ })
+
+ it.each(['errors', 'pageviews OR 1=1', ['pageviews', 'custom_events']])(
+ 'rejects invalid event selection %s before querying',
+ async (invalid) => {
+ await expect(
+ service.rows(projectId, day, invalid as 'pageviews').next(),
+ ).rejects.toThrow('Invalid export selection')
+ expect(query).not.toHaveBeenCalled()
+ },
+ )
})