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";
18
18
import { RateLimited } from "./api/rate-limited" ;
19
19
import { RateLimitter } from "./rate-limitter" ;
20
20
import { RateLimiterRes } from "rate-limiter-flexible" ;
21
+ import * as crypto from "crypto" ;
21
22
22
23
@injectable ( )
23
24
export class AnalyticsController {
@@ -69,6 +70,7 @@ export class AnalyticsController {
69
70
const clientHeaderFields = toClientHeaderFields ( req ) ;
70
71
const event = req . body as RemoteIdentifyMessage ;
71
72
this . identifyUser ( req . user . id , event , clientHeaderFields ) ;
73
+ this . setHashedUserIdCookie ( req . user . id , res ) ;
72
74
res . sendStatus ( 200 ) ;
73
75
} catch ( e ) {
74
76
console . error ( "failed to identify user" , e ) ;
@@ -177,4 +179,16 @@ export class AnalyticsController {
177
179
throw e ;
178
180
}
179
181
}
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
+ }
180
194
}
You can’t perform that action at this time.
0 commit comments