Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

前端自己存储token,xss安全性问题 #2549

Open
GoldSubmarine opened this issue Sep 2, 2019 · 3 comments
Open

前端自己存储token,xss安全性问题 #2549

GoldSubmarine opened this issue Sep 2, 2019 · 3 comments

Comments

@GoldSubmarine
Copy link

Question(提问)

感谢提供这么好的模板。

我注意到前端自己把token存储到cookie里,但是这样会有xss的风险,虽然vue已经在一定程度上防范了xss,但仍然有安全风险,毕竟前端环境本身是不安全的。就像我注意到之前你引用了一个带有xss安全问题的markdown库。

为什么不是后端直接设置cookie,并设置httponly,前后端约定一个code例如:4000。任意一个接口返回4000,axios全局拦截器就拦截跳转到登录页面。

我从permission.js中看到前端从本地获取了一下cookie,没有值就跳转到登录页面,好像不需要这么做。应该像上面说的按照后端的接口code值,判断是否要跳转登录。

Other relevant information(格外信息)

  • vue-element-admin version:4.2.1(minimal )
@GoldSubmarine GoldSubmarine changed the title 前端自己存储token,安全性问题,xss 前端自己存储token,xss安全性问题 Sep 2, 2019
@GoldSubmarine
Copy link
Author

还有一个问题,如果后端是session的模式,前端存储一遍就够了,但如果是jwt的模式,就需要更新jwt,如果是当前这种前端存储cookie的做法,前后端还需约定更新的头信息。但如果是后端设置cookie,前端则不需要考虑token更新问题。

@moonose
Copy link

moonose commented Sep 3, 2019

有具体点的prototype吗?

@xiaolu289
Copy link

感觉题主说得有道理,我也觉得应该后端直接将token设置到cookie(http-only),防止js直接读取登录态

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants