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

Empty secret is accepted by encode #1009

Open
lacop11 opened this issue Oct 24, 2024 · 0 comments
Open

Empty secret is accepted by encode #1009

lacop11 opened this issue Oct 24, 2024 · 0 comments

Comments

@lacop11
Copy link

lacop11 commented Oct 24, 2024

I think it would be a good idea for jwt.encode to raise an exception if the secret argument is an empty string.

https://vulnapi.cerberauth.com/docs/vulnerabilities/broken-authentication/jwt-blank-secret

Right now it works but produces JWT that is trivially spoofed:

>>> e = jwt.encode({"foo":"bar"}, '', algorithm='HS256')
>>> print(e)
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIifQ._NaFhGu8tCCgBKksGBA6ADwRdKx3e9GES_KyF4A5phE
>>> jwt.decode(e, '', algorithms=['HS256'])
{'foo': 'bar'}

Of course users should not call it with empty secret but that will usually come from some configuration file, environment variable or secret store, and it is possible to have a bug somewhere along that chain and accidentally initialize it to empty value. Having the encode call fail would be safer.

This would technically be a breaking API change and there might be intentional calls with empty secret such as in tests, but I think those would be easy to swap to another non-empty test string.

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

1 participant