fix(webhook): validate custom headers as a control-char-free string map - #403
Merged
Conversation
The webhook `headers` field was only @isObject — it accepted any shape with no per-value validation, so a value containing CR/LF could attempt header injection into the outbound request and non-string values silently broke delivery. Add an @IsHeaderMap validator (Create + Update DTOs) that requires valid header names, string values free of C0 control chars (the CR/LF injection vector), and bounds the map (max 50 entries, value max 1024 chars). The delivery-time reserved-name filter (sanitizeCustomHeaders) is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The webhook
headersfield (Create + Update DTOs) was validated only with@IsObject()— it accepted any object shape with no per-entry checks. That allowed:CR/LF(e.g."a\r\nX-Injected: 1") could attempt to inject extra headers into the outbound webhook request.A new
@IsHeaderMap()validator now requires a flat map of valid header names ([A-Za-z0-9-]+) to string values that are free of C0 control characters + DEL, and bounds the map (≤50 entries, value ≤1024 chars). The existing delivery-time reserved-name filter (sanitizeCustomHeaders) is unchanged — this is the complementary input-side guard.Tests
webhook.dto.spec.ts: accepts a normal string map; rejects CR/LF values (injection), non-string values, invalid header names;UpdateWebhookDtoenforces the same.Risk
Low. Only rejects header maps that were already malformed or unsafe at delivery — surfaces the error at create/update time (400) instead of silently mangling or injecting at send time. Valid string headers are unaffected.