Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are JWT tokens stored on the server and other related questions

Tags:

security

jwt

As the title suggests, where are JWT tokens stored on the server side? in database or in memeory? I understand the implementation can vary due to different requirements, but just in general where would you store it?

If I want to provide a very basic token authentication server, meaning upon receiving a username and password via a POST request, I would like to return a token. In this case, how is a token generated with a very basic algorithm work differently than a jwt token?

With a token generated by a simple algorithm:

  1. it does not contain payload
  2. its value is not computed based on the username and password, thus it cannot be rehashed back to anything meaningful

In this case, is there still value to use JWT?

Thanks!

like image 526
Cheng Avatar asked Oct 31 '15 04:10

Cheng


People also ask

Where JWT tokens are stored on server?

A JWT needs to be stored in a safe place inside the user's browser. Any way,you shouldn't store a JWT in local storage (or session storage). If you store it in a LocalStorage/SessionStorage then it can be easily grabbed by an XSS attack. If the answer is helpful, please click "Accept Answer" and upvote it.

Where is the best place to store JWT token react?

Storing JWT Token We can store it as a client-side cookie or in a localStorage or sessionStorage. There are pros and cons in each option but for this app, we'll store it in sessionStorage.

What are the 3 parts of JWT token?

Figure 1 shows that a JWT consists of three parts: a header, payload, and signature.

Where should tokens be stored?

# Tokens stored in localStorage are automatically protected from CSRF attacks, because localStorage items are not automatically sent to servers with each HTTP request. But they are vulnerable to XSS attacks, where they can be easily accessed by JavaScript.


1 Answers

client needs to store it, on server storage is not required.

JWT have all the claims in itself and is signed by the server as well. On receipt, server checks for the signature and reads the claims. It does not match it against a stored value. That is the whole point of using JWT against access tokens.

Look at how a JWT is structured.

like image 169
Vikash Avatar answered Oct 07 '22 18:10

Vikash