---
title: "Comment by Lihai Ben-Haim on \"React, NodeJS and JWT Authentication - the right way!\" | Hashnode"
description: "Hey Gal thank you for this amazing thread ive learn alot. However i have some questions: How JWT in memory protects against XSS attacks as if XSS attack occurs"
url: "https://hashnode.com/posts/react-nodejs-and-jwt-authentication-the-right-way/5f4ff0aec48c6b29cd2ecd0a/comment/5f7837917d160d41227d7363"
---

[Discussion](https://hashnode.com/posts/react-nodejs-and-jwt-authentication-the-right-way/5f4ff0aec48c6b29cd2ecd0a)

Comment [React, NodeJS and JWT Authentication - the right way!](https://hashnode.com/posts/react-nodejs-and-jwt-authentication-the-right-way/5f4ff0aec48c6b29cd2ecd0a)

[Lihai Ben-Haim](https://hashnode.com/@lihaibh)

[Oct 3, 2020](https://hashnode.com/posts/react-nodejs-and-jwt-authentication-the-right-way/5f4ff0aec48c6b29cd2ecd0a/comment/5f7837917d160d41227d7363)

Hey Gal thank you for this amazing thread ive learn alot. However i have some questions:

1.  How JWT in memory protects against XSS attacks as if XSS attack occurs an attacker can access all the resources a client has.
2.  On a "refresh-token" call i saw you are creating both refresh token and an access token, this can eventually increase the login expiration time to indefinitely as we call "refresh\_token" before the access token expires and the access token should have short expiry time.
3.  In case of a common server <-> client communication (not micro services) i dont see the reason why to encrypt the access\_token. You should not read the jwt payload on the client side?

[Gal Malachi](https://hashnode.com/@galm)

[Oct 3, 2020](https://hashnode.com/posts/react-nodejs-and-jwt-authentication-the-right-way/5f4ff0aec48c6b29cd2ecd0a/comment/5f7837917d160d41227d7363#reply-5f7841f47d160d41227d743c)

Hi [Lihai Ben-Haim](https://hashnode.com/@lihaibh),

Glad you like it! Let me answer your questions:

1.  You are right, it is still not bulletproof, however, it makes it much difficult to still the token from the memory, as the attack should be tailored to your exact app. Combining that with a short-living tokens makes the risk low, but still exists.
2.  The limit come from the refresh token expiration. When the user is active and logged in, we don't want revoke his access. If we want to limit the time for an active user, we can add a logic on the client side or the backend to force logout after a certain period. I didn’t took care of it here, but it is completely possible.
3.  encrypting the token is a good practice as it contains the identifier of the user inside it, and if stolen can give the hacker data that might be used in future attacks.
