📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
fix: validate warehouse credential payloads and fail fast on export errors
Blue Mousebc695b4dfe06
diff --git a/backend/apps/cloud/src/data-export/data-export.crypto.spec.ts b/backend/apps/cloud/src/data-export/data-export.crypto.spec.tsindex 19a989990..6aef8654a 100644--- a/backend/apps/cloud/src/data-export/data-export.crypto.spec.ts+++ b/backend/apps/cloud/src/data-export/data-export.crypto.spec.ts@@ -69,4 +69,34 @@ describe('warehouse credential storage', () => {encryptWarehouseCredentials('key', 'project', 'connection'),).toThrow('SECRET_KEY_BASE')})++ it.each([0, 1, 2, 4])('rejects payloads with %i parts', (count) => {+ const parts = encryptWarehouseCredentials(+ 'private-key',+ 'project',+ 'connection',+ ).split('.')+ const payload = [...parts, 'extra'].slice(0, count).join('.')+ expect(() =>+ decryptWarehouseCredentials(payload, 'project', 'connection'),+ ).toThrow()+ })++ it.each([0, 4, 8, 12, 15, 17])(+ 'rejects %i-byte authentication tags',+ (length) => {+ const parts = encryptWarehouseCredentials(+ 'private-key',+ 'project',+ 'connection',+ ).split('.')+ const tag = Buffer.from(parts[1], 'base64')+ parts[1] = Buffer.concat([tag, Buffer.alloc(1)])+ .subarray(0, length)+ .toString('base64')+ expect(() =>+ decryptWarehouseCredentials(parts.join('.'), 'project', 'connection'),+ ).toThrow()+ },+ )})diff --git a/backend/apps/cloud/src/data-export/data-export.crypto.ts b/backend/apps/cloud/src/data-export/data-export.crypto.tsindex 4710bfa00..a93485f18 100644--- a/backend/apps/cloud/src/data-export/data-export.crypto.ts+++ b/backend/apps/cloud/src/data-export/data-export.crypto.ts@@ -30,10 +30,17 @@ export const decryptWarehouseCredentials = (projectId: string,connectionId: string,) => {- const [iv, tag, encrypted] = credentials- .split('.')- .map((part) => Buffer.from(part, 'base64'))- const decipher = createDecipheriv('aes-256-gcm', encryptionKey(), iv)+ const parts = credentials.split('.')+ if (parts.length !== 3) {+ throw new Error('Invalid warehouse credential payload')+ }+ const [iv, tag, encrypted] = parts.map((part) => Buffer.from(part, 'base64'))+ if (tag.length !== 16) {+ throw new Error('Invalid warehouse credential authentication tag')+ }+ const decipher = createDecipheriv('aes-256-gcm', encryptionKey(), iv, {+ authTagLength: 16,+ })decipher.setAAD(Buffer.from(`${projectId}:${connectionId}`))decipher.setAuthTag(tag)return Buffer.concat([decipher.update(encrypted), decipher.final()]).toString(diff --git a/docs/content/docs/integrations/data-warehouse.mdx b/docs/content/docs/integrations/data-warehouse.mdxindex b9c99692c..96611e4ed 100644--- a/docs/content/docs/integrations/data-warehouse.mdx+++ b/docs/content/docs/integrations/data-warehouse.mdx@@ -166,14 +166,14 @@ The response is `application/x-ndjson`: one JSON object per line, using the schecurl --fail --show-error \'https://api.swetrix.com/v1/data-export/YOUR_PROJECT_ID/events?date=2026-10-01&type=pageviews' \-H "X-Api-Key: $SWETRIX_API_KEY" \- --output pageviews-2026-10-01.ndjson.part && \- mv pageviews-2026-10-01.ndjson.part pageviews-2026-10-01.ndjson+ --output pageviews-2026-10-01.ndjson.part || exit 1+mv pageviews-2026-10-01.ndjson.part pageviews-2026-10-01.ndjson || exit 1curl --fail --show-error \'https://api.swetrix.com/v1/data-export/YOUR_PROJECT_ID/events?date=2026-10-01&type=custom_events' \-H "X-Api-Key: $SWETRIX_API_KEY" \- --output custom-events-2026-10-01.ndjson.part && \- mv custom-events-2026-10-01.ndjson.part custom-events-2026-10-01.ndjson+ --output custom-events-2026-10-01.ndjson.part || exit 1+mv custom-events-2026-10-01.ndjson.part custom-events-2026-10-01.ndjson || exit 1```For a reliable pipeline: