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-Positive STR100 inspection on local scope string in class method? #157

Open
martinpakosch opened this issue Sep 29, 2020 · 1 comment

Comments

@martinpakosch
Copy link

Hi,

today I updated to PyCharm 2020.2.2 with the latest compatible Python-Security plugin. Noticed a new inspection error I did not get with PyCharm 2020.1.3 and the corresponding plugin version (no idea which one).

However, I understand the background of this STR100 inspection. But in my case (see example) I assume it is a false-positive error. It shows up on the template.format() call where template is a local scope variable inside the class method. Maybe I do not understand the vulnerability completely, but how can this (constant) format string template be a risk/manipulated from outside?

Do I get something wrong with the vulnerability? Or is the inspection just unable to differentiate between scopes/variable context/definition (would be fine to know)? Or is it a bug?

class anything(object):
    # ...
    def report(self):
        template = "{C}{left:37}{N}  {EQ}  {C}{right:37}{N}"  # Using max. 80 chars.
        if False in self.equal.values():
            for key in self.datakeys:
                self.print(
                    template.format(
                        left=self.left.get(key, 'Unknown'),
                        right=self.right.get(key, 'Unknown'),
                        EQ='>>' if not self.equal.get(key) else '==',
                        C=fg.BLUE if not self.equal.get(key) else '',
                        N=fg.NONE if not self.equal.get(key) else '',
                    )
                ) 

Kind regards, Martin

@liiight
Copy link

liiight commented Feb 8, 2021

This occurs for any .format() it sees. I encounter the same issue with pendulum.DateTime.format as well.

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

2 participants