Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

261
Visualizações
Building a secure user roles route in React

I'm trying to think about different ways to approach this. One method is... Let's say we get a token that has a claim to a role returned when a user logs in. For this imaginary app we have 3 roles, super, admin , guest.

The token returns a string value in the role property, eg, role: "admin"

In the app, we build two functions, a routeBuilder and a navItemBuilder, to build out these objects we pass in the role string eg "admin"

Then the application renders the correct routes and menu items that are available based on what role the user has. eg "guest" only gets access to the about page and the news.. but a super also gets another nav item called profile or something like that...

However, if I then use react dev tools and edit the token role claim, I can cause the app to re-render a new nav route. I can change the token object role string and then when it updates the routeBuilder and navItemBuilder will build the new route based off any string I want.

How can I build roles in my app and avoid this security issue?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Nothing sensitive should be built into the application itself.

Apply security at the server level.

It shouldn't matter if, for example, the user can display the UI for the Admin route.

When their browser requests the data needed to populate it from the server, the server should perform AuthZ and return an error instead of (for example) a list of users that can be administered.

Your client-side code can then handle the error so if the user ends up there by accident (e.g. if they are a valid user but their session has expired) they can be diverted to a login screen or given a useful error message.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda