-
Notifications
You must be signed in to change notification settings - Fork 1
fix: add HTML escaping to sanitize=False computed Html fields #140
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
18d1a78
fix(spp_audit,spp_change_request_v2): add HTML escaping to computed H…
gonzalesedwin1123 1599361
test(spp_audit,spp_change_request_v2): add HTML escaping coverage tests
gonzalesedwin1123 4af35e8
fix(spp_change_request_v2): escape remaining computed Html fields
gonzalesedwin1123 6631cff
chore(spp_audit,spp_change_request_v2): bump versions and add changelog
gonzalesedwin1123 aeb197f
chore: regenerate static/description/index.html files
gonzalesedwin1123 7ee9652
test(spp_audit,spp_change_request_v2): assert escaped entities in XSS…
gonzalesedwin1123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| from . import test_audit_backend | ||
| from . import test_html_escaping | ||
| from . import test_spp_audit_rule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| from odoo.tests.common import TransactionCase | ||
|
|
||
|
|
||
| class TestAuditHtmlEscaping(TransactionCase): | ||
| """Tests that audit log HTML fields properly escape dynamic values.""" | ||
|
|
||
| @classmethod | ||
| def setUpClass(cls): | ||
| super().setUpClass() | ||
| cls.model_partner = cls.env["ir.model"].search([("model", "=", "res.partner")], limit=1) | ||
| cls.audit_rule = cls.env["spp.audit.rule"].search([("model_id", "=", cls.model_partner.id)], limit=1) | ||
| if not cls.audit_rule: | ||
| cls.audit_rule = cls.env["spp.audit.rule"].create( | ||
| { | ||
| "name": "Test Rule", | ||
| "model_id": cls.model_partner.id, | ||
| "is_log_create": True, | ||
| "is_log_write": True, | ||
| "is_log_unlink": False, | ||
| } | ||
| ) | ||
|
|
||
| def _create_audit_log(self, old_vals, new_vals): | ||
| """Create an audit log record with given old/new values.""" | ||
| data = repr({"old": old_vals, "new": new_vals}) | ||
| return self.env["spp.audit.log"].create( | ||
| { | ||
| "audit_rule_id": self.audit_rule.id, | ||
| "user_id": self.env.uid, | ||
| "model_id": self.model_partner.id, | ||
| "res_id": 1, | ||
| "method": "write", | ||
| "data": data, | ||
| } | ||
| ) | ||
|
|
||
| def test_data_html_escapes_script_tags(self): | ||
| """Verify data_html escapes <script> in field values.""" | ||
| xss_payload = '<script>alert("xss")</script>' | ||
| log = self._create_audit_log( | ||
| old_vals={"name": "Safe Name"}, | ||
| new_vals={"name": xss_payload}, | ||
| ) | ||
| html = log.data_html | ||
| self.assertNotIn("<script>", html) | ||
| self.assertIn("<script>", html) | ||
|
|
||
| def test_data_html_escapes_html_entities(self): | ||
| """Verify data_html escapes angle brackets and ampersands.""" | ||
| log = self._create_audit_log( | ||
| old_vals={"name": "Before <b>bold</b>"}, | ||
| new_vals={"name": "After <img src=x onerror=alert(1)>"}, | ||
| ) | ||
| html = log.data_html | ||
| self.assertNotIn("<img ", html) | ||
| self.assertIn("<img ", html) | ||
| self.assertNotIn("<b>bold</b>", html) | ||
| self.assertIn("<b>bold</b>", html) | ||
|
|
||
| def test_data_html_renders_table_structure(self): | ||
| """Verify data_html still produces valid table structure.""" | ||
| log = self._create_audit_log( | ||
| old_vals={"name": "Old"}, | ||
| new_vals={"name": "New"}, | ||
| ) | ||
| html = log.data_html | ||
| self.assertIn("<table", html) | ||
| self.assertIn("<thead>", html) | ||
| self.assertIn("<tbody>", html) | ||
| self.assertIn("<td>", html) | ||
|
|
||
| def test_parent_data_html_escapes_script_tags(self): | ||
| """Verify parent_data_html escapes <script> in field values.""" | ||
| xss_payload = '<script>alert("xss")</script>' | ||
| parent_model = self.env["ir.model"].search([("model", "=", "res.partner")], limit=1) | ||
| log = self.env["spp.audit.log"].create( | ||
| { | ||
| "audit_rule_id": self.audit_rule.id, | ||
| "user_id": self.env.uid, | ||
| "model_id": self.model_partner.id, | ||
| "res_id": 1, | ||
| "method": "write", | ||
| "data": repr({"old": {"name": "Safe"}, "new": {"name": xss_payload}}), | ||
| "parent_model_id": parent_model.id, | ||
| "parent_res_ids_str": "1", | ||
| } | ||
| ) | ||
| html = log.parent_data_html | ||
| self.assertNotIn("<script>", html) | ||
| self.assertIn("<script>", html) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.