Fix share token confusion vulnerability
Cache tokens from /api/send and share tokens were both signed with the same secret and parsed without distinguishing claim types, allowing a public cache token to be replayed as x-umami-share-token to read any website's analytics. Add explicit token type claims (share/cache) and require the matching type when parsing each.
This commit is contained in:
1 parent
c4b1452c29
commit
8bc49a29e3
4 files changed
+27
-7
No files matched your search
@@ -3,7 +3,7 @@ import { isbot } from 'isbot';
|
||||
import { serializeError } from 'serialize-error';
|
||||
import { z } from 'zod';
|
||||
import clickhouse from '@/lib/clickhouse';
|
||||
import { COLLECTION_TYPE, EVENT_TYPE } from '@/lib/constants';
|
||||
import { CACHE_TOKEN_TYPE, COLLECTION_TYPE, EVENT_TYPE } from '@/lib/constants';
|
||||
import { getSalt, hash, secret, uuid } from '@/lib/crypto';
|
||||
import { getClientInfo, hasBlockedIp } from '@/lib/detect';
|
||||
import { createToken, parseToken } from '@/lib/jwt';
|
||||
@@ -106,7 +106,7 @@ export async function POST(request: Request) {
|
||||
if (cacheHeader) {
|
||||
const result = await parseToken(cacheHeader, secret());
|
||||
|
||||
if (result) {
|
||||
if (result?.type === CACHE_TOKEN_TYPE) {
|
||||
cache = result;
|
||||
}
|
||||
}
|
||||
@@ -308,7 +308,10 @@ export async function POST(request: Request) {
|
||||
});
|
||||
}
|
||||
|
||||
const token = createToken({ websiteId, sessionId, visitId, iat }, secret());
|
||||
const token = createToken(
|
||||
{ websiteId, sessionId, visitId, iat, type: CACHE_TOKEN_TYPE },
|
||||
secret(),
|
||||
);
|
||||
|
||||
return json({ cache: token, sessionId, visitId });
|
||||
} catch (e) {
|
||||
|
||||
Reference in new issue
Block a user