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

security: address code scanning alert for missing rate limiting #76

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"dotenv": "^16.4.5",
"express": "^5.0.0",
"fast-xml-parser": "^4.5.0",
"luxon": "^3.5.0"
"luxon": "^3.5.0",
"express-rate-limit": "^7.4.1"
},
"devDependencies": {
"@types/express": "^5.0.0",
Expand Down
8 changes: 8 additions & 0 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { json } from 'body-parser';
import express, { Express, Request, Response } from 'express';
import { XMLParser } from 'fast-xml-parser';
import path from 'path';
import rateLimit from 'express-rate-limit';

import { cleanTableData } from './cleanTableData';
import { SpotTheStationResponse } from './types';
Expand All @@ -15,6 +16,13 @@ export class Server {
this.app = app;
this.app.disable('x-powered-by'); // security

const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit each IP to 100 requests per windowMs
});

this.app.use(limiter);

this.app.use(express.static(path.resolve('../dist/web')));

this.app.use(json());
Expand Down
Loading