#32061: Credential leaks on MySQL's dbshell crash
-------------------------------------+-------------------------------------
Reporter: Simon | Owner: nobody
Charette |
Type: Bug | Status: new
Component: Core | Version: 3.1
(Management commands) |
Severity: Normal | Keywords:
Triage Stage: Accepted | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
''I reported this issue to the security team on September 9th 2020 but it
was deemed that it was better to handle it in public. On September 30th
Charlie Denton also reported the issue to the security team hence why I'm
finally creating a ticket for this so he also gets credit''
A variant of this issue was initially reported 5 years ago (#24999) where
the reporter mentioned that usage of the --password flag when spawning a
mysql shell process would show up in ps with the password in plain text.
What I'm reporting now is that if the dbshell management crash on backends
that pass the `--password` flag in plain text (e.g. MySQL) the
`CalledProcessError` exception raised will have the following signature
{{{
CalledProcessError: Command '['mycl', '--user=user', '--
password=p4ssword', '--host=host', '--port=3306', 'database']' returned
non-zero exit status 1.
}}}
That's not a big deal when no form of logging is in place but when it's
the case (e.g. Sentry, Elastic, Graylog) it's possible for some systems to
fail at obfuscating the `--password=` part due to the complex nature of
the string.
In order to prevent that from happening I suggest we override
[https://github.com/django/django/blob/9e8edc1e5511f128dec6bcd70a10ebd263b76280/django/db/backends/mysql/client.py#L52
MySQL backend's runshell method] to pass `env={'MYSQL_PWD': PASSWORD}`
instead of using the `--password` flag even if
[https://dev.mysql.com/doc/refman/8.0/en/environment-variables.html it
looks like this is discouraged] (and even meant to be deprecated?) for
reasons similar to the ones mentioned in #24999.
[https://github.com/django/django/blob/5b884d45ac5b76234eca614d90c83b347294c332/django/db/backends/postgresql/client.py#L35-L37
That's the exact approach currently used by the PostgreSQL backend
though].
An alternative could be using the [https://pypi.org/project/pexpect/
pexpect library] to provide the password when prompted for instead but I
fear this solution might not be suitable due to the external dependency it
would incur. I haven't investigated how complex it would be to implement a
cross-platform vendored solution without the use of `pexpect` but I fear
dragons may lurk in the details of dealing with that properly.
--
Ticket URL: <https://code.djangoproject.com/ticket/32061>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.2342521e0bc29cbbe7bce7437c7e7067%40djangoproject.com.