Skip to content

Commit 43e31ed

Browse files
authored
Merge pull request #5 from NightProxy/alert-autofix-8
Potential fix for code scanning alert no. 8: Missing rate limiting
2 parents d809f52 + f774624 commit 43e31ed

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { baremuxPath } from "@mercuryworkshop/bare-mux/node";
1818
import { meteorPath } from "meteorproxy"
1919
import wisp from "wisp-server-node";
2020
import { createBareServer } from "@tomphttp/bare-server-node"
21-
//wahts the library i forgot
21+
import RateLimit from "express-rate-limit";
2222
import net from "node:net"
2323
import { hostname } from "node:os"
2424
const __filename = fileURLToPath(import.meta.url);
@@ -294,6 +294,15 @@ function startServer() {
294294
console.log(chalk.green("Serving", chalk.yellow("Daylight's"), chalk.green("files")));
295295
console.log(chalk.green("All necessary files served. Setting up server."))
296296

297+
// set up rate limiter: maximum of 100 requests per 15 minutes
298+
const limiter = RateLimit({
299+
windowMs: 15 * 60 * 1000, // 15 minutes
300+
max: 100, // max 100 requests per windowMs
301+
});
302+
303+
// apply rate limiter to all requests
304+
app.use(limiter);
305+
297306
app.get("/", (req, res) => {
298307
res.sendFile(path.join(__dirname, "dist/index.html"));
299308
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@
9797
"vite-plugin-static-copy": "^1.0.6",
9898
"vite-plugin-vsharp": "^1.8.1",
9999
"wisp-server-node": "^1.1.3",
100-
"zod": "^3.23.8"
100+
"zod": "^3.23.8",
101+
"express-rate-limit": "^7.5.0"
101102
},
102103
"devDependencies": {
103104
"@babel/core": "^7.24.9",

0 commit comments

Comments
 (0)