Skip to content

Commit

Permalink
isso: html.py: Prevent auto creation of invalid links in comments (#995)
Browse files Browse the repository at this point in the history
* isso: html.py: Prevent auto creation of invalid links

Fixes #557
  • Loading branch information
pkvach authored Mar 10, 2024
1 parent b587a74 commit 90aa041
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ Bugfixes & Improvements
- Changed website validation to allow domain names containing umlauts (`#951`_, schneidr)
- Improve Spanish translation (`#967`_, welpo)
- Make language code handling more robust (`#983`_, ix5)
- Prevent auto creation of invalid links in comments (`#995`_, pkvach)

.. _#951: https://github.com/posativ/isso/pull/951
.. _#967: https://github.com/posativ/isso/pull/967
.. _#983: https://github.com/posativ/isso/pull/983
.. _#995: https://github.com/isso-comments/isso/pull/995

0.13.1.dev0 (2023-02-05)
------------------------
Expand Down
2 changes: 2 additions & 0 deletions isso/tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def test_sanitizer(self):
['<a href="http://example.org/" rel="nofollow noopener">Ha</a>',
'<a rel="nofollow noopener" href="http://example.org/">Ha</a>']),
('<a href="sms:+1234567890">Ha</a>', '<a>Ha</a>'),
('ld.so', 'ld.so'),
('/usr/lib/x86_64-linux-gnu/libc/memcpy-preload.so', '/usr/lib/x86_64-linux-gnu/libc/memcpy-preload.so'),
('<p style="visibility: hidden;">Test</p>', '<p>Test</p>'),
('<script>alert("Onoe")</script>', 'alert("Onoe")')]

Expand Down
5 changes: 5 additions & 0 deletions isso/utils/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def sanitize(self, text):
clean_html = bleach.clean(text, tags=self.elements, attributes=self.attributes, strip=True)

def set_links(attrs, new=False):
# Linker can misinterpret text as a domain name and create new invalid links.
# To prevent this, we only allow existing links to be modified.
if new:
return None

href_key = (None, u'href')

if href_key not in attrs:
Expand Down

0 comments on commit 90aa041

Please sign in to comment.