Skip to content

Commit e0a2117

Browse files
committed
Modify config of sanitize for OGP
1 parent ff88e59 commit e0a2117

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/common/text_sanitizer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ def allow_div_attributes(tag, name, value):
3535
return True
3636
if name == 'data-alis-iframely-url':
3737
p = urlparse(value)
38-
return p.netloc == 'twitter.com'
38+
is_url = len(p.scheme) > 0 and len(p.netloc) > 0
39+
is_clean = True if bleach.clean(value) == value else False
40+
return is_url and is_clean
3941
if name == 'contenteditable':
4042
if value == 'false':
4143
return True

tests/common/test_text_sanitizer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def test_sanitize_article_body(self):
6868
</div>
6969
<a href="http://example.com">link</a>
7070
<div data-alis-iframely-url="https://twitter.com/hoge">hoge</div>
71+
<div data-alis-iframely-url="https://example.com/hoge?x=1">hoge</div>
72+
<div data-alis-iframely-url="http://example.com/hoge?x=1%3Cdiv%3Ehoge%3C%2Fdiv%3E">hoge</div>
7173
'''.format(domain=os.environ['DOMAIN'])
7274

7375
result = TextSanitizer.sanitize_article_body(target_html)
@@ -143,7 +145,7 @@ def test_sanitize_article_body_with_div_unauthorized_url(self):
143145
target_html = '''
144146
<h2>sample h2</h2>
145147
<div class='hoge piyo' data='aaa' contenteditable='true'></div>
146-
<div data-alis-iframely-url="https://example.com/hoge">hoge</div>
148+
<div data-alis-iframely-url="https://example.com/hoge?<script>piyo</script>">hoge</div>
147149
'''
148150

149151
expected_html = '''

0 commit comments

Comments
 (0)