Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Improve hash validation.

Mike Caoe6908d9e048a
diff --git a/lib/utils.js b/lib/utils.js
index 06cd14acd..a02387e80 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -11,6 +11,10 @@ export function hash(s) {
return uuid(s, md5(process.env.HASH_SALT));
}
+export function validHash(s) {
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(s);
+}
+
export function getIpAddress(req) {
if (req.headers['cf-connecting-ip']) {
return req.headers['cf-connecting-ip'];
@@ -58,7 +62,12 @@ export function parseCollectRequest(req) {
session: { website_id, session_id, time, hash: validationHash },
} = payload;
- if (hash(`${website_id}${session_id}${time}`) === validationHash) {
+ if (
+ validHash(website_id) &&
+ validHash(session_id) &&
+ validHash(validationHash) &&
+ hash(`${website_id}${session_id}${time}`) === validationHash
+ ) {
return {
valid: true,
type,