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

changing the JWT signing key to high-entropy random String #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

islamazhar
Copy link

@islamazhar islamazhar commented May 19, 2020

Setting the JWT signing key to small-sized easily guessable weak string like "secret" can make it vulnerable to offline brute-force attack using cracking tools like JohnTheRipper, hashcat,
c-jwt-cracker [1]

Therefore, the JWT signing key must be [2]

  • at least 128 bits (16 characters long)
  • cryptographically produced random string having high entropy

I have set the JWT signing key to a cryptographically secure random string so that if anyone uses your code for developing an application, then attackers won't be able to guess the secret key of the application.

References:
[1] Weak Token Secret, OWASP JWT cheat-sheet
[2] Ensure Cryptographic Keys Have Sufficient Entropy RFC-8725 JSON Web Token Best Current Practices

@nazar-art
Copy link

nazar-art commented Oct 17, 2020

nice comment.
However, generate new random secret is not a good idea - if you restart app your old token wouldn't be valid anymore. Thus, it couldn't be valid for 10 hours, etc.

@koushikkothagal
Copy link
Owner

Agree with @nazar-art . A better approach would be to move it to a properties file and use a longer and more complicated key. The value assignment and usage here is intentionally simplistic to support learning in a tutorial context.

@jmhmjayamaha
Copy link

what we usually do in a production-level application is, read the secret key from a property file. So then it is possible to change the secret key depends on the environment( dev, uat, prod). when deploying the .jar file in servers we override the property file with a sysconfig file.

Copy link

@jmhmjayamaha jmhmjayamaha left a comment

Choose a reason for hiding this comment

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

when restarting the server this will change. It is good to read the secret key from the property file. Also, the key should be strong.

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.

None yet

4 participants