rest - JWT stored in cookie - security concerns -
i'm building spa app server side rendering, using jwt-based authentication.
current implementation is:
- jwt token issued , transferred client after successful username , password verification
- token stored in cookie (not
httponly
) - purpose of avoid need login again after full refresh or closing page - logging out deleted cookie token
authorization
header attached every api request if token exists- full ssl traffic
i can't store token in localstorage because of server side rendering, there no httponly
because need access cookie in order construct authorization
header.
what possibilities of stealing token in such architecture?
one major risk single cross-site scripting vulnerability in application used steal token cookie, because it's not httponly (while understand why case). xss in javascript-heavy application spa common , hard avoid.
also you're saying token kept in cookie after closing browser, user still logged in. on 1 hand, that's bad practice, user closing browser expects being logged out. on other hand, means cookie persisted disk, easier attacker steal client.
another thing comes mind cross-site request forgery (csrf), if understand correctly, authentication based on authorize
header, token copied in each request. if that's case, csrf not issue (but be, if sending token in cookie enough).
so @ least, think should
not use persisted cookie token
try minimize chance of xss (eg. automatically scanning code, never 100%, choosing secure default technologies)
make sure auhentication based on
authorize
header , not cookie
still because of xss risk, not recommend doing way in security-critical application.
Comments
Post a Comment