Skip to content

Conversation

@topherbullock
Copy link
Contributor

@topherbullock topherbullock commented Oct 27, 2025

Add ID validation to prevent XSS vulnerabilities

This PR adds string ID validation to protect against XSS vulnerabilities when request IDs are reflected in responses. By default, string IDs are now validated to contain only alphanumeric characters, dashes, and underscores; this prevents users from sending HTML content that is reflected back in responses. Reflecting raw ids with HTML content in responses opens a vector for XSS if proper content type validations are not also applied.

The validation pattern can be customized by passing an id_validation_pattern parameter to handle or handle_json methods:

  • Default pattern: /\A[a-zA-Z0-9_-]+\z/
  • Custom pattern: Pass any regex pattern to allow different characters
  • Disable validation: Pass nil to accept any string ID (not recommended)

The README has been updated with examples showing how to use and customize the ID validation.

prevent potential for XSS by rejecting ids with special characters
allow passing a validation pattern to override the default id validations
@topherbullock topherbullock force-pushed the validate-request-id-formatting branch from 3661b11 to a5cf618 Compare October 28, 2025 18:14
@topherbullock topherbullock marked this pull request as ready for review October 28, 2025 18:16
@topherbullock topherbullock merged commit b41c412 into main Oct 28, 2025
7 checks passed
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.

2 participants