mirror of
https://github.com/Yonle/bostr.git
synced 2025-09-20 14:40:41 +02:00
config&http: allow blocking websocket connections from the specified hosts
Signed-off-by: Yonle <yonle@lecturify.net>
This commit is contained in:
@@ -89,6 +89,15 @@ module.exports = {
|
|||||||
// ....
|
// ....
|
||||||
],
|
],
|
||||||
|
|
||||||
|
// Block incomming websocket connections from the following hosts.
|
||||||
|
blocked_hosts: [
|
||||||
|
// "127.0.0.1",
|
||||||
|
// "127.0.0.2",
|
||||||
|
// "::1",
|
||||||
|
// "::2",
|
||||||
|
// ....
|
||||||
|
],
|
||||||
|
|
||||||
// Used for accessing NIP-42 protected events from certain relays.
|
// Used for accessing NIP-42 protected events from certain relays.
|
||||||
// It could be your key. Leaving this empty completely disables NIP-42 function.
|
// It could be your key. Leaving this empty completely disables NIP-42 function.
|
||||||
//
|
//
|
||||||
|
2
http.js
2
http.js
@@ -89,6 +89,8 @@ server.on('upgrade', (req, sock, head) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ip = req.headers["x-forwarded-for"]?.split(",")[0] || sock.address()?.address;
|
const ip = req.headers["x-forwarded-for"]?.split(",")[0] || sock.address()?.address;
|
||||||
|
|
||||||
|
if (config.blocked_hosts && config.blocked_hosts.includes(ip)) return sock.destroy();
|
||||||
const lv = lastConn.get(ip) // last visit
|
const lv = lastConn.get(ip) // last visit
|
||||||
if (config.incomming_ratelimit && (config.incomming_ratelimit > (Date.now() - lv))) {
|
if (config.incomming_ratelimit && (config.incomming_ratelimit > (Date.now() - lv))) {
|
||||||
log(`Rejected connection from ${ip} as the last connection was ${Date.now() - lv} ms ago.`);
|
log(`Rejected connection from ${ip} as the last connection was ${Date.now() - lv} ms ago.`);
|
||||||
|
Reference in New Issue
Block a user