Reject zero-length Buffer/KeyObject secrets for HS* algorithms, like empty strings
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- javascript, node.js
- Domínio
- authentication, backend, security
Direção de pesquisa
Start by reading the sign and verify key validation paths and the tests for empty string secrets; the issue names no file paths. Check how keys become KeyObjects and how HS* algorithms handle a zero-length symmetric key. Done means zero-length Buffer and secret KeyObject inputs are rejected in sign and verify with the existing errors, while algorithm: 'none' behavior remains unchanged. The issue says a PR is ready, so check the linked work before starting.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Describe the problem you'd like to have solved
jwt.sign() and jwt.verify() reject an empty string secret (secretOrPrivateKey must have a value / secret or public key must be provided). A zero-length Buffer, or a secret KeyObject created from one, is truthy, so it gets past that check. HS256/HS384/HS512 then sign and verify with an empty HMAC key.
In practice this comes from configuration, not intent. For example, the secret is read from a file that exists but is empty (fs.readFileSync(path)), or it is decoded from an unset variable (Buffer.from(process.env.JWT_SECRET ?? '', 'base64')). The application keeps working, because it signs and verifies its own tokens, but anyone can compute valid tokens for an empty key. With '' the same mistake fails loudly.
This has been visible since auth0/node-jws#51. It is related to #286 and #335, which cover missing or empty string secrets.
Describe the ideal solution
Treat a zero-length symmetric key the same way as an empty string for HS* algorithms. After the key has been converted to a KeyObject, reject symmetricKeySize === 0 in sign and verify, using the existing error messages. algorithm: 'none' behaviour stays the same (#386).
Alternatives and current work-arounds
Applications can check the key length themselves before calling the library.
Additional context
I have a small PR ready with tests and will link it here.
- Linguagem predominante
- JavaScript
- Estrelas
- 18.2k
- Forks
- 1.3k
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de auth0/node-jsonwebtoken
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
auth0/node-jsonwebtoken#1042 · 2 comentários ·
-
`jwt.sign()` callback is executed twice for "The payload already has an "..." property" errorsTalvez já em andamento @cobyfrombrooklyn-bot assumiu há 268 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
auth0/node-jsonwebtoken#1000 · 2 comentários · 1 reação ·
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 15/100
auth0/node-jsonwebtoken#1054 ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 45/100
auth0/node-jsonwebtoken#1048 · 1 comentário ·
-
verify() resolves a string secret by attempting createPublicKey() first, costing 4x-52x on the HS* pathTalvez já em andamento @Hashim1999164 assumiu há 62 dias. Aberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 65/100
auth0/node-jsonwebtoken#1046 ·
Todas as issues de auth0/node-jsonwebtoken
Issues semelhantes
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 72/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
OWASP/CheatSheetSeries#3018 ·
Mantenedores costumam responder em até 1 dia
-
Radix number block generates NaN after switching a negative or decimal number to binary, octal or hexTalvez já em andamento @matthewalberto assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 64/100
mit-cml/appinventor-sources#4246 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
marketing
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 83/100
GoogleChrome/modern-web-guidance-src#3675 · 2 comentários ·
Mantenedores costumam responder em até 1 dia