Skip to content
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

JS: Added support for Array.prototype.[findLastIndex, findLast] ES2022 feature #18005

Merged
merged 12 commits into from
Nov 21, 2024

Conversation

Napalys
Copy link
Contributor

@Napalys Napalys commented Nov 18, 2024

Added support for ES2023 feature, Arrray.protype.findLastIndex, Arrray.protype. findLast.

DCA run shows that the run time stays approximately the same. Meta queries revealed new taint for Arrray.protype.find calls with lambda, which was expected.

@Napalys Napalys force-pushed the napalys/ES2022-find-functions branch from 04830fb to 8795d1a Compare November 18, 2024 13:51
@Napalys Napalys marked this pull request as ready for review November 18, 2024 15:03
@Napalys Napalys requested a review from a team as a code owner November 18, 2024 15:03
@Napalys Napalys force-pushed the napalys/ES2022-find-functions branch from 8795d1a to 04830fb Compare November 19, 2024 07:23
@Napalys Napalys force-pushed the napalys/ES2022-find-functions branch 2 times, most recently from b025fc6 to 0648392 Compare November 19, 2024 08:28
@Napalys Napalys force-pushed the napalys/ES2022-find-functions branch from 0648392 to 1b0f8aa Compare November 19, 2024 08:30
Comment on lines 125 to 129
{ // Test for findLastIndex function
const list = ["source"];
const element = list.findLastIndex((item) => sink(item)); // NOT OK -- Not caught, currently missing dataflow tracking.
const element = list.findLastIndex((item) => sink(item)); // NOT OK
sink(element); // OK
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a test like:

    const element = source.findLastIndex((item) => sink(item)); // NOT OK - only found with taint-tracking. 
    sink(element); // OK

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds test case: f1e95a8

Copy link
Contributor

@erik-krogh erik-krogh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small suggestions to look into.

Otherwise OK 👍

override predicate step(DataFlow::Node obj, DataFlow::Node element) {
exists(DataFlow::MethodCallNode call |
call.getMethodName() = ["findLast", "find", "findLastIndex"] and
obj = call.getReceiver().getALocalSource() and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
obj = call.getReceiver().getALocalSource() and
obj = call.getReceiver() and

I don't think you need .getALocalSource() here.
Try to see if the tests work with this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9dbf7d1 fixes.

@@ -492,7 +492,20 @@ private module ArrayLibraries {
exists(DataFlow::MethodCallNode call |
call.getMethodName() = ["findLast", "find", "findLastIndex"] and
prop = arrayLikeElement() and
obj = call.getReceiver() and
obj = call.getReceiver().getALocalSource() and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
obj = call.getReceiver().getALocalSource() and
obj = call.getReceiver() and

In the storeStep you definitely need .getALocalSource(), but I'm not sure you need it here?
See if this suggestion still passes the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

64c45de fixes.

@Napalys Napalys merged commit 82ca369 into github:main Nov 21, 2024
14 checks passed
@Napalys Napalys deleted the napalys/ES2022-find-functions branch November 21, 2024 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants