etherpad-lite/src/node/hooks/express
John McLear af03259555
fix: POST API requests with JSON body no longer time out (#7455)
* fix: POST API requests with JSON body no longer time out

When express.json() middleware parses the request body before the
OpenAPI handler runs, formidable's IncomingForm hangs forever waiting
for stream data that was already consumed. Now checks req.body first
and only falls back to formidable for multipart/form-data requests.

Also fixed case-insensitive method check (c.request.method may be
uppercase depending on openapi-backend version).

Fixes #7127

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: handle empty JSON body and missing method safely

- Remove Object.keys().length > 0 check on req.body so empty JSON
  objects ({}) don't fall through to formidable (which would hang)
- Guard c.request.method with fallback to empty string to prevent
  TypeError if method is undefined

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* security: prevent parameter pollution by excluding headers from field merge

Previously Object.assign merged headers, params, query, and formData
into a single fields object. This allowed POST body parameters to
override security-sensitive headers like Authorization, or headers to
pollute API parameter values.

Now only merges params, query, and formData. The Authorization header
is passed explicitly as a fallback for legacy API key authentication,
but cannot be overridden by body/query parameters.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-05 01:58:35 +01:00
..
admin.ts chore: fix minor issue on admin retrieval 2025-09-08 20:11:45 +02:00
adminplugins.ts feat: disable stats endpoint if enableMetrics is false 2025-07-27 22:22:18 +02:00
adminsettings.ts Enforce 2-space indentation across codebase (#7426) 2026-04-01 19:48:45 +01:00
apicalls.ts chore: fixed objectAsString 2025-08-01 21:58:10 +02:00
errorhandling.ts Added typescript to etherpad 2024-02-05 21:13:02 +01:00
importexport.ts feat: make cookie names configurable with prefix setting (#7450) 2026-04-05 01:58:29 +01:00
openapi.ts fix: POST API requests with JSON body no longer time out (#7455) 2026-04-05 01:58:35 +01:00
padurlsanitize.ts Added typescript to etherpad 2024-02-05 21:13:02 +01:00
pwa.ts chore: migrated settings to esm6 (#7062) 2025-08-04 22:42:50 +02:00
socketio.ts chore: migrated settings to esm6 (#7062) 2025-08-04 22:42:50 +02:00
specialpages.ts feat: make cookie names configurable with prefix setting (#7450) 2026-04-05 01:58:29 +01:00
static.ts chore: migrated settings to esm6 (#7062) 2025-08-04 22:42:50 +02:00
tokenTransfer.ts feat: make cookie names configurable with prefix setting (#7450) 2026-04-05 01:58:29 +01:00
webaccess.ts chore: migrated settings to esm6 (#7062) 2025-08-04 22:42:50 +02:00