Skip to content

Commit db139c5

Browse files
committed
Security: fix XSS and path traversal in uicore templatetags SACGF/variantgrid_private#3832
- escapejs on user.username in JS string context (menu_bar_main.html) - html.escape() on title attribute in severity_icon filter (ui_utils.py) - Validate page_id with whitelist regex in page_help tag (ui_help.py)
1 parent b0d4991 commit db139c5

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

uicore/templates/uicore/menus/menu_bar_main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{% menu_top 'variant_tags' app_name='variantopedia|variants|manual_variant_entry' title='Variants' %}
1515
{% menu_top 'annotation' app_name='annotation' title='Annotation' %}
1616
<a class="nav-link" target="_blank" href="{{ help_url }}">Help</a>
17-
<a id="suggestion" class="nav-link" data-toggle="tooltip" title="Suggestion / Bug Report" href="javascript:suggestionDialog('{{ user.username }}')"><i class="fas fa-bug mt-1"></i></a>
17+
<a id="suggestion" class="nav-link" data-toggle="tooltip" title="Suggestion / Bug Report" href="javascript:suggestionDialog('{{ user.username|escapejs }}')"><i class="fas fa-bug mt-1"></i></a>
1818
<!--
1919
<button type="button" style="color:#866" class="btn bg-transparent" data-toggle="modal" data-target="#vgReportModal"><i class="fas fa-bug mt-1"></i></button>
2020
-->

uicore/templatetags/ui_help.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import re
23
from typing import Optional
34

45
from django import template
@@ -34,6 +35,9 @@ def page_help(page_id: str = None, title=None, show_title=True, header_tag="h3")
3435

3536
help_url = settings.HELP_URL
3637
page_help_html = None
38+
if page_id and not re.fullmatch(r'[\w\-]+', page_id):
39+
report_message(f"page_help: invalid page_id {page_id!r}")
40+
page_id = None
3741
page_help_path = f"page_help/{page_id}.html"
3842
page_help_filename = finders.find(page_help_path)
3943
file_exists = False

uicore/templatetags/ui_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def severity_icon(severity: str, title: Optional[str] = None) -> str:
398398
title_html = ""
399399
if title:
400400
classes.append('hover-detail')
401-
title_html = f' title="{title}"'
401+
title_html = f' title="{escape(title)}"'
402402

403403
def severity_for(severity_part: str) -> Optional[list[str]]:
404404
match severity_part:

0 commit comments

Comments
 (0)