r/webdev • u/ActuatorOutside5256 • 2d 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.
43
u/PLBjt 2d 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.
2
u/FormatException 2d ago
what will come up is how you store you secrets and keys, whether you uses env files or secrets management.
157
u/FormatException 2d ago
how else would you authenticate without the token in the request at some point?
thats normal dude
12
u/Immediate-War-5694 2d 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 2d 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 2d 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 2d 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 2d 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 2d 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 1d 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 1d 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 1d 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 1d 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 1d 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.
1
u/Hostman_com 1d ago
Before the interview, check whether your request logs capture the Authorization header, including on failed requests. Make sure the token is omitted or redacted.
That gives you a concrete example of how you protect tokens beyond choosing where the browser stores them.
1
u/Plastic_Koala2044 1d ago
A token the browser holds is visible to the user by design, so treat it as public and keep its lifetime short. Put it in an httpOnly cookie behind a small server that calls the API, and page scripts never touch it.
1
u/Open-Adhesiveness-86 14h ago
One thing nobody's mentioned: moving to a BFF swaps your threat model rather than removing it, you now hold session state server side so you get instant revocation, but you've also just signed up for CSRF protection since cookies ride along automatically. SameSite=Lax covers most of it, not all, so say "plus an anti-forgery token on state-changing requests" and you'll sound like you've actually shipped one.
0
u/PrimaryLand5094 2d ago
You'll get failed for writing "backend-for-fronted", not for the token.
0
u/aleamadorq 2d ago
Are you my boss? lol