mirror of
https://github.com/LightZirconite/Microsoft-Rewards-Bot.git
synced 2026-01-10 17:26:17 +00:00
Potential fix for code scanning alert no. 21: Missing rate limiting
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Obsidian <123307773+LightZirconite@users.noreply.github.com>
This commit is contained in:
@@ -87,6 +87,7 @@
|
|||||||
"rebrowser-playwright": "1.52.0",
|
"rebrowser-playwright": "1.52.0",
|
||||||
"socks-proxy-agent": "^8.0.5",
|
"socks-proxy-agent": "^8.0.5",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"ws": "^8.18.3"
|
"ws": "^8.18.3",
|
||||||
|
"express-rate-limit": "^8.2.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ import fs from 'fs'
|
|||||||
import { createServer } from 'http'
|
import { createServer } from 'http'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { WebSocket, WebSocketServer } from 'ws'
|
import { WebSocket, WebSocketServer } from 'ws'
|
||||||
|
import rateLimit from 'express-rate-limit'
|
||||||
import { log as botLog } from '../util/notifications/Logger'
|
import { log as botLog } from '../util/notifications/Logger'
|
||||||
import { apiRouter } from './routes'
|
import { apiRouter } from './routes'
|
||||||
import { DashboardLog, dashboardState } from './state'
|
import { DashboardLog, dashboardState } from './state'
|
||||||
@@ -20,7 +21,12 @@ export class DashboardServer {
|
|||||||
private server: ReturnType<typeof createServer>
|
private server: ReturnType<typeof createServer>
|
||||||
private wss: WebSocketServer
|
private wss: WebSocketServer
|
||||||
private clients: Set<WebSocket> = new Set()
|
private clients: Set<WebSocket> = new Set()
|
||||||
|
private dashboardLimiter = rateLimit({
|
||||||
|
windowMs: 15 * 60 * 1000, // 15 minutes
|
||||||
|
max: 100, // limit each IP to 100 requests per windowMs for dashboard UI
|
||||||
|
standardHeaders: true,
|
||||||
|
legacyHeaders: false,
|
||||||
|
})
|
||||||
constructor() {
|
constructor() {
|
||||||
this.app = express()
|
this.app = express()
|
||||||
this.server = createServer(this.app)
|
this.server = createServer(this.app)
|
||||||
@@ -69,7 +75,7 @@ export class DashboardServer {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Serve dashboard UI
|
// Serve dashboard UI
|
||||||
this.app.get('/', (_req, res) => {
|
this.app.get('/', this.dashboardLimiter, (_req, res) => {
|
||||||
const indexPath = path.join(__dirname, '../../public/index.html')
|
const indexPath = path.join(__dirname, '../../public/index.html')
|
||||||
|
|
||||||
// Force no cache on HTML files
|
// Force no cache on HTML files
|
||||||
|
|||||||
Reference in New Issue
Block a user