Skip to content

Commit

Permalink
CVE-2017-1002152: Sanitize Bugzilla titles in rendered HTML.
Browse files Browse the repository at this point in the history
fixes #1740

Signed-off-by: Randy Barlow <[email protected]>
  • Loading branch information
bowlofeggs committed Aug 15, 2017
1 parent fb679ea commit 2a3b06b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
5 changes: 3 additions & 2 deletions bodhi/server/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,9 @@ def bug_link(context, bug, short=False):
link = "<a target='_blank' href='%s'>%s</a>" % (url, display)
if not short:
if bug.title:
# We're good...
link = link + " " + bug.title
# We're good, but we do need to clean the bug title in case it contains malicious
# tags. See CVE-2017-1002152: https://github.com/fedora-infra/bodhi/issues/1740
link = link + " " + bleach.clean(bug.title, tags=[], attributes=[])
else:
# Otherwise, the backend is async grabbing the title from rhbz, so
link = link + " <img class='spinner' src='static/img/spinner.gif'>"
Expand Down
32 changes: 32 additions & 0 deletions bodhi/tests/server/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,38 @@ def test_short_false_with_title(self):
("<a target='_blank' href='https://bugzilla.redhat.com/show_bug.cgi?id=1234567'>"
"#1234567</a> Lucky bug number"))

def test_short_false_with_title_sanitizes_safe_tags(self):
"""
Test that a call to bug_link() with short=False on a Bug that has a title sanitizes even
safe tags because really they should be rendered human readable.
"""
bug = mock.MagicMock()
bug.bug_id = 1234567
bug.title = 'Check <b>this</b> out'

link = util.bug_link(None, bug)

self.assertEqual(
link,
("<a target='_blank' href='https://bugzilla.redhat.com/show_bug.cgi?id=1234567'>"
"#1234567</a> Check &lt;b&gt;this&lt;/b&gt; out"))

def test_short_false_with_title_sanitizes_unsafe_tags(self):
"""
Test that a call to bug_link() with short=False on a Bug that has a title sanitizes unsafe
tags.
"""
bug = mock.MagicMock()
bug.bug_id = 1473091
bug.title = '<disk> <driver name="..."> should be optional'

link = util.bug_link(None, bug)

self.assertEqual(
link,
("<a target='_blank' href='https://bugzilla.redhat.com/show_bug.cgi?id=1473091'>"
"#1473091</a> &lt;disk&gt; &lt;driver name=\"...\"&gt; should be optional"))

def test_short_false_without_title(self):
"""Test a call to bug_link() with short=False on a Bug that has no title."""
bug = mock.MagicMock()
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
# The short X.Y version.
version = '2.9'
# The full version, including alpha/beta/rc tags.
release = '2.9.0'
release = '2.9.1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
12 changes: 12 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
Release notes
=============

2.9.1
-----

2.9.1 is a security release for
`CVE-2017-1002152 <https://github.com/fedora-infra/bodhi/issues/1740>`_.

Release contributors
^^^^^^^^^^^^^^^^^^^^

Thanks to Marcel for reporting the issue. Randy Barlow wrote the fix.


2.9.0
-----

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_requirements(requirements_file='requirements.txt'):

here = os.path.abspath(os.path.dirname(__file__))
README = open(os.path.join(here, 'README.rst')).read()
VERSION = '2.9.0'
VERSION = '2.9.1'
# Possible options are at https://pypi.python.org/pypi?%3Aaction=list_classifiers
CLASSIFIERS = [
'Development Status :: 5 - Production/Stable',
Expand Down

0 comments on commit 2a3b06b

Please sign in to comment.