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