Skip to content

Commit 3c79758

Browse files
JohnMcLearclaude
andcommitted
Fix: add 1MB size limit on request body to prevent DoS
The POST /post endpoint buffered the entire request body with no size limit, allowing an attacker to exhaust server memory. Now rejects requests larger than 1MB with HTTP 413. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8650d0b commit 3c79758

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,27 @@
33
const API = require('ep_etherpad-lite/node/db/API.js');
44
const randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
55

6+
const MAX_BODY_SIZE = 1024 * 1024; // 1 MB
7+
68
exports.registerRoute = (hookName, args, callback) => {
79
args.app.post('/post', (req, res) => {
810
let padId = req.headers['x-pad-id'];
911
if (padId === undefined) {
1012
padId = randomString(8);
1113
}
1214
let content = '';
15+
let aborted = false;
1316

1417
req.on('data', (data) => {
15-
// Append data.
1618
content += data;
19+
if (content.length > MAX_BODY_SIZE) {
20+
aborted = true;
21+
res.status(413).send('Request body too large');
22+
req.destroy();
23+
}
1724
});
1825
req.on('end', async () => {
26+
if (aborted) return;
1927
let padExists = true;
2028
try {
2129
padExists = await API.getText(padId, 0);

0 commit comments

Comments
 (0)