-
Notifications
You must be signed in to change notification settings - Fork 38
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
feat: Introduce a separate parsing_method rule #244
base: main
Are you sure you want to change the base?
Conversation
ceb2644
to
5d1d053
Compare
Right. This would help with #81, which is a long-standing issue for some users. |
Is the purpose of this to add validation of Don't forget to also add support for |
@Rob--W That is already covered by the 'method' rule, see
|
5ee194b
to
b0ed868
Compare
@mozfreddyb I opened up this PR for a review pass on your side (in the meantime I applied the fixes for the typos in the markdown file, fixed the recommended config, and the README.md file which had a syntax error, and added a base integration test executed by the github workflow, which would have caught the issue with the typo in the severity level of the new rule in the previous version of this PR). |
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.
Looks great. Just a few things missing :)
tests/rules/parsing_method.js
Outdated
errors: [ | ||
{ | ||
message: | ||
/Unsafe call to DOMParser.parseFromString for argument 0/, |
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.
I wonder if it could be cool to call them "Potentially unsafe call" or even more concrete "Parsing can be unsafe when....? 🤔
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.
That feels like a good point to be too, let me take a look to what additional change may be needed in this PR if we would like to use slightly different message for the separate parsing_method rule.
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.
@mozfreddyb I have included in afe2df6 one possible approach to customize the message (for now I went for the simpler "Potentially unsafe call..." one, but if the approach looks reasonable we can tweak the message further).
I have also changed the objectMatches for the DOMParser parseFromString method to 'parser' for now.
I was actually tempted to go even for just 'parse' or 'pars' (so that it would also match other variations, like 'htmlParsing' or 'parseHTML' or 'parseUtils'), wdyt?
… new rule tests to fix wrong example usage of the DOMParser.parseFromString
ba0ea56
to
98508bd
Compare
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.
Almost ready to go :) Thank you, Luca!
valid: [ | ||
{ | ||
code: "var doc = parser.parseFromString('static string');", | ||
}, | ||
{ | ||
code: "var doc = Document.parseHTMLUnsafe('static string');", | ||
}, | ||
], |
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.
What would a sanitized version of this look like?
parseHTMLUnsafe(sanitize(badness))
or would sanitizeDocument(parseHTMLUnsafe(badness))
be more likely? I am leaning to (1) and would like to suggest to add a simplified test case here
The _parsing_method_ rule in _eslint-plugin-no-unsanitized_ performs basic security | ||
checks for function calls that parse strings into new Document or DocumentFragment | ||
instances. The idea of these checks is to allow developers to opt-in/opt-out of detecting | ||
use of these methods, separately from the `method` rule which is reporting violation | ||
as errors by default. |
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.
The _parsing_method_ rule in _eslint-plugin-no-unsanitized_ performs basic security | |
checks for function calls that parse strings into new Document or DocumentFragment | |
instances. The idea of these checks is to allow developers to opt-in/opt-out of detecting | |
use of these methods, separately from the `method` rule which is reporting violation | |
as errors by default. | |
The _parsing_method_ rule in _eslint-plugin-no-unsanitized_ performs basic security | |
checks for function calls that parse strings into new Document or DocumentFragment | |
instances. It is close to impossible to automatically check whether the resulting | |
Document is actually used insecurely, so this offers a control at the parse step. | |
Therefore, these checks allow developers to opt-in/opt-out of detecting | |
use of these methods, separately from the `method` and `property` rule which is | |
reporting violation as errors by default. |
This PR move shared bits of the
method
rule into abase_method.js
module and then reuse the helper function exported by that method to create two separatemethod
andparsing_method
rules.The purpose of splitting the
method
rule into two separate rules is to report violations detected by theparsing_method
rule as warnings instead of errors by default, and allow developers to opt-in/opt-out on parsing methods violations separately from themethod
rule.