Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

`validateCustomClaims` only runs once and then returns the same result for every other attempted call even when checking different claims (security flaw or am I using it wrong?)

Aberta
#514 2 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
48/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Ativa
Stack de tecnologia
firebase, react, typescript

Direção de pesquisa

Comece pelo CodeSandbox vinculado, especialmente App e ComponentForSuperadminOnly; depois, leia o ponto de entrada useSigninCheck e compare validateCustomClaims com requiredClaims. Confirme como diferentes verificações de claims são tratadas entre as chamadas; o trabalho estará concluído quando as verificações de admin e superadmin retornarem cada uma o resultado apropriado, em vez de reutilizarem o primeiro resultado.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

v5
Version info

React: 17.0.1

Firebase: 9.6.1

ReactFire: 4.2.1

Steps to reproduce

use useSigninCheck with validateCustomClaims at some point in the component tree and then try to use it again later on with different custom claims

Expected behavior

I should be able to pass different custom claims during different calls to show/hide different parts of the UI. validateCustomClaims should run every time I use it and return the appropriate result. For example, if I want to show some components to "admin" users and some other components to "superadmin" users.

Actual behavior

validateCustomClaims only runs the first time you call it and on subsequent calls just returns the same hasRequiredClaims result from the initial run. This seems to be a major security flaw especially if you aren't aware that it's doing this.

Test case

The sandbox below calls validateCustomClaims in the <App /> component and returns a hardcoded true result... Later in the <ComponentForSuperadminOnly /> it tries to validate that the user has superadmin claim and returns true even though it does not have the claim. Additionally, the validateCustomClaims function is not even run in this call as there is no console.log for it.

If you switch the validateCustomClaims check in the <App /> component to use the requiredClaims method then the custom validator does run in the <ComponentForSuperadminOnly /> component.

Lastly, using the requiredClaims property method to check for superadmin instead of a custom validator returns the appropriate result no matter where it is used. I would assume both methods should always return an accurate result no matter where they are used in the tree.

https://codesandbox.io/s/usesignincheckissue-xqwm4u?file=/src/App.js

Linguagem predominante
TypeScript
Estrelas
3.6k
Forks
403
Merge médio
5d 1h
PRs com merge (30d)
10

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de FirebaseExtended/reactfire

Todas as issues de FirebaseExtended/reactfire

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.