Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isso: html.py: Prevent auto creation of invalid links in comments #995

Merged
merged 3 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading