codeant-ai-for-open-source[bot] commented on code in PR #43389:
URL: https://github.com/apache/superset/pull/43389#discussion_r3832417951
##########
tests/unit_tests/utils/test_core.py:
##########
@@ -1942,13 +1942,28 @@ def test_sanitize_svg_content_safe():
def test_sanitize_svg_content_removes_scripts():
- """Test that nh3 removes dangerous script content."""
+ """Test that dangerous script content is removed."""
malicious_svg = '<svg><script>alert("xss")</script><rect/></svg>'
result = sanitize_svg_content(malicious_svg)
assert "script" not in result.lower()
assert "alert" not in result
+def test_sanitize_svg_content_removes_script_with_attributes_on_closer():
+ """A closing </script foo> tag is still a valid closer to browsers."""
+ malicious_svg = "<svg><script>fetch('/api/v1/me/')</script foo></svg>"
+ result = sanitize_svg_content(malicious_svg)
+ assert "script" not in result.lower()
+ assert "fetch" not in result
+
+
+def test_sanitize_svg_content_removes_unterminated_script():
+ """An unterminated <script> opener with no closing tag is still
stripped."""
+ malicious_svg = "<svg><script>alert('xss')"
+ result = sanitize_svg_content(malicious_svg)
+ assert "script" not in result.lower()
Review Comment:
✅ **Customized review instruction saved!**
**Instruction:**
> For SVG sanitizer tests, do not require removal of script payload text
when stripping the tags leaves the payload as inert plain text; verify that the
executable markup is removed instead.
**Applied to:**
- `**/test/**`
- `**/tests/**`
- `**/*test*.py`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI
Settings](https://app.codeant.ai/org/settings/learnings)*
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]