Skip to content

Commit a799094

Browse files
committed
Fixes #7788: Improve XSS mitigation in Markdown renderer
1 parent 2f064cd commit a799094

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

docs/release-notes/version-3.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* [#7766](https://github.com/netbox-community/netbox/issues/7766) - Add missing outer dimension columns to rack table
1818
* [#7780](https://github.com/netbox-community/netbox/issues/7780) - Preserve multi-line values during CSV file import
1919
* [#7783](https://github.com/netbox-community/netbox/issues/7783) - Fix indentation of locations under site view
20+
* [#7788](https://github.com/netbox-community/netbox/issues/7788) - Improve XSS mitigation in Markdown renderer
2021
* [#7791](https://github.com/netbox-community/netbox/issues/7791) - Enable sorting device bays table by installed device status
2122
* [#7802](https://github.com/netbox-community/netbox/issues/7802) - Differentiate ID and VID columns in VLANs table
2223

netbox/utilities/templatetags/helpers.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,19 @@ def render_markdown(value):
4040
"""
4141
Render text as Markdown
4242
"""
43+
schemes = '|'.join(settings.ALLOWED_URL_SCHEMES)
44+
4345
# Strip HTML tags
4446
value = strip_tags(value)
4547

4648
# Sanitize Markdown links
47-
schemes = '|'.join(settings.ALLOWED_URL_SCHEMES)
48-
pattern = fr'\[(.+)\]\((?!({schemes})).*:(.+)\)'
49+
pattern = fr'\[([^\]]+)\]\((?!({schemes})).*:(.+)\)'
4950
value = re.sub(pattern, '[\\1](\\3)', value, flags=re.IGNORECASE)
5051

52+
# Sanitize Markdown reference links
53+
pattern = fr'\[(.+)\]:\w?(?!({schemes})).*:(.+)'
54+
value = re.sub(pattern, '[\\1]: \\3', value, flags=re.IGNORECASE)
55+
5156
# Render Markdown
5257
html = markdown(value, extensions=['fenced_code', 'tables'])
5358

0 commit comments

Comments
 (0)