I see that it's almost standard today to use JWT for modern applications, where the API and the front-end are totally separated, and served from a different server.
I know that browsers will not send cookies to different domains by default, but this can be overcome easily by setting the correct headers in the backend, and configuring the HTTP client accordingly, for example with Axios:
withCredentials: true
And express:
res.setHeader('Access-Control-Allow-Credentials', true);
This allowed me to use express-session, even though the frontend sits on localhost:3000 and the backend on localhost:8000(treated as cross-domain).
The question: Does this pose an increased security risk(cookie being stolen and used, for instatnce) over a JWT token, stored in localStorage? I mean, with cookies you can at least set the httpOnly attribute(what express-session does by default), which will block JS from using it, but with localStorage this is obviously impossible, being that you have to get it via JS.
Any clarification will be greatly appreciated.