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

Add formaction attribute to defs.link_attrs #316

Merged
merged 2 commits into from Mar 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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