Hash the web password and revoke sessions server-side
Store a scrypt hash (migrating a plaintext password without changing it), sign sessions with a generation that ./password and --revoke-all rotate, make logout a same-origin POST that revokes the token, add sign out everywhere, and close proxied websockets whose session ends. Enforce a strength rule for new passwords, back off logins per client and server-wide, check Origin on login, tighten next, add security headers and a __Host- cookie over https.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// The upgraded browser sockets (the /connect websocket and relayed peer
|
||||
// sockets), each with the session token it was opened with. A sweep destroys
|
||||
// every socket whose session is no longer valid: signed out, signed out
|
||||
// everywhere, expired, or issued before a password change.
|
||||
export class SessionSockets {
|
||||
constructor() {
|
||||
this.sockets = new Map(); // socket -> token
|
||||
}
|
||||
|
||||
track(socket, token) {
|
||||
this.sockets.set(socket, token);
|
||||
socket.once("close", () => this.sockets.delete(socket));
|
||||
}
|
||||
|
||||
get size() {
|
||||
return this.sockets.size;
|
||||
}
|
||||
|
||||
/** Destroys the sockets whose token valid() rejects; returns how many. */
|
||||
sweep(valid) {
|
||||
let closed = 0;
|
||||
for (const [socket, token] of this.sockets) {
|
||||
if (valid(token)) continue;
|
||||
this.sockets.delete(socket);
|
||||
socket.destroy();
|
||||
closed++;
|
||||
}
|
||||
return closed;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user