Skip to content

Commit a581156

Browse files
smcmurtryCopilot
andauthored
Add allowed url characters to a safelist (#417)
* add allowed url characters to a safelist * make werkzeug version the same as admin and api Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * go with a simpler approach --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 6c1438e commit a581156

5 files changed

Lines changed: 18 additions & 9 deletions

File tree

.github/actions/waffles/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ docopt==0.6.2
22
Flask==2.3.3
33
markupsafe==2.1.5
44
setuptools==78.1.1 # required for distutils in Python 3.12
5-
git+https://github.com/cds-snc/notifier-utils.git@53.2.27#egg=notifications-utils
5+
git+https://github.com/cds-snc/notifier-utils.git@53.2.29#egg=notifications-utils

notifications_utils/formatters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ def block_quote(self, text):
496496
).format(text)
497497

498498
def link(self, link, title, content):
499-
safe_href = html.escape(sanitise_link_url(link), quote=True)
499+
safe_href = sanitise_link_url(link).replace('"', "%22")
500500
title_attr = ' title="{}"'.format(html.escape(title, quote=True)) if title else ""
501501
return ('<a style="{}" href="{}"{}>{}</a>').format(
502502
LINK_STYLE,

poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "notifications-utils"
3-
version = "53.2.28"
3+
version = "53.2.29"
44
description = "Shared python code for Notification - Provides logging utils etc."
55
authors = ["Canadian Digital Service"]
66
license = "MIT license"
@@ -39,7 +39,7 @@ PyYAML = "6.0.3"
3939
requests = "2.32.3"
4040
smartypants = "2.0.2"
4141
statsd = "3.3.0"
42-
werkzeug = "3.1.8"
42+
werkzeug = "3.1.6"
4343

4444
[tool.poetry.group.test.dependencies]
4545
beautifulsoup4 = "^4.12.3"

tests/test_formatters.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ def test_link_with_title(markdown_function, expected):
742742
# href with a stray double-quote must not break out of the attribute
743743
(
744744
'[hi](https://example.com"onmouseover="alert)',
745-
"https://example.com&quot;onmouseover=&quot;alert",
745+
"https://example.com%22onmouseover=%22alert",
746746
"",
747747
),
748748
),
@@ -777,9 +777,18 @@ def test_email_link_blocks_unsafe_url_schemes(scheme_url):
777777
(
778778
"http://example.com",
779779
"https://example.com/path?q=1",
780+
"https://example.com/path?a=1&b=2", # & must not become &amp;
780781
"mailto:hi@example.com",
781782
"tel:+15551234567",
782783
"example.com/relative", # no scheme — passed through
784+
"https://example.com/search?q=hello%20world",
785+
"https://example.com/search?q=a+b",
786+
"https://example.com/?q=one&two=three",
787+
"https://example.com/page#section-1",
788+
"https://example.com/café",
789+
"https://example.com/a%2Fb",
790+
"https://example.com/?next=%2Fadmin%3Fdebug%3D1",
791+
"https://example.com/~user/path",
783792
),
784793
)
785794
def test_email_link_allows_safe_url_schemes(safe_url):

0 commit comments

Comments
 (0)