Skip to content

Commit 6c79332

Browse files
committed
Merge branch 'dev' of https://github.com/umami-software/umami into analytics
2 parents 306aafd + 7514af4 commit 6c79332

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/app/(main)/websites/[websiteId]/settings/SharesTable.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export function SharesTable(props: DataTableProps) {
1111
const { isMobile } = useMobile();
1212

1313
const getUrl = (slug: string) => {
14-
return `${cloudMode ? process.env.cloudUrl : window?.location.origin}${process.env.basePath || ''}/share/${slug}`;
14+
if (cloudMode) {
15+
return `${process.env.cloudUrl}/share/${slug}`;
16+
}
17+
return `${window?.location.origin}${process.env.basePath || ''}/share/${slug}`;
1518
};
1619

1720
return (

src/app/api/send/route.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { startOfHour, startOfMonth } from 'date-fns';
1+
import { startOfHour } from 'date-fns';
22
import { isbot } from 'isbot';
33
import { serializeError } from 'serialize-error';
44
import { z } from 'zod';
55
import clickhouse from '@/lib/clickhouse';
66
import { COLLECTION_TYPE, EVENT_TYPE } from '@/lib/constants';
7-
import { hash, secret, uuid } from '@/lib/crypto';
7+
import { getSalt, hash, secret, uuid } from '@/lib/crypto';
88
import { getClientInfo, hasBlockedIp } from '@/lib/detect';
99
import { createToken, parseToken } from '@/lib/jwt';
1010
import { fetchWebsite } from '@/lib/load';
@@ -130,7 +130,8 @@ export async function POST(request: Request) {
130130
const createdAt = timestamp ? new Date(timestamp * 1000) : new Date();
131131
const now = Math.floor(Date.now() / 1000);
132132

133-
const sessionSalt = hash(startOfMonth(createdAt).toUTCString());
133+
const saltRotation = process.env.SALT_ROTATION || 'month';
134+
const sessionSalt = getSalt(saltRotation, createdAt);
134135
const visitSalt = hash(startOfHour(createdAt).toUTCString());
135136

136137
const sessionId = id ? uuid(sourceId, id) : uuid(sourceId, ip, userAgent, sessionSalt);

src/lib/crypto.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import crypto from 'node:crypto';
2+
import { startOfDay, startOfMonth, startOfWeek } from 'date-fns';
23
import { v4, v5, v7 } from 'uuid';
34

45
const ALGORITHM = 'aes-256-gcm';
@@ -67,3 +68,11 @@ export function uuid(...args: any) {
6768
export function createAuthKey() {
6869
return crypto.randomBytes(16).toString('hex');
6970
}
71+
72+
export function getSalt(saltRotation: string, createdAt: Date): string {
73+
return hash(
74+
(saltRotation === 'day' ? startOfDay : saltRotation === 'week' ? startOfWeek : startOfMonth)(
75+
createdAt,
76+
).toUTCString(),
77+
);
78+
}

0 commit comments

Comments
 (0)