diff --git a/src/gateway/Server.ts b/src/gateway/Server.ts
index 269cc2ed..5d7f8d87 100644
--- a/src/gateway/Server.ts
+++ b/src/gateway/Server.ts
@@ -28,6 +28,7 @@ import ws from "ws";
import { Connection } from "./events/Connection";
import http from "http";
import { cleanupOnStartup } from "./util/Utils";
+import { randomString } from "@spacebar/api";
export class Server {
public ws: ws.Server;
@@ -50,6 +51,10 @@ export class Server {
if (server) this.server = server;
else {
this.server = http.createServer(function (req, res) {
+ if(!req.headers.cookie?.split("; ").find(x => x.startsWith("__sb_sessid="))) {
+ res.setHeader("Set-Cookie", `__sb_sessid=${randomString(32)}; Secure; HttpOnly; SameSite=None`);
+ }
+
res.writeHead(200).end("Online");
});
}
diff --git a/src/gateway/events/Connection.ts b/src/gateway/events/Connection.ts
index bc74dee6..9b132d4b 100644
--- a/src/gateway/events/Connection.ts
+++ b/src/gateway/events/Connection.ts
@@ -72,6 +72,13 @@ export async function Connection(
);
}
+ if (request.headers.cookie?.split("; ").find(x => x.startsWith("__sb_sessid="))) {
+ socket.fingerprint = request.headers.cookie
+ .split("; ")
+ .find((x) => x.startsWith("__sb_sessid="))
+ ?.split("=")[1];
+ }
+
//Create session ID when the connection is opened. This allows gateway dump to group the initial websocket messages with the rest of the conversation.
const session_id = genSessionId();
socket.session_id = session_id; //Set the session of the WebSocket object
diff --git a/src/gateway/listener/listener.ts b/src/gateway/listener/listener.ts
index 75cb6bc6..f76adfb2 100644
--- a/src/gateway/listener/listener.ts
+++ b/src/gateway/listener/listener.ts
@@ -29,6 +29,7 @@ import {
Message,
NewUrlUserSignatureData,
GuildMemberAddEvent,
+ Ban,
} from "@spacebar/util";
import { OPCODES } from "../util/Constants";
import { Send } from "../util/Send";
@@ -174,6 +175,16 @@ async function consume(this: WebSocket, opts: EventOpts) {
case "GUILD_DELETE":
this.events[id]?.();
delete this.events[id];
+ if (event === "GUILD_DELETE" && this.ipAddress) {
+ const ban = await Ban.findOne({
+ where: { guild_id: id, user_id: this.user_id },
+ });
+
+ if (ban) {
+ ban.ip = this.ipAddress || undefined;
+ await ban.save();
+ }
+ }
break;
case "CHANNEL_CREATE":
if (!permission.overwriteChannel(data.permission_overwrites).has("VIEW_CHANNEL")) {
diff --git a/src/gateway/util/WebSocket.ts b/src/gateway/util/WebSocket.ts
index 00ef9e98..d0a42eaf 100644
--- a/src/gateway/util/WebSocket.ts
+++ b/src/gateway/util/WebSocket.ts
@@ -33,6 +33,7 @@ export interface WebSocket extends WS {
compress?: "zlib-stream" | "zstd-stream";
ipAddress?: string;
userAgent?: string; // for cdn request signing
+ fingerprint?: string;
shard_count?: bigint;
shard_id?: bigint;
deflate?: Deflate;
|