Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential fix for code scanning alert no. 8: Missing rate limiting #5

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { baremuxPath } from "@mercuryworkshop/bare-mux/node";
import { meteorPath } from "meteorproxy"
import wisp from "wisp-server-node";
import { createBareServer } from "@tomphttp/bare-server-node"
//wahts the library i forgot
import RateLimit from "express-rate-limit";
import net from "node:net"
import { hostname } from "node:os"
const __filename = fileURLToPath(import.meta.url);
Expand Down Expand Up @@ -294,6 +294,15 @@ function startServer() {
console.log(chalk.green("Serving", chalk.yellow("Daylight's"), chalk.green("files")));
console.log(chalk.green("All necessary files served. Setting up server."))

// set up rate limiter: maximum of 100 requests per 15 minutes
const limiter = RateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // max 100 requests per windowMs
});

// apply rate limiter to all requests
app.use(limiter);

app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "dist/index.html"));
});
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
"vite-plugin-static-copy": "^1.0.6",
"vite-plugin-vsharp": "^1.8.1",
"wisp-server-node": "^1.1.3",
"zod": "^3.23.8"
"zod": "^3.23.8",
"express-rate-limit": "^7.5.0"
},
"devDependencies": {
"@babel/core": "^7.24.9",
Expand Down
Loading