Log notification subscription lifecycle and websocket rejections
This commit is contained in:
@@ -705,6 +705,12 @@ function proxyUpgrade(req, clientSocket, clientHead) {
|
||||
clientSocket.on("error", () => upstream.destroy());
|
||||
}
|
||||
|
||||
function logRejectedUpgrade(status, pathname, reason) {
|
||||
// pathname excludes the query string so cookies/tokens can never enter this
|
||||
// diagnostic line.
|
||||
console.warn(`websocket upgrade rejected status=${status} path=${pathname} reason=${reason}`);
|
||||
}
|
||||
|
||||
server.on("upgrade", (req, clientSocket, clientHead) => {
|
||||
try { refreshAuth(); } catch {
|
||||
clientSocket.end("HTTP/1.1 503 Service Unavailable\r\nContent-Length: 0\r\n\r\n");
|
||||
@@ -712,11 +718,13 @@ server.on("upgrade", (req, clientSocket, clientHead) => {
|
||||
}
|
||||
const pathname = (req.url ?? "").split("?")[0];
|
||||
if (access.plainLanBlocked(req) || !sameOriginUpgrade(req.headers.origin, req.headers.host)) {
|
||||
logRejectedUpgrade(403, pathname, access.plainLanBlocked(req) ? "LAN access refused" : "origin mismatch");
|
||||
clientSocket.write("HTTP/1.1 403 Forbidden\r\nConnection: close\r\nContent-Length: 0\r\n\r\n");
|
||||
clientSocket.destroy();
|
||||
return;
|
||||
}
|
||||
if (auth && !isAuthed(req)) {
|
||||
logRejectedUpgrade(401, pathname, "not authenticated");
|
||||
clientSocket.write("HTTP/1.1 401 Unauthorized\r\nConnection: close\r\nContent-Length: 0\r\n\r\n");
|
||||
clientSocket.destroy();
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user