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] Taint does not propagate through .push(...) for arrays #4509

Closed
1 of 3 tasks
minusworld opened this issue Jan 12, 2022 · 4 comments · Fixed by #5547
Closed
1 of 3 tasks

[JS] Taint does not propagate through .push(...) for arrays #4509

minusworld opened this issue Jan 12, 2022 · 4 comments · Fixed by #5547
Assignees
Labels
enhancement New feature or request feature:taint priority:low user:internal requested only by someone within Semgrep Inc.

Comments

@minusworld
Copy link
Member

Describe the bug
It appears that taint mode stops propagating data at .push(...) in array objects.

To Reproduce
This link has 3 examples. The third does not work, but should.
https://semgrep.dev/s/bXKp

What is the priority of the bug to you?

  • P0: blocking your adoption of Semgrep or workflow
  • P1: important to fix or quite annoying
  • P2: regular bug that should get fixed
@IagoAbal IagoAbal added enhancement New feature or request feature:taint priority:low user:internal requested only by someone within Semgrep Inc. labels Jan 12, 2022
@IagoAbal
Copy link
Collaborator

At present taint-mode only propagates taint through explicit assignments. In your example taint needs to be propagated through a side-effectful method call. We could perhaps asume that a (pressumably void-returning) method call like data.push(input) does taint data if input is tainted. We make similar assumptions in constant propagation already.

The current workaround would be:

pattern-sources:
  - patterns:
    - pattern-inside: |
        $ARRAY.push(<... req.query ...>)
        ...
    - pattern: $ARRAY

@IagoAbal
Copy link
Collaborator

Ooops, the workaround doesn't work in your example due to the limitations of ... in Semgrep. 😞

@minusworld
Copy link
Member Author

Is it a good idea to allow someone to specify side-effectful regions which still propagate taint? That might be an easy way to permit this behavior on a case-by-case basis.

Another random idea I just had is to "chain" taint rules together, like source -> array.push(...), then array becomes a source for a new taint rule.

@IagoAbal IagoAbal self-assigned this Jun 13, 2022
IagoAbal added a commit that referenced this issue Jun 15, 2022
Closes PA-1361
Closes #4509

test plan:
make test # added three tests
IagoAbal added a commit that referenced this issue Jun 15, 2022
Closes PA-1361
Closes #4509

test plan:
make test # added three tests
aryx pushed a commit that referenced this issue Jun 16, 2022
Closes PA-1361
Closes #4509

test plan:
make test # added three tests
@aryx
Copy link
Collaborator

aryx commented Jun 16, 2022

"We could perhaps asume that a (pressumably void-returning) method call like data.push(input) does taint data if input is tainted."
What if we did that instead of taint propagators? This is especially something we could do better in DeepSemgrep because we have more type information about the methods (but it's also easy to detect when something does not return anything because it's not used in an rvalue position.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature:taint priority:low user:internal requested only by someone within Semgrep Inc.
Development

Successfully merging a pull request may close this issue.

3 participants