add filesize rate limiting
This commit is contained in:
parent
7fba908b7c
commit
dd400b1d2a
@ -17,6 +17,7 @@ import {
|
||||
} from "./utils"
|
||||
import { IDisposable, IPty, spawn } from "node-pty"
|
||||
import {
|
||||
MAX_BODY_SIZE,
|
||||
createFileRL,
|
||||
deleteFileRL,
|
||||
renameFileRL,
|
||||
@ -116,6 +117,14 @@ io.on("connection", async (socket) => {
|
||||
try {
|
||||
await saveFileRL.consume(data.userId, 1)
|
||||
|
||||
if (Buffer.byteLength(body, "utf-8") > MAX_BODY_SIZE) {
|
||||
socket.emit(
|
||||
"rateLimit",
|
||||
"Rate limited: file size too large. Please reduce the file size."
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
const file = sandboxFiles.fileData.find((f) => f.id === fileId)
|
||||
if (!file) return
|
||||
file.data = body
|
||||
|
@ -5,6 +5,8 @@ export const saveFileRL = new RateLimiterMemory({
|
||||
duration: 1,
|
||||
})
|
||||
|
||||
export const MAX_BODY_SIZE = 5 * 1024 * 1024
|
||||
|
||||
export const createFileRL = new RateLimiterMemory({
|
||||
points: 3,
|
||||
duration: 1,
|
||||
|
Loading…
x
Reference in New Issue
Block a user