Skip to content

Commit b0596ee

Browse files
chore: Add hashed user ID cookie in analytics controller service (#20226)
1 parent 2be52da commit b0596ee

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

components/server/src/analytics-controller.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { Config } from "./config";
1818
import { RateLimited } from "./api/rate-limited";
1919
import { RateLimitter } from "./rate-limitter";
2020
import { RateLimiterRes } from "rate-limiter-flexible";
21+
import * as crypto from "crypto";
2122

2223
@injectable()
2324
export class AnalyticsController {
@@ -69,6 +70,7 @@ export class AnalyticsController {
6970
const clientHeaderFields = toClientHeaderFields(req);
7071
const event = req.body as RemoteIdentifyMessage;
7172
this.identifyUser(req.user.id, event, clientHeaderFields);
73+
this.setHashedUserIdCookie(req.user.id, res);
7274
res.sendStatus(200);
7375
} catch (e) {
7476
console.error("failed to identify user", e);
@@ -177,4 +179,16 @@ export class AnalyticsController {
177179
throw e;
178180
}
179181
}
182+
183+
private setHashedUserIdCookie(userId: string, res: express.Response): void {
184+
const hashedUserId = crypto.createHash("md5").update(userId).digest("hex");
185+
const oneYearInSeconds = 365 * 24 * 60 * 60;
186+
res.cookie("gitpod_hashed_user_id", hashedUserId, {
187+
domain: ".gitpod.io",
188+
maxAge: oneYearInSeconds * 1000, // Convert to milliseconds
189+
httpOnly: true,
190+
secure: true,
191+
sameSite: "lax",
192+
});
193+
}
180194
}

0 commit comments

Comments
 (0)