-
Notifications
You must be signed in to change notification settings - Fork 0
Add DOMPurify to address XSS issues; closes #420 #3
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
base: base-sha/e1a3fa6b6cbc4536d5519f2aa347e03178ccb050
Are you sure you want to change the base?
Conversation
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
|
This is a benchmark review for experiment This pull request was cloned from Experiment configurationreview_config:
# User configuration for the review
# - benchmark - use the user config from the benchmark reviews
# - <value> - use the value directly
user_config:
enable_ai_review: true
enable_rule_comments: false
enable_complexity_comments: benchmark
enable_docstring_comments: benchmark
enable_security_comments: benchmark
enable_tests_comments: benchmark
enable_comment_suggestions: benchmark
enable_approvals: true
ai_review_config:
# The model responses to use for the experiment
# - benchmark - use the model responses from the benchmark reviews
# - llm - call the language model to generate responses
model_responses:
comments_model: benchmark
comment_validation_model: benchmark
comment_suggestion_model: benchmark
complexity_model: benchmark
docstrings_model: benchmark
security_model: benchmark
tests_model: benchmark
# The pull request dataset to run the experiment on
pull_request_dataset:
- https://github.com/LunaPurpleSunshine/ipget/pull/194
- https://github.com/W-zrd/unishare_mobile/pull/6
- https://github.com/nbhirud/nbhirud.github.io/pull/5
- https://github.com/LunaPurpleSunshine/ipget/pull/196
- https://github.com/aleph23/Composer/pull/31
- https://github.com/Amm1rr/WebAI-to-API/pull/31
- https://github.com/erxes/erxes/pull/5152
- https://github.com/EduardSchwarzkopf/pecuny/pull/128
- https://github.com/MKiperszmid/HabitsAppCourse/pull/3
- https://github.com/gdsfactory/kfactory/pull/298
- https://github.com/zen-audio-player/zen-audio-player.github.io/pull/431
- https://github.com/nbhirud/nbhirud.github.io/pull/3
- https://github.com/osism/python-osism/pull/869
- https://github.com/W-zrd/unishare_mobile/pull/7
- https://github.com/shreejitverma/MScFE690-Capstone/pull/5
- https://github.com/CPUT-DEVS/devpost-hackathon/pull/28
- https://github.com/Idrinth/api-bench/pull/852
- https://github.com/gdsfactory/gdsfactory/pull/2694
- https://github.com/kloudlite/web/pull/195
- https://github.com/shreejitverma/MScFE690-Capstone/pull/4
- https://github.com/gdsfactory/kfactory/pull/300
- https://github.com/ShiroePL/EasternTalesShelf/pull/45
- https://github.com/Idrinth/api-bench/pull/855
- https://github.com/shreejitverma/MScFE690-Capstone/pull/6
- https://github.com/aleph23/Composer/pull/32
- https://github.com/nbhirud/nbhirud.github.io/pull/6
- https://github.com/jackdewinter/pymarkdown/pull/1061
- https://github.com/Idrinth/api-bench/pull/848
- https://github.com/erxes/erxes/pull/5153
- https://github.com/leaver2000/nzthermo/pull/5
- https://github.com/Idrinth/api-bench/pull/849
- https://github.com/usama-maxenius/image-editor/pull/71
- https://github.com/albumentations-team/albumentations/pull/1679
- https://github.com/shreejitverma/MScFE690-Capstone/pull/7
- https://github.com/LunaPurpleSunshine/ipget/pull/195
- https://github.com/avelino/awesome-go/pull/5280
- https://github.com/nbhirud/system_update/pull/17
- https://github.com/EduardSchwarzkopf/pecuny/pull/129
- https://github.com/UCL/dxss/pull/63
- https://github.com/nbhirud/system_update/pull/18
- https://github.com/jackdewinter/pymarkdown/pull/1060
- https://github.com/ShiroePL/EasternTalesShelf/pull/44
- https://github.com/RogerSelwyn/mqtt_discoverystream_ha/pull/11
- https://github.com/strawberry-graphql/strawberry/pull/3467
- https://github.com/CPUT-DEVS/devpost-hackathon/pull/29
- https://github.com/dciborow/action-pylint/pull/14
- https://github.com/ElectronicBabylonianLiterature/ebl-api/pull/546
- https://github.com/leaver2000/nzthermo/pull/4
- https://github.com/nbhirud/nbhirud.github.io/pull/4
- https://github.com/strawberry-graphql/strawberry/pull/3469
review_comment_labels:
- label: correct
question: Is this comment correct?
- label: helpful
question: Is this comment helpful?
- label: comment-type
question: Is the comment type correct?
- label: comment-area
question: Is the comment area correct?
- label: llm-test
question: Should this comment become an LLM test?
# Benchmark reviews generated by running
# python -m scripts.experiment benchmark <experiment_name>
benchmark_reviews: []
|
SourceryAI
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @sourcery-ai-experiments-bot - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟢 Security: all looks good
- 🟡 Testing: 6 issues found
- 🟢 Complexity: all looks good
- 🟢 Docstrings: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
| const { | ||
| entries, | ||
| setPrototypeOf, | ||
| isFrozen, | ||
| getPrototypeOf, | ||
| getOwnPropertyDescriptor, | ||
| } = Object; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (code_refinement): Consider destructuring directly in the import statement for clarity.
Destructuring directly in the import statement can make the code cleaner and more readable by reducing the need for additional lines to declare variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment helpful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the comment type correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the comment area correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this comment become an LLM test?
| }; | ||
| return DOMPurify; | ||
| } | ||
| var purify = createDOMPurify(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (code_refinement): Consider using 'const' for declaring 'purify' if it's not reassigned.
| var purify = createDOMPurify(); | |
| const purify = createDOMPurify(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment helpful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the comment type correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the comment area correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this comment become an LLM test?
| it("should load DOMPurify and sanitize", async function() { | ||
| const page = await browser.newPage(); | ||
| await page.goto(indexHTMLURL); | ||
|
|
||
| const dp = await page.evaluate(() => { | ||
| return Object.keys(window).includes("DOMPurify"); | ||
| }); | ||
| assert.ok(dp, "DOMPurify should be loaded on the page."); | ||
|
|
||
| const sanitizedOutput = await page.evaluate(() => { | ||
| const dirty = "<img src=\"x\" onerror=\"alert(1)\">"; | ||
| return window.DOMPurify.sanitize(dirty); | ||
| }); | ||
| assert.strictEqual(sanitizedOutput, "<img src=\"x\">", "DOMPurify should sanitize malicious scripts correctly."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Consider adding tests for different types of XSS payloads
It's great to see tests for basic XSS protection. However, consider adding more diverse test cases covering different types of XSS payloads, such as those involving script tags, different event handlers, and other contexts like style tags or URL attributes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment helpful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the comment type correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the comment area correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this comment become an LLM test?
| it("should load DOMPurify and sanitize", async function() { | ||
| const page = await browser.newPage(); | ||
| await page.goto(indexHTMLURL); | ||
|
|
||
| const dp = await page.evaluate(() => { | ||
| return Object.keys(window).includes("DOMPurify"); | ||
| }); | ||
| assert.ok(dp, "DOMPurify should be loaded on the page."); | ||
|
|
||
| const sanitizedOutput = await page.evaluate(() => { | ||
| const dirty = "<img src=\"x\" onerror=\"alert(1)\">"; | ||
| return window.DOMPurify.sanitize(dirty); | ||
| }); | ||
| assert.strictEqual(sanitizedOutput, "<img src=\"x\">", "DOMPurify should sanitize malicious scripts correctly."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Ensure test isolation and independence
Currently, the test for DOMPurify loading and sanitization is combined into one. Consider splitting this into two separate tests: one for loading DOMPurify and another for its sanitization functionality. This enhances test clarity and isolation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment helpful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the comment type correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the comment area correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this comment become an LLM test?
| @@ -0,0 +1,363 @@ | |||
| import { freeze } from './utils.js'; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Consider adding tests for attribute sanitization
It would be beneficial to add unit tests to verify that the attribute sanitization works as expected, especially for edge cases and potential security vulnerabilities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment helpful?
| @@ -0,0 +1,280 @@ | |||
| import { freeze } from './utils.js'; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Add tests for tag sanitization
Ensure to include tests that validate the correct sanitization of HTML, SVG, and MathML tags, covering both allowed and disallowed tags.
| @@ -0,0 +1,17 @@ | |||
| import { seal } from './utils.js'; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Add tests for regular expression functionality
Regular expressions are used to detect patterns that need sanitization. Tests should verify that these patterns are correctly identified and handled.
| @@ -0,0 +1,226 @@ | |||
| const { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Include tests for utility functions
Utility functions such as 'freeze', 'unapply', and 'clone' are critical for the library's functionality. Tests should be added to ensure they perform as expected under various conditions.
Closes zen-audio-player#420