jaraco / keyring

MIT License
1.24k stars 152 forks source link

Backslashes in password are not handled correctly #674

Open lajonss opened 4 months ago

lajonss commented 4 months ago

Describe the bug Backslashes in password (e.g. encoded unicode characters) make the library behave incorrectly.

To Reproduce

~$ cat dupapassword
\u0142u\u017c
~$ keyring set dupaservice dupauser < dupapassword
~$ keyring get dupaservice dupauser

~$

Expected behavior I guess backslashes should be supported, or an error should be reported when trying to set such password.

Environment

$ pip list | grep keyring
keyring               25.0.0

$ keyring --list-backends
keyring.backends.libsecret.Keyring (priority: 4.8)
keyring.backends.kwallet.DBusKeyring (priority: 4.9)
keyring.backends.SecretService.Keyring (priority: 5)
keyring.backends.fail.Keyring (priority: 0)
keyring.backends.chainer.ChainerBackend (priority: 10)

Additional context I've stumbled upon this when using Numberstation with polish characters (ł, ż) entered as token names. Numberstation uses urllib.parse.urlencode and json.dumps to turn them into a password.

Python API returns empty string:

>>> keyring.get_password('dupaservice', 'dupauser') is None
False
>>> keyring.get_password('dupaservice', 'dupauser')
''