-
Notifications
You must be signed in to change notification settings - Fork 11
Sanitize the inbound X-Request-Id to prevent header and log injection #77
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-idrequest idrequest idpriority: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-idrequest idrequest idpriority:mediumMedium priorityMedium prioritystack:expressstack:expressstack:expressstack:nodejsNode.jsNode.jsstack:typescriptTypeScriptTypeScripttype:securitySecurity hardening / fixSecurity hardening / fix
Type
Fields
Give feedbackNo fields configured for Feature.
Sanitize the client-supplied X-Request-Id
Description
The correlation middleware in
src/index.tstrusts the inboundx-request-idheader verbatim as long as its length is<= 200, then reflects it into theX-Request-Idresponse header and into every structured log line and JSON error body. A value containing CRLF or control characters can forge log entries (log injection) or, depending on the downstream proxy, split response headers. This issue restricts the accepted id to a safe character set and otherwise generates a fresh UUID.Requirements and context
x-request-idonly when it matches a strict pattern (e.g.^[A-Za-z0-9._-]{1,200}$); otherwise fall back torandomUUID().X-Request-Idresponse header and echo the id in error bodies, but only with the sanitized value.requestIdfield can take.Suggested execution
git checkout -b security/request-id-29-sanitizesrc/index.ts— tighten the id acceptance check in the correlation middleware.src/__tests__/index.test.ts— send a valid id (echoed), a CRLF-containing id (replaced with a UUID), an over-length id (replaced), and no id (UUID).X-Request-Idformat inREADME.md.Test and commit
npm run build,npm run lint, andnpm test.npm testoutput and a short note on the injection vector in the PR.Example commit message
fix(security): sanitize inbound X-Request-Id against header/log injectionGuidelines
Community & contribution rewards