Skip to content

Commit 71a7b81

Browse files
Potential fix for code scanning alert no. 13: Missing rate limiting
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 4d93a9e commit 71a7b81

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

examples/developer-hub-javascript/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
1818
"cors": "^2.8.5",
1919
"hardhat": "^2.26.1",
20-
"web3": "^4.16.0"
20+
"web3": "^4.16.0",
21+
"express-rate-limit": "^8.2.1"
2122
},
2223
"devDependencies": {
2324
"@babel/eslint-parser": "^7.28.0",

examples/developer-hub-javascript/x402Server.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ import { ethers } from "ethers";
1616
import * as fs from "fs";
1717
import * as path from "path";
1818
import "dotenv/config";
19+
import rateLimit from "express-rate-limit";
1920

2021
const app = express();
2122
app.use(cors());
23+
24+
const rootRateLimiter = rateLimit({
25+
windowMs: 15 * 60 * 1000, // 15 minutes
26+
max: 100, // limit each IP to 100 requests per windowMs
27+
});
2228
app.use(express.json());
2329

2430
// Configuration
@@ -298,7 +304,7 @@ app.get("/health", (req: Request, res: Response) => {
298304
});
299305

300306
// Serve frontend - inject config into HTML
301-
app.get("/", (req: Request, res: Response) => {
307+
app.get("/", rootRateLimiter, (req: Request, res: Response) => {
302308
const frontendPath = path.join(__dirname, "frontend.html");
303309
let html = fs.readFileSync(frontendPath, "utf-8");
304310

0 commit comments

Comments
 (0)