File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import { Config } from "./config";
1818import { RateLimited } from "./api/rate-limited" ;
1919import { RateLimitter } from "./rate-limitter" ;
2020import { RateLimiterRes } from "rate-limiter-flexible" ;
21+ import * as crypto from "crypto" ;
2122
2223@injectable ( )
2324export 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}
You can’t perform that action at this time.
0 commit comments