-
Notifications
You must be signed in to change notification settings - Fork 1.9k
JS: Update test suite to use post-processed inline expectations #18670
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
Conversation
6e464f3 to
3a86b71
Compare
3a86b71 to
684fefb
Compare
| @@ -1 +1 @@ | |||
| Comments/CommentedOutCode.ql | |||
| query: Comments/CommentedOutCode.ql | |||
Check warning
Code scanning / CodeQL
Query test without inline test expectations Warning test
| @@ -1 +1 @@ | |||
| Comments/TodoComments.ql | |||
| query: Comments/TodoComments.ql | |||
Check warning
Code scanning / CodeQL
Query test without inline test expectations Warning test
Check warning
Code scanning / CodeQL
Query test without inline test expectations Warning test
| @@ -1 +1 @@ | |||
| LanguageFeatures/ConditionalComments.ql | |||
| query: LanguageFeatures/ConditionalComments.ql | |||
Check warning
Code scanning / CodeQL
Query test without inline test expectations Warning test
Check warning
Code scanning / CodeQL
Query test without inline test expectations Warning test
| @@ -1 +1 @@ | |||
| Security/CWE-094/ExpressionInjection.ql | |||
| query: Security/CWE-094/ExpressionInjection.ql | |||
Check warning
Code scanning / CodeQL
Query test without inline test expectations Warning test
Check warning
Code scanning / CodeQL
Query test without inline test expectations Warning test
| @@ -1 +1 @@ | |||
| Security/CWE-312/ActionsArtifactLeak.ql | |||
| query: Security/CWE-312/ActionsArtifactLeak.ql | |||
Check warning
Code scanning / CodeQL
Query test without inline test expectations Warning test
| @@ -1 +1 @@ | |||
| Security/CWE-313/PasswordInConfigurationFile.ql | |||
| query: Security/CWE-313/PasswordInConfigurationFile.ql | |||
Check warning
Code scanning / CodeQL
Query test without inline test expectations Warning test
| @@ -1 +1 @@ | |||
| Security/CWE-862/EmptyPasswordInConfigurationFile.ql | |||
| query: Security/CWE-862/EmptyPasswordInConfigurationFile.ql | |||
Check warning
Code scanning / CodeQL
Query test without inline test expectations Warning test
Check warning
Code scanning / CodeQL
Query test without inline test expectations Warning test
| @@ -1 +1 @@ | |||
| LanguageFeatures/SyntaxError.ql | |||
| query: LanguageFeatures/SyntaxError.ql | |||
Check warning
Code scanning / CodeQL
Query test without inline test expectations Warning test
a456a5b to
77a27de
Compare
bc599d1 to
9df0bf6
Compare
Some OK-style comments had to be moved to the following line, shifting line numbers. In selected range also included the comments themselves. Lastly, the result sets were reordered by the CLI in some cases.
JSON does not support comments so we can't use inline expectations
The presence of a syntax error sometimes prevents us from parsing the inline comment correctly.
One of the diffs look confusing but:
Previously parameter {2,3} where flagged, now parameter {1,2} are flagged.
Note that for command injection, the SystemCommandExecution is flagged
despite the test file claiming otherwise.
This adds Alert annotations for alerts that seem intentional by the test but has not been annotated with 'NOT OK', or the comment was in the wrong place. In a few cases I included 'Source' expectations to make it easier to see what happened. Other 'Source' expectations will be added in bulk a later commit.
These are listed in a function called 'good' but it's difficult to say in isolation whether they should be flagged or not. Accepting the changes as they seem reasonable.
The history of updates to this test got messed up so just squashing into one commit. Some possible regressions have been accepted, but the query is strangely opinionated so it's just hard to say what it ought to flag.
9df0bf6 to
2a194a5
Compare
Napalys
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.
Amazing work! 🚀 You're officially #1 on my list for the biggest pull request I've ever reviewed! 😆
| @@ -1,2 +1,2 @@ | |||
| // OK | |||
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.
This stands outs for me as an odd case. Do we need to remove this?
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.
Don't see a reason to keep it
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.
It seemed unclear whether it was meant to be a separate test case with just // OK or if it was part of the next line, indicating that the next line is // OK. That's why I wasn't sure if it should be removed or not 😄
| // not OK | ||
| <a href="http://semmle.com" href={someValue()}>Semmle</a>; | ||
| <a href="http://semmle.com" href={someValue()}>Semmle</a>; // $ Alert | ||
|
|
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.
Sorry, I couldn't help but notice the extra line 😄
| var o = { rel: "noopener noreferrer "}; | ||
|
|
||
| // OK | ||
|
|
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.
This file now has many extra lines due to the replacements of // OK with /n. 🙈
| @@ -1,2 +1,2 @@ | |||
| // OK | |||
|
|
|||
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.
File starting with new line 🙈
| g = 23; // $ Alert | ||
|
|
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.
Additional new line in //NO OK
javascript/ql/test/query-tests/Security/CWE-079/ExceptionXss/exception-xss.js
Outdated
Show resolved
Hide resolved
javascript/ql/test/query-tests/Security/CWE-116/IncompleteSanitization/UnsafeHtmlExpansion.js
Outdated
Show resolved
Hide resolved
| libxmljs.parseXml(req.param("some-xml"), { noent: true }); // $ Alert | ||
| libxmljs.parseXml(req.param("some-xml"), { noent: true }); // $ Alert // $ Alert - unguarded entity expansion | ||
| }); | ||
|
|
||
| express().post('/some/path', function (req, res) { | ||
| // NOT OK: unguarded entity expansion | ||
| libxmljs.parseXml(req.param("some-xml"), { noent: true }); // $ Alert | ||
| libxmljs.parseXml(req.param("some-xml"), { noent: true }); // $ Alert // $ Alert - unguarded entity expansion | ||
|
|
||
| // NOT OK: unguarded entity expansion | ||
| libxmljs.parseXmlString(req.param("some-xml"), { noent: true }) // $ Alert | ||
| // NOT OK: unguarded entity expansion | ||
| libxmljs.parseXmlString(req.files.products.data.toString('utf8'), { noent: true })// $ Alert | ||
| libxmljs.parseXmlString(req.param("some-xml"), { noent: true }) // $ Alert // $ Alert - unguarded entity expansion | ||
| libxmljs.parseXmlString(req.files.products.data.toString('utf8'), { noent: true })// $ Alert // $ Alert - unguarded entity expansion |
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.
This looks suspicious, shouldn't it be a single // $ Alert instead of // $ Alert // $ Alert?
javascript/ql/test/query-tests/Security/CWE-730/server-crash.js
Outdated
Show resolved
Hide resolved
javascript/ql/test/query-tests/Security/CWE-400/ReDoS/polynomial-redos.js
Outdated
Show resolved
Hide resolved
…t/uselesscat.js Co-authored-by: Napalys Klicius <napalys@github.com>
…t/uselesscat.js Co-authored-by: Napalys Klicius <napalys@github.com>
…t.js Co-authored-by: Napalys Klicius <napalys@github.com>
…xception-xss.js Co-authored-by: Napalys Klicius <napalys@github.com>
…tization/UnsafeHtmlExpansion.js Co-authored-by: Napalys Klicius <napalys@github.com>
Co-authored-by: Napalys Klicius <napalys@github.com>
…al-redos.js Co-authored-by: Napalys Klicius <napalys@github.com>
|
LGTM 👍 But you got some merge-conflicts, again. |
'Accept incoming changes' in vscode somehow deleted this line.
JS: Update test suite to use post-processed inline expectations
Updates all of JavaScript's query tests to use post-processed inline expectations except in a few cases where it's not possible. Overall 233 query tests consisting of 712 JavaScript files have been updated.
Inline expectations are now written as
// $ Alertinstead of// NOT OK. Our oldNOT OK-style comments were not automatically verified for consistency except in a handful of cases, so some discrepancies have crept in over the years. This PR reviews and fixes up these discrepancies and of course prevents them from being introduced in the future.Only query tests have been updated. Library tests have to be implemented a bit differently; that's for another PR.
This PR has the following overall structure:
.qlreffiles and run the test to get a list of discrepancies.NOT OKcomment, but where it's farily easy too see from the test that it was intended to be flagged. There are many of these and I found it's probably easiest to spot check some results from a single commit than having 100+ commits with "trivial" changes.In a few cases the underlying bugs were simple enough that I went ahead and fixed them on the spot.