{# Security macros — S1 of SECURITY_REVIEW_20261129.md (approved by the owner). LimeSurvey renders theme twig with autoescape OFF, so every theme option value emitted into a `, quotes, braces, semicolons, parens etc. can never reach the output. Import in a view with: {% import './subviews/security_macros.twig' as sec %} ('./' resolves against the theme's views/ root, like every other include). NOTE: twig macros only see globals + their own arguments, so macros defined in custom_header.twig itself (cm/cmbg) cannot call sec.* — they inline the same validation instead. #} {# A CSS color value: #rgb/#rrggbb/#rrggbbaa hex, or a plain color keyword (transparent, lightyellow, currentColor, ...). Anything else -> fallback. #} {% macro color(value, fallback = '') -%} {%- set v = value|default('') -%} {{- (v matches '/^#[0-9a-fA-F]{3,8}$/' or v matches '/^[a-zA-Z]{3,20}$/') ? v : fallback|default('') -}} {%- endmacro %} {# A CSS length/percentage: 16px, 1.2rem, 2em, 90%, ... #} {% macro length(value, fallback = '') -%} {%- set v = value|default('') -%} {{- v matches '/^[0-9]+([.][0-9]+)?(px|rem|em|%)$/' ? v : fallback|default('') -}} {%- endmacro %} {# A single CSS keyword/enum: solid, dashed, italic, fixed, tile, cover, ... #} {% macro keyword(value, fallback = '') -%} {%- set v = value|default('') -%} {{- v matches '/^[a-zA-Z-]{1,30}$/' ? v : fallback|default('') -}} {%- endmacro %} {# A font-select slug, emitted as the class token font- inside a class attribute: [a-zA-Z0-9_-] only; invalid values become "base" (no override). #} {% macro fontslug(value) -%} {%- set v = value|default('') -%} {{- v matches '/^[a-zA-Z0-9_-]{1,40}$/' ? v : 'base' -}} {%- endmacro %} {# A unitless px number (the "px" is appended in the template): digits only. #} {% macro pxnum(value, fallback = '0') -%} {%- set v = value|default('') -%} {{- v matches '/^[0-9]{1,4}$/' ? v : fallback|default('0') -}} {%- endmacro %} {# A check-icon unicode codepoint for the CSS content property (e.g. EB7A): hex digits only; anything else -> fallback. #} {% macro iconcode(value, fallback = 'EB7A') -%} {%- set v = value|default('') -%} {{- v matches '/^[0-9a-fA-F]{1,6}$/' ? v : fallback|default('EB7A') -}} {%- endmacro %}