-
Notifications
You must be signed in to change notification settings - Fork 11
Enforce JSON Content-Type on mutating requests #76
Copy link
Copy link
Open
Labels
GRANTFOX OSSGrantFox open-source campaign taskGrantFox open-source campaign taskMAYBE REWARDEDMay be rewarded under the GrantFox campaignMay be rewarded under the GrantFox campaignOFFICIAL CAMPAIGNOfficial GrantFox campaign issueOfficial GrantFox campaign issuearea:request-validationrequest validationrequest validationpriority:mediumMedium priorityMedium prioritystack:expressstack:expressstack:expressstack:nodejsNode.jsNode.jsstack:typescriptTypeScriptTypeScripttype:securitySecurity hardening / fixSecurity hardening / fix
Description
Metadata
Metadata
Assignees
Labels
GRANTFOX OSSGrantFox open-source campaign taskGrantFox open-source campaign taskMAYBE REWARDEDMay be rewarded under the GrantFox campaignMay be rewarded under the GrantFox campaignOFFICIAL CAMPAIGNOfficial GrantFox campaign issueOfficial GrantFox campaign issuearea:request-validationrequest validationrequest validationpriority:mediumMedium priorityMedium prioritystack:expressstack:expressstack:expressstack:nodejsNode.jsNode.jsstack:typescriptTypeScriptTypeScripttype:securitySecurity hardening / fixSecurity hardening / fix
Type
Fields
Give feedbackNo fields configured for Feature.
Reject non-JSON Content-Type on write requests
Description
src/index.tsmountsexpress.json({ limit: "100kb" }), which only parses bodies whoseContent-Typeis JSON and otherwise leavesreq.bodyundefined. APOST /api/v1/pairssent astext/plainorapplication/x-www-form-urlencodedtherefore arrives with no parsed body and falls through the handlers'req.body ?? {}guards, producing confusing400 invalid_requestmessages rather than a clear content-type rejection. This issue adds an explicit415 unsupported_media_typeguard for mutating methods.Requirements and context
POST,PATCH,PUT) that include a payload, requires aContent-Typeofapplication/json(allowingcharsetparameters).415 unsupported_media_typewith the canonical{ error, message, requestId }body when the type is missing or wrong.GET/HEAD/DELETE/OPTIONSand for empty bodies.requestIdis present in the error body, and before the route handlers.Suggested execution
git checkout -b security/request-validation-28-content-typesrc/index.ts— add the content-type guard middleware.src/__tests__/index.test.ts— POST a pair withtext/plain(415), withapplication/json(works), and a bodyless DELETE (unaffected).README.md.Content-Typecannot bypass the body-size limit or smuggle an unparsed body into a handler.Test and commit
npm run build,npm run lint, andnpm test.npm testoutput in the PR.Example commit message
feat(security): enforce application/json content-type on writesGuidelines
Community & contribution rewards