File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -430,9 +430,15 @@ export class GmodDev extends BaseSession {}
430430
431431const MAX_SESSIONS_PER_IP = 2 ;
432432
433+ async function hashIP ( ip : string ) : Promise < string > {
434+ const data = new TextEncoder ( ) . encode ( ip ) ;
435+ const hash = await crypto . subtle . digest ( "SHA-256" , data ) ;
436+ return btoa ( String . fromCharCode ( ...new Uint8Array ( hash ) ) ) ;
437+ }
438+
433439export class QueueDO extends DurableObject < Env > {
434440 activeSessions : Map < string , string > ; // sessionId → type
435- sessionIPs : Map < string , string > ; // sessionId → IP
441+ sessionIPs : Map < string , string > ; // sessionId → hashed IP
436442 waitingQueue : {
437443 ticketId : string ;
438444 sessionType : string ;
@@ -485,7 +491,8 @@ export class QueueDO extends DurableObject<Env> {
485491
486492 if ( url . pathname === "/api/request-session" ) {
487493 const sessionType = url . searchParams . get ( "type" ) || "public" ;
488- const clientIP = request . headers . get ( "CF-Connecting-IP" ) || "unknown" ;
494+ const rawIP = request . headers . get ( "CF-Connecting-IP" ) || "unknown" ;
495+ const clientIP = rawIP !== "unknown" ? await hashIP ( rawIP ) : "unknown" ;
489496
490497 if ( clientIP !== "unknown" && this . activeSessionCountForIP ( clientIP ) >= MAX_SESSIONS_PER_IP ) {
491498 return new Response ( JSON . stringify ( {
You can’t perform that action at this time.
0 commit comments