Skip to content

fix(request,response): cache regexp patterns, set Content-Length, and…#22

Merged
KARTIKrocks merged 1 commit into
mainfrom
fix/request-response-hardening
Apr 4, 2026
Merged

fix(request,response): cache regexp patterns, set Content-Length, and…#22
KARTIKrocks merged 1 commit into
mainfrom
fix/request-response-hardening

Conversation

@KARTIKrocks
Copy link
Copy Markdown
Owner

… validate JSONP callbacks

Summary

Changed

  • requestMatchesRegexp now caches compiled *regexp.Regexp patterns in a sync.Map, eliminating repeated recompilation
  • requestValidation.MatchesPattern delegates to the cached MatchesRegexp instead of calling regexp.MatchString directly
  • responsewrite() marshals JSON to a buffer first and sets the Content-Length header before writing, improving client framing behavior
  • response — JSONP output is now prefixed with /**/ to mitigate Rosetta Flash and content-type-sniffing attacks

Fixed

  • response — JSONP callback parameter is validated against ^[a-zA-Z_$][a-zA-Z0-9_$.]*$; invalid names return 400 to prevent XSS injection
  • response — JSON encoding errors in write() are now caught before headers are sent, returning a clean 500 instead of a truncated body

Checklist

  • fmt, vet, lint, test, build passes (make all)
  • New code has tests where appropriate
  • Breaking changes are documented

@KARTIKrocks KARTIKrocks self-assigned this Apr 4, 2026
@KARTIKrocks KARTIKrocks merged commit 8f7b51c into main Apr 4, 2026
10 checks passed
@KARTIKrocks KARTIKrocks deleted the fix/request-response-hardening branch April 4, 2026 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant