1

Are there any security risks to returning a user's JWT in the response body to a GET request? The JWT is only returned for authenticated users. Authentication is managed via a JWT stored as a HttpOnly, Secure, SameSite:Lax cookie.

Flow, in detail:

  1. User makes GET request to my.com/api/session. The request includes the user's JWT cookie mentioned above.
  2. Server validates the authentication cookie, and – for authenticated users – returns the JWT in the response body.

Is there a risk of a CSRF attack in browsers that don't support SameSite:Lax? In those cases, could a malicious site make the GET request to my.com/api/session and – if the user is logged into our site – have the JWT cookie automatically included in that request?

1 Answer 1

2

... malicious site make the GET request to my.com/api/session and – if the user is logged into our site – have the JWT cookie automatically included in that request?

Yes, this is possible. But due to the nature of Same Origin Policy the malicious site cannot directly cross-origin read the result of the request.

Depending on how the JWT is exactly delivered it might be possible though to observe effects of the JWT and thus get to the value. For example if the body of the response consists of name=value it might be possible for an attacker to do a cross-origin script include for the resource and then be able to access the value though name from Javascript.

Variations of this exist and issuing the JWT itself (even not read) might also have unwanted side effects at the server. So it is better to detect such cross-origin request at the server. This can be done with classic CSRF tokens, by observing headers like Referer, Origin or (in newer browsers) Sec-Fetch-Site, by requiring a special non-standard HTTP header (which results in a CORS preflight on cross-origin requests).

2
  • And if we've enabled all CORS requests on the server do we lose the protection of the Same Origin Policy? Commented Nov 16, 2021 at 13:34
  • 2
    @StudSterkel: If you allow arbitrary cross-origin requests using CORS then you are losing protection from SOP. A proper CORS policy should allow access only for selected cross-origin requests though and usually only from specific origin either, so that it weakens SOP for the necessary selected use cases and not in general. Commented Nov 16, 2021 at 17:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .