Tornando Webhook mais seguro com JWT token by victoreduardo · Pull Request #1318 · EvolutionAPI/evolution-api · GitHub
Skip to content

Tornando Webhook mais seguro com JWT token#1318

Merged
DavidsonGomes merged 3 commits intoEvolutionAPI:developfrom
victoreduardo:victoreduardos/jwt-webhook
May 10, 2025
Merged

Tornando Webhook mais seguro com JWT token#1318
DavidsonGomes merged 3 commits intoEvolutionAPI:developfrom
victoreduardo:victoreduardos/jwt-webhook

Conversation

@victoreduardo
Copy link
Copy Markdown
Contributor

@victoreduardo victoreduardo commented Mar 19, 2025

Objetivo:

Validar se a mensagem está sendo enviada por um remetente autentico, evitando que requisições maliciosas utilizem a URL para enviar informações fraudulentas. Para isso, ao enviar a requisição para a URL do webhook, adicionamos uma camada de autenticação utilizando JWT token. Para quem utiliza n8n, por exemplo, conseguirá adicionar a autenticação por JWT no webhook, protegendo-o de requisições maliciosas.

Mudanças:

  • instala a dependencia jsonwebtoken para gerar o token
  • Quando hover a chave jwt_key dentro do campo headers da tabela Webhooks, então utilizaremos essa key para gerar o JWT token e encaminha-lo via requisição.

Summary by Sourcery

Enhance webhook security by adding JWT authentication. This ensures that webhook requests originate from an authenticated source, preventing malicious requests and fraudulent information.

Enhancements:

  • Implement JWT token generation and validation for webhook requests, using a 'jwt_key' in the webhook headers to generate a JWT token and include it in the Authorization header.
  • Add labels to the chat model.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Mar 19, 2025

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @victoreduardo - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a configuration option for the JWT expiration time, instead of hardcoding it to 10 minutes.
  • The addition of the jsonwebtoken dependency should be noted in the description.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/api/integrations/event/webhook/webhook.controller.ts
@victoreduardo victoreduardo changed the title Tornando Webhook mais seguro com JWT Tornando Webhook mais seguro com JWT token Mar 19, 2025
@victoreduardo victoreduardo force-pushed the victoreduardos/jwt-webhook branch from 4b25e84 to cee2bc4 Compare March 19, 2025 21:04
@bergpinheiro
Copy link
Copy Markdown
Contributor

Se possivel deixar esse tipo de autenticação opcional. Nem todo mundo vai usar.

@victoreduardoss
Copy link
Copy Markdown

victoreduardoss commented Mar 20, 2025

Se possivel deixar esse tipo de autenticação opcional. Nem todo mundo vai usar.

a autenticação só é aplicada se existir jwt_key dentro de headers. Mesmo gerando a autenticação, ela só será utilizada se o destinatário (webhook URL) estiver habilitado para verificar a autenticação.

@DavidsonGomes DavidsonGomes changed the base branch from main to develop March 26, 2025 12:58
@DavidsonGomes
Copy link
Copy Markdown
Collaborator

Ajuste os conflitos e lint por favor, estava para a branch main, o correto é para a develop, rode o compando npm run lint

@victoreduardo
Copy link
Copy Markdown
Contributor Author

@DavidsonGomes DavidsonGomes merged commit d1a28ea into EvolutionAPI:develop May 10, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants