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

False Negative: Patterns are unable to match imports when alias is redeclared #10110

Open
1 of 3 tasks
1nv8rzim opened this issue Apr 16, 2024 · 0 comments
Open
1 of 3 tasks
Labels
bug Something isn't working priority:medium python Pull requests that update Python code

Comments

@1nv8rzim
Copy link

1nv8rzim commented Apr 16, 2024

Describe the bug
When attempting to match a function call from an imported package; if the name of the import is aliased to an existing symbol, rules are unable match it.

As an example, I will be using os.system as the pattern I want to match; however, any combination of [module].[function](...) work with my example.

A pattern like os.system(...) is able to match the following:

import os as a
a.system("ls")

Instead if the variable a is already declared, it is unable to match the pattern:

a = None
import os as a
a.system("ls")

Likewise, if you try and build more advanced pattern (like the below) to try and detect cases like the above, the pattern is still not able to match:

$ALIAS = ...
...
import os as $ALIAS
...
$ALIAS.system(...)

To Reproduce
Here is an example of using os.system() in python and rules I feel like should match the example I provided:
https://semgrep.dev/playground/s/5rzLj

Expected behavior
Redeclaration of a variable should not ruin patterns.

os.system(...) should be able to match both:

import os as a
a.system("ls")

and

a = None
import os as a
a.system("ls")

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

Environment
I have tested cli and semgrep.dev which both have this issue.

Use case
Properly match imported functions when an alias to their import has already been used.

@ievans ievans added bug Something isn't working python Pull requests that update Python code priority:medium labels Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority:medium python Pull requests that update Python code
Development

No branches or pull requests

2 participants