Skip to content

✨ feat(auth-permission): accept a list of headers in apiKeyHeader - #68

Merged
MatheusAndrade23 merged 3 commits into
mainfrom
feature/tim-3596
Oct 7, 2026
Merged

MatheusAndrade23 merged 3 commits into
mainfrom
feature/tim-3596

Conversation

@MatheusAndrade23

@MatheusAndrade23 MatheusAndrade23 commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Contexto

TIM-3596

apiKeyHeader aceitava apenas string | undefined. Agora também aceita uma lista de headers, no registerPermissionAuth (Fastify) e no expressRegisterPermissionAuth (Express).

Mudanças

  • apiKeyHeader?: string | readonly string[]. Com lista, a requisição passa se qualquer chave enviada for válida; só recusa quando nenhuma é. As chaves são testadas na ordem da lista e para na primeira válida. Erros que não dependem da chave (validator indisponível, header de broker malformado) são lançados na hora. Se todas falharem, um 403 (chave válida sem permissão) tem prioridade sobre 401.
  • Nomes de header normalizados para minúsculas ('Authorization' passa a funcionar).
  • Retrocompatível: sem configuração, continua x-api-key.
  • Erro no registro quando:
    • a lista é vazia;
    • a lista inclui o authorizationHeader e alguma rota usa acceptsSessionToken (o Bearer <jwt> seria lido como API key).
  • assertHasPermission, o hook e o rate limit usam a mesma lista resolvida.
  • Rate limit: o orçamento de cada chave enviada é verificado (credentialRateLimitKeys), para que uma chave aleatória extra num dos headers não fure o limite da chave válida.

Testes

  • Fastify e Express: leitura por qualquer header da lista (case-insensitive), 401 para header fora da lista, lista vazia, conflito com session token.
  • Fastify e Express: aceita quando uma das chaves é válida e recusa (401) só quando nenhuma é.
  • Fastify: para na primeira chave válida, 503 não tenta a próxima, assertHasPermission standalone e rate limit bucketizando pela chave lida da lista.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-07T15:25:00.135280Z 9e791b2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@MatheusAndrade23 MatheusAndrade23 self-assigned this Oct 7, 2026
@MatheusAndrade23 MatheusAndrade23 added the enhancement New feature or request label Oct 7, 2026
MatheusAndrade23 and others added 2 commits October 7, 2026 12:26
…ey header is valid

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rying keys on per-key broker errors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MatheusAndrade23
MatheusAndrade23 merged commit 4fddfb0 into main Oct 7, 2026
6 checks passed
@MatheusAndrade23
MatheusAndrade23 deleted the feature/tim-3596 branch October 7, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant