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:
parent
2b19f350f4
commit
d8ee93a1c0
1 changed files with 322 additions and 36 deletions
160
views/layout_global.twig
Normal file
160
views/layout_global.twig
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
{#
|
||||
LimeSurvey
|
||||
Copyright (C) 2007-2026 The LimeSurvey Project Team
|
||||
All rights reserved.
|
||||
License: GNU/GPL License v2 or later, see LICENSE.php
|
||||
LimeSurvey is free software. This version may have been modified pursuant
|
||||
to the GNU General Public License, and as distributed it includes or
|
||||
is derivative of works licensed under the GNU General Public License or
|
||||
other free or open source software licenses.
|
||||
See COPYRIGHT.php for copyright notices and details.
|
||||
|
||||
(¯`·._.·(¯`·._.· Global Layout ·._.·´¯)·._.·´¯)
|
||||
|
||||
This is the global layout that will be used to displayed most pages (less the error page)
|
||||
If you're creating your own template, remember there is no obligation to respect the current file flow of this template.
|
||||
This is different from the old LimeSurvey template engine, where you had to provide every one of the pstpl files.
|
||||
Here, you must have a file called main_layout.twig (called from SurveyRuntimeHelper::run() ).
|
||||
Other than that, you're free to organize your files and inclusions as you want.
|
||||
|
||||
|
||||
|
||||
(¯`·._.·(¯`·._.· Bootstrap ·._.·´¯)·._.·´¯)
|
||||
|
||||
LimeSurvey uses Bootstrap.
|
||||
See: https://getbootstrap.com
|
||||
|
||||
This template is an instance of Bootswatch Theme Flatly.
|
||||
See: https://bootswatch.com/
|
||||
|
||||
|
||||
|
||||
(¯`·._.·(¯`·._.· Twig Engine ·._.·´¯)·._.·´¯)
|
||||
|
||||
The template engine uses Twig.
|
||||
See: http://twig.sensiolabs.org/
|
||||
|
||||
The main variable is aSurveyInfo. It's an array containing the main information about the survey.
|
||||
aSurveyInfo also contains other needed arrays, such as aNavigator, or aQuestionGroups (which contain aQuestions), etc.
|
||||
|
||||
If you want to see what is available in aSurveyInfo, turn debug mode on in application/config.php, and copy the following line to the end of the <body> element below:
|
||||
{{ dump(aSurveyInfo) }}
|
||||
|
||||
To echo a variable, just insert : {{ variable }}
|
||||
To translate a string, just insert : {{gT( string )}}
|
||||
|
||||
NOTE: aSurveyInfo should be cleaned to remove the unnecessary data.
|
||||
|
||||
|
||||
(¯`·._.·(¯`·._.· Twig Engine: advanced ·._.·´¯)·._.·´¯)
|
||||
|
||||
For security reason, Twig is in a sandBox.
|
||||
About sandBox, see: http://twig.sensiolabs.org/doc/2.x/api.html#sandbox-extension
|
||||
|
||||
Available functions/Object Methods are defined in internal.php: components => twigRenderer
|
||||
Eg:
|
||||
Functions : 'include', 'dump', 'flatEllipsizeText', 'getLanguageData', 'array_flip', 'array_intersect_key', 'registerPublicCssFile', 'getAllQuestionClasses', 'getShowqnumcode', 'intval'
|
||||
|
||||
Methods :
|
||||
- CHtml::textfield() (and: form, link, emailField, beginForm, endForm, dropDownList,htmlButton)
|
||||
- Survey::getAllLanguages()
|
||||
- LSHttpRequest::getParam()
|
||||
|
||||
If you need to add simple functions or static methods, just add them to internal.php.
|
||||
If you need to add complex process, use application/core/LS_Twig_Extension.php (more help/comments there)
|
||||
|
||||
|
||||
NOTE: Feel free to ask for functions, variables, etc, that you feel are missing - https://bugs.limesurvey.org/my_view_page.php
|
||||
#}
|
||||
|
||||
{# THEME OVERRIDE of vanilla's layout_global.twig: identical, except the S1
|
||||
sanitization of the font-{{ }} body class and data-thememode below (see
|
||||
security_macros.twig). Keep in sync with the parent when vanilla changes. #}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ aSurveyInfo.htmllanguagecode }}" dir="{{ aSurveyInfo.dir }}" class="{{ aSurveyInfo.languagecode }} dir-{{ aSurveyInfo.dir }} {{ aSurveyInfo.class.html }}" {{ aSurveyInfo.attr.html }}>
|
||||
{% block head %}
|
||||
{# Headers, metadata, etc #}
|
||||
{{ include('./subviews/header/head.twig') }}
|
||||
{% endblock %}
|
||||
{# S1 (SECURITY_REVIEW_20261129.md): this layout is inherited from vanilla — the
|
||||
body class font-<font> and data-thememode are raw option values there; sanitize
|
||||
them at emission here (autoescape is OFF in LimeSurvey theme twig). #}
|
||||
{% import './subviews/security_macros.twig' as sec %}
|
||||
<body class=" {{ aSurveyInfo.class.body }} font-{{ sec.fontslug(aSurveyInfo.options.font|default('inter')) }} lang-{{aSurveyInfo.languagecode}} {{aSurveyInfo.surveyformat}} {% if( aSurveyInfo.options.brandlogo == "on") %}brand-logo{%endif%}" {{ aSurveyInfo.attr.body }} data-thememode="{{ sec.keyword(aSurveyInfo.options.thememode ? aSurveyInfo.options.thememode : 'light', 'light') }}">
|
||||
|
||||
{# Notice if emcache is on or off, used by tests. #}
|
||||
{% if aSurveyInfo.emcache %}
|
||||
<span style="display: none;" id="__emcache_debug" value="on"></span>
|
||||
{% else %}
|
||||
<span style="display: none;" id="__emcache_debug" value="off"></span>
|
||||
{% endif %}
|
||||
|
||||
{# This used for the pjax system #}
|
||||
{% block pjaxbegin %}
|
||||
<div id="beginScripts" class="script-container">
|
||||
<###begin###>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{# Ajaxify cannot handle an element that is a direct child of body, so => create simple wrapper section #}
|
||||
<div id="content">
|
||||
|
||||
<div id="{{ aSurveyInfo.id.dynamicreload }}">
|
||||
{% block body %}
|
||||
|
||||
{# Skip link for keyboard users: Only visible when focused #}
|
||||
<a href="#{{ aSurveyInfo.id.outerframe }}" class="skip-link visually-hidden-focusable">{{ gT("Skip to main content") }}</a>
|
||||
|
||||
{# Bootstrap Navigation Bar: the top menu #}
|
||||
{% block nav_bar %}
|
||||
{{ include('./subviews/header/nav_bar.twig') }}
|
||||
{% endblock %}
|
||||
|
||||
{# Top Container: in this template, it contains only #}
|
||||
{% block progress %}
|
||||
{{ include('./subviews/header/progress_bar.twig') }}
|
||||
{% endblock %}
|
||||
|
||||
<!-- Outer Frame Container -->
|
||||
{% block content %}
|
||||
{#
|
||||
Content depends on the action (survey, questions, register, assessments, submit, etc)
|
||||
Action are in ./subviews/content/
|
||||
#}
|
||||
{% set sViewContent = './subviews/content/' ~ aSurveyInfo.include_content ~ '.twig' %}
|
||||
{% include './subviews/content/outerframe.twig' with {'include_content': sViewContent } %}
|
||||
{% endblock %}
|
||||
|
||||
{# Bootstrap alert modal #}
|
||||
{{ include('./subviews/messages/bootstrap_alert_modal.twig') }}
|
||||
|
||||
{# Basic ThemeScript options #}
|
||||
{{ registerScript("BasicThemeScripts", "
|
||||
if(window.basicThemeScripts === undefined){
|
||||
window.basicThemeScripts = new ThemeScripts();
|
||||
}
|
||||
basicThemeScripts.initGlobal();
|
||||
", "POS_END") }}
|
||||
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{% block footer %}
|
||||
{{ include('./subviews/footer/footer.twig') }}
|
||||
{% endblock %}
|
||||
{% block pjaxend %}
|
||||
<div id="bottomScripts" class="script-container">
|
||||
<###end###>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block themescripts %}
|
||||
<script>
|
||||
window.basicThemeScripts.init();
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in a new issue