Skip to content

Commit

Permalink
Add HTML-5 "formaction" attribute to "defs.link_attrs" (GH-316)
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdHeat committed Mar 21, 2021
1 parent e986a9c commit 2d01a1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lxml/html/defs.py
Expand Up @@ -23,6 +23,8 @@
'usemap',
# Not standard:
'dynsrc', 'lowsrc',
# HTML5 formaction
'formaction'
])

# Not in the HTML 4 spec:
Expand Down
15 changes: 15 additions & 0 deletions src/lxml/html/tests/test_clean.py
Expand Up @@ -123,6 +123,21 @@ def test_sneaky_js_in_math_style(self):
b'<math><style>/* deleted */</style></math>',
lxml.html.tostring(clean_html(s)))

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()
Expand Down

0 comments on commit 2d01a1b

Please sign in to comment.