-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Question/Request: Should S105
, S106
, S107
(Insecure hardcoded password) apply to stubs?
#15206
Comments
I think I'd prefer to keep these rules enabled on stub files. These aren't executed nor importable via user code but it still will be visible in the source code and there isn't any way to catch them other then these rules. |
Do you have real-world examples where those rules flagged some code that was out of the stub author's control? The only legitimate place I can think of right now is the default value for function arguments and parameters. In this case, the default value should already be flagged in the actual code, and, arguably, the rules are then somewhat useless to run on stub files. But that only really applies to S107 because stub files should rarely contain function calls. |
I think the only thing I'd consider a false positive in stubs if the rule flaggs Since in both cases we can comfortably say that there is no hardcoded password to be found in the stub file (although it might be worth to check the annotation for a suspicious So I think the main thing we want to protect ourselves from is some automatic stub generation tool copying a hardcoded password from the source code to the stub. |
I think you meant hardcoded-password-func-arg (S106) ? There's some possible calls with kwargs in stubs (I can think of custom decorators that affect types, and class params like
hardcoded-password-string (S105)
hardcoded-password-default (S107)
That's a valid argument (and more or less what I was suggesting in my original post, but better illustrated).
From what I can tell, it's only acting on strings. Not elipsis or other types (like ints). So all good there. As a sidenote, I'd maybe even lump in hardcoded-bind-all-interfaces (S104) with a different argument as it's not about leaking a password, but a misconfiguration. Similar to #15207 it doesn't affect runtime so can't be an issue. |
Thanks for sharing the examples. They are all obvious false positives but so are they if used outside a stub file. I'm also leaning towards the keeping the rule as is because of the argument @Daverball made before
|
I agree with the other maintainers on this issue. I think having a hardcoded password in a stub is just as big a security issue as having a hardcoded password in a runtime file, and I agree that it's easy to see how it could happen as a result of a stub generated by stubgen or a codemod made by stubdefaulter. It's true that our bandit rules have lots of false positives, but if you're working on code where security is important, you really don't want to miss any possible vulnerabilities, so in some ways erring on the side of false positives is desirable for security rules. |
Thank you everyone who provided answers! |
hardcoded-password-string (S105)
,hardcoded-password-func-arg (S106)
andhardcoded-password-default (S107)
will naturally have false-positives. But do they make sense to enable in stubs? Is the risk that hardcoded password be found in source code on an assignement of a certain name, and have that be exposed as public API through stubs, actually a concern ?Or should one be encouraged to disable these rules for stubs in one's projects if they produce too many false-positives ?
(this question is extracted from #14535 (comment) for ease of tracking and discussion)
The text was updated successfully, but these errors were encountered: