fix(security): sanitize theme option values at emission (S1) and escape imagefile option HTML (S2)

S1 (HIGH, SECURITY_REVIEW_20261129.md): LimeSurvey renders theme twig with
autoescape OFF, so stored option values are untrusted on the public survey
pages. New views/subviews/security_macros.twig provides validators (color,
length, keyword, fontslug, pxnum, iconcode) applied at every emission point:
the <style> block in custom_header.twig (incl. the resolved values of the
cm()/cmbg() chooser macros), the inline style="color:..." and font-<slug>
class attributes in all survey subviews, and the <body> font class +
data-thememode in the newly overridden layout_global.twig and
layout_survey_list.twig. Crafted values fall back to the configured
defaults; legitimate picker/enum/slug values pass unchanged.

S2 (MEDIUM): options/options.twig escapes group/preview/filepath/filename
with |e('html_attr')/|e('html') when building the imagefile <option> HTML.

Verified: twig compile of all changed templates, malicious-value renders
neutralized + legit renders unchanged, live surveys 216664/282267 render
correct colors with no twig errors, jsdom custom_js tests pass (options_*
tests still need /tmp fixtures, pre-existing), export_public.sh exit 0.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Tammo ter Hark 2026-11-30 11:27:38 +01:00
commit d8ee93a1c0

View file

@ -36,6 +36,8 @@ For the survey navigator ("Next", "Back", etc.), see: navigation/navigator.twig
{%- endif -%}
{%- endmacro %}
{% import _self as navmacros %}
{# S1: sanitize option values at emission (autoescape is OFF) — see security_macros.twig #}
{% import './subviews/security_macros.twig' as sec %}
{% if not aSurveyInfo.popupPreview %}
{% set navClass = "navbar-light bg-light" %}
{% if( aSurveyInfo.template == "bootswatch") %}
@ -72,6 +74,7 @@ For the survey navigator ("Next", "Back", etc.), see: navigation/navigator.twig
Emitted as an inline style on #survey-nav below. #}
{% set sHeaderTextColorMode = aSurveyInfo.options.headertextcolor|default('default') %}
{% set sHeaderTextColor = sHeaderTextColorMode == 'primary' ? aSurveyInfo.options.primarycolor|default('') : (sHeaderTextColorMode == 'secondary' ? aSurveyInfo.options.secondarycolor|default('') : (sHeaderTextColorMode == 'other' ? aSurveyInfo.options.headertextcolorcustom|default('') : aSurveyInfo.options.fontcolor|default(''))) %}
{% set sHeaderTextColor = sec.color(sHeaderTextColor, '') %}
{# THEME ADDITION: sticky header per screen size (options
headersticky{computer,tablet,mobile}; Prompt L — the master key no longer
counts). When the checkbox options exist (theme was reset after adding
@ -79,7 +82,7 @@ For the survey navigator ("Next", "Back", etc.), see: navigation/navigator.twig
the media queries instead. Before a reset the old behaviour (always
fixed-top) is kept as fallback. #}
{% set bStickyConfigured = aSurveyInfo.options.headerstickycomputer is defined %}
<div id="survey-nav" class="navbar {{ navClass }} navbar-expand-md {% if not bStickyConfigured %}fixed-top{% endif %} border-bottom pt-0 pb-0 {% if sHeaderFont != 'base' %}font-{{ sHeaderFont }}{% endif %}"{% if sHeaderTextColor != '' %} style="color: {{ sHeaderTextColor }};"{% endif %}>
<div id="survey-nav" class="navbar {{ navClass }} navbar-expand-md {% if not bStickyConfigured %}fixed-top{% endif %} border-bottom pt-0 pb-0 {% if sHeaderFont != 'base' %}font-{{ sec.fontslug(sHeaderFont) }}{% endif %}"{% if sHeaderTextColor != '' %} style="color: {{ sHeaderTextColor }};"{% endif %}>
<div class="container-fluid d-flex flex-column">
{# ROW 1 — the logos (layout rules in sass/plain.sass): left logo always
far left, center logo always exactly centered (absolute, independent