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 · 2 comments
Open

Empty secret is accepted by encode #1009

lacop11 opened this issue Oct 24, 2024 · 2 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.

Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the stale Issues without activity for more than 60 days label Dec 24, 2024
@Craz1k0ek
Copy link

If you look at the RFC specification, you can see that there is a none algorithm which MUST be implemented. This is correctly done in this library. You can see that there is specific handling of the none algorithm scenario in algorithms.py.

I do agree that having no secret is very counter intuitive, but it is a valid option for a JWT.

@github-actions github-actions bot removed the stale Issues without activity for more than 60 days label Dec 31, 2024
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

2 participants