oauthjwtrefresh-token

is refresh token really beneficial in terms of security?


This question is SPA application specific like reactjs or vuejs.

when implementing jwt, refresh token is recommended for several reasons.

I found that the main reason of this is increasing security by keeping access token short-live(ex an hour) while refresh token set long-live(ex a year).

I also found that the safest place to store the tokens is cookie as it prevents XSS attack.

However, if we store both access and refresh token in cookie, both are sent over every http request and both can be stolen. then what is the point of having refresh token?

I know if we have auth server and resource server separately, only using refresh token to the auth server can reduce the chance to steal. But I have only one server (resource auth) and I don't think many apps implement auth server separately.

to sum up, question is is there any benefit to implement refesh token in terms of security?


Solution

  • It is all about limiting the impact of exploits.

    OAUTH BEHAVIOURS

    These are the standard OAuth behaviors in any environment, to protect bearer tokens.

    BROWSER BEHAVIOURS

    The browser is a particular client environment with its own best practices. Browser clients cannot usually safely supply a client credential:

    SUMMARY

    In some client environments you can use stronger defenses like proof of possession tokens. But that is not usually practical in the browser.

    When the client environment restricts your options, follow the above type of standard behaviours, regardless of your particular setup.

    In the browser, an XSS exploit can call all endpoints, send all cookies and steal your data. You mitigate as best you can by following best practices. Such attacks also end when the user navigates away from the app.