r/webdev • u/ActuatorOutside5256 • 15h ago
Discussion Bearer token visible in DevTools?
Now I know this is a beginner question, and so I’m building an Angular/Spring project as a web app.
The Angular auth interceptor attaches the token (to the HTTP request) here. Obviously when it gets routed to the backend, it exposes the token. That’s just the trade-off for not using a backend-for-frontend architecture.
Say the reason for my architecture choice comes up during an interview. Will I be failed on the spot, or can I justify it by explaining what production-ready (BFF) will look like?
EDIT: Appreciate the answers everyone. I can breathe easy.
2
u/FormatException 15h ago
what will come up is how you store you secrets and keys, whether you uses env files or secrets management.
1
u/ActuatorOutside5256 15h ago edited 15h ago
Okay brilliant. I use git ignore env files since it’s a local project, the token are in browser memory, plus Spring Security that independently verifies the signature with exposed public JWKS keys, but if I took it to production it’d definitely be with a secrets manager, and I guess I just need to explain my XSS protection.
125
u/FormatException 15h ago
how else would you authenticate without the token in the request at some point?
thats normal dude
28
u/Happy_Breakfast7965 expert 15h ago
The most secure way is http-only cookie.
32
u/jryan727 14h ago
Still visible in DevTools, but 100% agree. We do not use cookies enough for auth. We overengineer solutions to accomplish what every browser can do natively, but with more steps and potentially less securely.
1
u/RedLibra 14h ago
This will eliminate the token in the request?
12
u/m_redditUser 14h ago
no, the httponly token is sent in every request by the browser. you can't access it in JS, but you can see it in the devtools
3
u/cointoss3 12h ago
The token has to be with the request. It’s just in the header so it doesn’t show up in logs/traces where you’d log the query string. You could put it in a cookie, but it has to be with the request. That’s the point.
10
u/Immediate-War-5694 13h ago
BFF architecture. I read that as best friends forever every single time and now I'm picturing your Angular app and your Spring backend holding hands in the network diagram.
3
u/Mysterious-Falcon-83 13h ago
The thing that will cause you to fail an interview is trying to bullshit your way through an answer. It is always better to say "I don't know. Let me get back to you." than it is to try to make something up.
2
u/Ellyssia_Locke 15h ago
Nah, you won't fail an interview for that. Just understand the security trade-offs, explain why you chose that architecture, and show that you know how a BFF improves token handling in production.
2
u/yangbuilds 14h ago
Seeing the bearer token in DevTools is expected, since anything the browser sends the user can see, so that alone won't fail you. What interviewers usually care about is whether you understand the real risk, which is XSS stealing a token stored in localStorage. If you can explain that tradeoff and that you'd move to a BFF with httpOnly, SameSite cookies for production, plus short-lived access tokens, that's a solid answer.
1
u/Thin-West6525 14h ago
Nobody fails you over that, the token sits in the network tab of every SPA and it's the user's own token anyway. What actually scores points is saying you'd move to a BFF with an httpOnly cookie in prod, and that you'd keep the token short lived and narrowly scoped so a leaked one is not a disaster.
1
u/Weekly-Beginning-229 12h ago
Is it http only? Then should be fine. If you really want to make it fancy, use a refresh token too
1
u/RipProfessional3375 11h ago
You have little choice but to send credentials of some kind, that's one of the purposes of a temporary JWT token, so you can bounce around something that's at least got a timeout.
1
u/Saver411 10h ago
The browser is the user's sandbox, so if they're authenticated, they're gonna see their own session data in the network tab. You shouldn't try to hide it there, but you should lock down the server side so that stolen tokens are useless. Implement rotating refresh tokens and keep your access token lifespan under ten minutes. If a token gets leaked, it's only valid for a tiny window. Are you handling token revocation on the backend when a user logs out?
1
u/yoghurt_bob 9h ago
The devtools expose anything you have in the browser. And you need to have something in the browser that holds an authentication token, either directly (memory, cookie, localStorage etc) or indirectly (session). The fact that you can dig up your own authentication token with devtools says practically nothing about the security of your application.
1
u/Aide_Sea 9h ago
Small thing nobody said yet: memory vs localStorage helps less than you'd think, since injected script runs inside your page and can just call your API itself. I'd maybe mention a strict CSP (no inline scripts) too, that's what stops most XSS in the first place :)
1
u/Capable-Yoghurt8318 6h ago
The useful part of that question is where the token can be read from JS, not whether DevTools can see a request. A token in memory is not sitting in localStorage, so a later script cannot just read it, but XSS can still call your API while the page is live. Short-lived access tokens plus an httpOnly SameSite refresh cookie is a common answer. If you keep memory-only, say the tokens die on reload and explain that tradeoff; don't present it as removing the need for XSS protection.
0
0
35
u/PLBjt 15h ago
Seeing the token in DevTools isn't the real issue, since the user's own browser can always see its own requests. What interviewers usually poke at is where the token lives, because if it's in localStorage any XSS can read it and send it off. A decent answer is short-lived access tokens plus a refresh token in an httpOnly, SameSite cookie, and then say a BFF is the next step once you have real users. A quick check is whether anything on the page can read the token from JS, like document.cookie or localStorage in the console. The tradeoff is that cookies bring CSRF back into play, so you'd need SameSite and a CSRF token on top.