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

Add 'with' variable instantiation detection to BadNameAttributeUseLinter #1

Open
mschwager opened this issue Jan 10, 2020 · 0 comments

Comments

@mschwager
Copy link
Contributor

I.e. Context managers.

The BadNameAttributeUseLinter helper currently supports normal variable instantiation of an object, e.g.

def func():
    foo = Foo()
    bar = foo.bad_function()  # Caught by BadNameAttributeUseLinter
    print(bar)

However, the helper does not support instantiation via the with statement, e.g.

def func():
    with Foo() as foo:
        bar = foo.bad_function()  # Not caught by BadNameAttributeUseLinter, yet
        print(bar)

This pattern is not as common as normal variable instantiation, however, it is worth detecting. One of our initial reasons for adding this helper was to catch insecure behavior in tarfile and zipfile, and both of these libraries have a common pattern of instantiation via the with statement.

Let's add context manager variable instantiation support to BadNameAttributeUseLinter.

@mschwager mschwager changed the title Code Issues 14 Pull requests 1 Actions Projects 0 Wiki Security Insights Add 'with' variable instantiation detection to BadNameAttributeUseLinter Add 'with' variable instantiation detection to BadNameAttributeUseLinter Jan 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant