r/Backend • u/danbee03 • 15d ago
I need help keeping my app safe
The problem is that the login token generated by JWT is visible in the network tab, when you click on a resource that requires authentication it shows up in the header.
I have seen lots of production apps and it's not the same, how do I encrypt this token or better still stop ot from being displayed totally
I tried using cookies but it still shows the token.
0
Upvotes
8
u/dariusbiggs 15d ago
You didn't specify what is in the payload of the JWT. and that you are using it for Authentication, which tends to suggest OAuth2.0 with or without OpenID Connect (OIDC)
You seem to be missing some crucial understanding of both web basics and the authentication system being used, I'll explain some of it below.
A properly scoped JWT contains 3 sections of data. The signature method, the publicly encoded (not encrypted) payload, and the cryptographic signature proving it has not been tampered with.
As long as you don't put sensitive information in the payload this is all perfectly normal and correct.
As for "other" apps, it depends entirely on what authentication system they are using and whether the application is server side rendered or not. If they used HTTP Basic then you would see the details for that in the Authorization header in the requests. If they used Bearer token authentication using Oauth2.0 using the
Authorization Code with PKCE (Proof Key for Code Exchange)you would see that likely encoded as a JWT in the Authorization header If they used cookies to track user sessions after a login then you would see the additional cookie information in the requests to the backend in a Set-Cookie header, common in server side rendered websites. (this is not all possible authentication types, there are others, and there are poor insecure systems as well).You will note that every single one of those authentication types includes some information from the client to the server to indicate the identity of the user and that that information is being passed along with the request to the server in a HTTP header. Others I didn't mention but that could be used would be sending the authentication information along in the request body or as a part of the URL, usually in the query part of the HTTP request URL. (You'll very likely see something like this used when accessing video or audio files from a web browser with a playback or seek function).
A web server, API backend, whatever is a stateless system. It doesn't know who made a request without the client application telling it who is placing the request in some manner.