admin管理员组文章数量:1404927
I have backend and frontend applications. On the backend side I'm using RSA private + public keys to issue JWTs. I understand that the private key should never be shared, but what about public key?
I'm using next.js for the frontend and I want to render or NOT to render some components based on user's role within the JWT. Suppose that I have some kind of <AdminNavigationBar/>
and I want to render it only if user's role is ADMIN. Now I have two options and the first one is exactly about my question.
- Include public key into frontend and verify JWTs on client side. But I don't understand if it's safe to expose public RSA key to be anyhow visible to someone else.
- Create separate /endpoint on the backend side for JWT verification and call it every time I need to verify JWT to render/not to render some components.
*Note: it's important to understand that I'm not talking about regular API endpoints to get any kind of data. In this case I would just return 403 and public key will be used only on the backend side (and therefore not exposed). I'm talking about frontend only.
I have backend and frontend applications. On the backend side I'm using RSA private + public keys to issue JWTs. I understand that the private key should never be shared, but what about public key?
I'm using next.js for the frontend and I want to render or NOT to render some components based on user's role within the JWT. Suppose that I have some kind of <AdminNavigationBar/>
and I want to render it only if user's role is ADMIN. Now I have two options and the first one is exactly about my question.
- Include public key into frontend and verify JWTs on client side. But I don't understand if it's safe to expose public RSA key to be anyhow visible to someone else.
- Create separate /endpoint on the backend side for JWT verification and call it every time I need to verify JWT to render/not to render some components.
*Note: it's important to understand that I'm not talking about regular API endpoints to get any kind of data. In this case I would just return 403 and public key will be used only on the backend side (and therefore not exposed). I'm talking about frontend only.
Share Improve this question asked Mar 9 at 14:51 Jake MayerJake Mayer 191 silver badge6 bronze badges 4 |1 Answer
Reset to default -1I ended up to this:
- On the frontend side check if there's JWT with required role (no verification, so it's fast)
- If yes, then I'm calling separate /endpoint implemented on the backend to verify that JWT is valid, not expired and contains required role.
- If backend verified that everything is okay then I'm rendering this on UI.
It's probably bad approach (because even if I'm an admin I need to wait for additional request to be finished) but it works. There is a mention about server side rendering in the comments but I didn't have enough time to invest into researching & implementing this even though it's probably the way to go.
本文标签: springJWT public key securityStack Overflow
版权声明:本文标题:spring - JWT public key security - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744868726a2629497.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
/admin/...
) has all the rights for it. So it doesn't matter if some "hacker" hacks his way into displaying ADMIN UI since the BE will still not allow calls to admin endpoints – asgarov1 Commented Mar 9 at 15:15