40 lines
1.4 KiB
Diff
40 lines
1.4 KiB
Diff
diff --git a/src/lxml/html/defs.py b/src/lxml/html/defs.py
|
|
index b21a113..e40c808 100644
|
|
--- a/src/lxml/html/defs.py
|
|
+++ b/src/lxml/html/defs.py
|
|
@@ -21,6 +21,8 @@ link_attrs = frozenset([
|
|
'usemap',
|
|
# Not standard:
|
|
'dynsrc', 'lowsrc',
|
|
+ # HTML5 formaction
|
|
+ 'formaction'
|
|
])
|
|
|
|
# Not in the HTML 4 spec:
|
|
diff --git a/src/lxml/html/tests/test_clean.py b/src/lxml/html/tests/test_clean.py
|
|
index a193d99..87b7220 100644
|
|
--- a/src/lxml/html/tests/test_clean.py
|
|
+++ b/src/lxml/html/tests/test_clean.py
|
|
@@ -68,6 +68,21 @@ class CleanerTest(unittest.TestCase):
|
|
s = lxml.html.fromstring('<invalid tag>child</another>')
|
|
self.assertEqual('child', clean_html(s).text_content())
|
|
|
|
+ def test_formaction_attribute_in_button_input(self):
|
|
+ # The formaction attribute overrides the form's action and should be
|
|
+ # treated as a malicious link attribute
|
|
+ html = ('<form id="test"><input type="submit" formaction="javascript:alert(1)"></form>'
|
|
+ '<button form="test" formaction="javascript:alert(1)">X</button>')
|
|
+ expected = ('<div><form id="test"><input type="submit" formaction=""></form>'
|
|
+ '<button form="test" formaction="">X</button></div>')
|
|
+ cleaner = Cleaner(
|
|
+ forms=False,
|
|
+ safe_attrs_only=False,
|
|
+ )
|
|
+ self.assertEqual(
|
|
+ expected,
|
|
+ cleaner.clean_html(html))
|
|
+
|
|
|
|
def test_suite():
|
|
suite = unittest.TestSuite()
|