Personal Telegram developer console for GitHub
security: enforce streamed editor request size without Content-Length
davoodmehraban89 committed
Oct 24, 2026 at 18:00 UTC
9c8717299f1894b2e39a2e7b1d8e706ae3f1530f
1 file changed
+6
-7
src/workspace-editor.js
+6
-7
@@ -4,6 +4,7 @@ import {
4
validateEditableFile
5
} from './core/workspace-policy.js';
6
import { validateTelegramWebAppInitData } from './core/telegram-webapp-auth.js';
7
+import { readBoundedJson } from './core/bounded-json.js';
8
9
const WORKSPACE_ID = /^[A-Za-z0-9_-]{10}$/;
10
@@ -70,15 +71,13 @@ export async function handleWorkspaceEditorRequest(request, {
71
}
72
73
if (request.method === 'PUT') {
73
- const contentLength = Number(request.headers.get('content-length'));
74
- if (Number.isFinite(contentLength) && contentLength > WORKSPACE_EDITOR_LIMITS.maxBytes + 4096) {
75
- return jsonResponse({ ok: false, error: 'Editor request body is too large' }, 413);
76
- }
74
let body;
75
try {
79
- body = await request.json();
80
- } catch {
81
- throw new Error('Editor request body must be valid JSON');
76
+ body = await readBoundedJson(request, WORKSPACE_EDITOR_LIMITS.maxBytes + 4096);
77
+ } catch (error) {
78
+ if (error instanceof RangeError) return jsonResponse({ ok: false, error: 'Editor request body is too large' }, 413);
79
+ if (error instanceof SyntaxError) return jsonResponse({ ok: false, error: 'Editor request body must be valid JSON' }, 400);
80
+ throw error;
81
}
82
const workspaceId = safeWorkspaceId(body?.workspaceId);
83
const workspace = await workspaces.getWorkspace({ ownerId: owner, workspaceId });