Module: Dandruff::Expressions Private
- Defined in:
- lib/dandruff/expressions.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Regular expressions for attribute matching and content validation
This module contains regular expressions used throughout Dandruff for validating attributes, detecting template expressions, and checking URI protocols. These patterns are critical for security and should not be modified without careful consideration.
Constant Summary collapse
- DATA_ATTR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Matches HTML5 data attributes (data-*)
Validates attribute names that follow the data attribute specification. Data attributes must start with ‘data-’ followed by one or more word characters or hyphens.
/^data-[\w-]+$/- ARIA_ATTR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Matches ARIA accessibility attributes (aria-*)
Validates attribute names that follow the ARIA specification. ARIA attributes must start with ‘aria-’ followed by one or more word characters or hyphens.
/^aria-[\w-]+$/- MUSTACHE_EXPR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Matches Mustache/Handlebars template expressions
Detects template expressions in the format ‘expression }`. Used when
safe_for_templatesis enabled to prevent template injection attacks. /\{\{[^}]+\}\}/- ERB_EXPR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Matches ERB (Embedded Ruby) template expressions
Detects ERB expressions in the format ‘<% expression %>`, `<%= expression %>`, or `<%- expression %>`. Used when
safe_for_templatesis enabled. /<%[=-]?[^%]+%>/- TMPLIT_EXPR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Matches JavaScript template literal expressions
Detects template expressions in the format ‘${ expression }`. Used when
safe_for_templatesis enabled to prevent template injection. /\$\{[^}]+\}/- IS_ALLOWED_URI =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Validates allowed URI protocols and relative URLs
This is the default URI validation pattern matching DOMPurify’s behavior. Allows: http, https, mailto, ftp, tel protocols and relative URLs. Blocks: javascript, data, vbscript, and other dangerous protocols.
**Allowed protocols:** http, https, mailto, ftp, tel, relative URLs (/, ./, ../) **Blocked protocols:** javascript, vbscript, data (unless explicitly enabled)
/^(?:(?:https?|mailto|ftp|tel):|[^a-z]|[a-z+.-]+(?:[^a-z+.-:]|$))/i- IS_SCRIPT_OR_DATA =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Detects dangerous JavaScript and data:text/html URIs
Matches URIs that start with
javascript:ordata:text/htmlprotocols, which are common XSS attack vectors. These are always blocked regardless of other configuration. Whitespace before the protocol is also detected. %r{^(?:\s*javascript:|\s*data:text/html)}i