简体   繁体   English

jsonwebtoken中的数据是否不可重写

[英]does data in jsonwebtoken are un rewritable

I'm using jsonwebtoken on my node js server and inside the jsonwebtoken i store the role of the user. 我在节点js服务器上使用jsonwebtoken ,并且在jsonwebtoken内部存储了用户角色。

So everytime he do a request i just have to check if the required role is given in the token. 因此,每次他提出请求时,我只需要检查令牌中是否指定了所需角色。 But do people can change this role ? 但是人们可以改变这个角色吗? I know everyone can see it but i guess no one can change it without my secret, right ? 我知道每个人都可以看到它,但是我想如果没有我的秘密,没有人可以更改它,对吗?

Off course im always checking the jsonwebtoken is correctly signed. 当然,我总是检查jsonwebtoken是否正确签名。 Do you think this method seems good ? 您认为这种方法看起来不错吗? Sorry, english is not my main language 抱歉,英语不是我的主要语言

if you change the jwt data and then hash it with a different signature then you server will know its a fake token. 如果更改jwt数据,然后使用其他签名对其进行哈希处理,则服务器将知道其为伪造令牌。

also make sure you use https so your tokens wont be available to sniffs. 还请确保您使用https,这样您的令牌就不会被嗅探器使用。

if you store your token in a cookie make sure you put your cookie with http-only to prevent cookie highjack 如果您将令牌存储在cookie中,请确保将cookie放在http的位置,以防止cookie劫持

also i recommend you to use csrf token to prevent csrf attacks 我也建议您使用csrf令牌来防止csrf攻击

I guess you store the jwt in a Cookie or in LocalStorage on the client side. 我猜您将jwt存储在Cookie或客户端的LocalStorage中。
So ofc, the user can delete or alter the cookie but he can't read it without your secret. 因此,用户可以删除或更改Cookie,但是如果没有您的秘密,他将无法读取它。

So if he tries to update the token, it will probably become corrupted and unreadable from your server side. 因此,如果他尝试更新令牌,则令牌可能会损坏并且无法从您的服务器端读取。

If the token is corrupted you'll probably want to log-out the user and redirect him to the login page. 如果令牌已损坏,您可能需要注销用户并将其重定向到登录页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM