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 input linter when asking for password #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

clavedeluna
Copy link
Contributor

Closes #16

The goal is to detect when a user uses the built-in input function with an arg or kwarg of string containing "password". Unit tests demonstrate when this may be a false positive, such as input("Please enter your name. Please do not enter your password")

First pass attempt, would love feedback.

Copy link
Contributor

@mschwager mschwager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Can you also add a line under an Added section in Unreleased in the CHANGELOG?

off_by_default = False

_code = 'DUO139'
_error_tmpl = 'DUO139 avoid using "input" to ask for password'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to include the remediation in the message if it's short enough. How does this sound?

DUO139 avoid using "input" to ask for password, prefer "getpass.getpass"

@@ -42,6 +42,7 @@ Dlint uses a simple, folder-based hierarchy written in [Markdown](https://en.wik
- [`DUO136` `BadXmlsecModuleAttributeUseLinter` insecure "xmlsec" attribute use](https://github.com/dlint-py/dlint/blob/master/docs/linters/DUO136.md)
- [`DUO137` `BadItsDangerousKwargUseLinter` insecure "itsdangerous" use allowing empty signing](https://github.com/dlint-py/dlint/blob/master/docs/linters/DUO137.md)
- [`DUO138` `BadReCatastrophicUseLinter` catastrophic "re" usage - denial-of-service possible](https://github.com/dlint-py/dlint/blob/master/docs/linters/DUO138.md)
- todo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this needs a bump 👍


def _get_arg_or_kwarg(self, node):
if node.args:
return node.args[0].value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also check that node.args and node.keywords are not empty before checking [0]. This would produce a runtime error in the code because input takes 1 argument, but you never know what code you'll find in the wild. In other words, static analysis will often see code that hasn't been executed, or has all kinds of weird bugs, so it's best to be defensive :)

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

Successfully merging this pull request may close these issues.

Add linter to detect input asking for password
2 participants