-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tornando Webhook mais seguro com JWT token #1318
base: develop
Are you sure you want to change the base?
Tornando Webhook mais seguro com JWT token #1318
Conversation
Reviewer's Guide by SourceryThis pull request introduces JWT authentication for webhooks, enhances the Chat model with labels, adds a unique constraint to the Chat model, and includes deployment configuration files. Sequence diagram for Webhook JWT AuthenticationsequenceDiagram
participant Client
participant WebhookController
participant JWT
participant Webhook
Client->>WebhookController: Sends request to webhook URL with headers (including jwt_key)
activate WebhookController
WebhookController->>WebhookController: Checks for jwt_key in headers
alt jwt_key exists
WebhookController->>JWT: generateJwtToken(jwt_key)
activate JWT
JWT->>JWT: Sign payload with jwt_key using HS256
JWT-->>WebhookController: Returns JWT token
deactivate JWT
WebhookController->>WebhookController: Adds Authorization header with JWT token
WebhookController->>WebhookController: Removes jwt_key from headers
end
WebhookController->>Webhook: Sends request to webhook with updated headers (including Authorization)
activate Webhook
Webhook-->>WebhookController: Returns response
deactivate Webhook
WebhookController-->>Client: Returns response
deactivate WebhookController
Updated class diagram for Chat modelclassDiagram
class Chat {
instanceId: string
remoteJid: string
createdAt: DateTime
labels: string[]
}
note for Chat "Added labels attribute to Chat model"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
4b25e84
to
cee2bc4
Compare
Se possivel deixar esse tipo de autenticação opcional. Nem todo mundo vai usar. |
a autenticação só é aplicada se existir |
Ajuste os conflitos e lint por favor, estava para a branch main, o correto é para a develop, rode o compando |
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:
jsonwebtoken
para gerar o tokenjwt_key
dentro do campoheaders
da tabelaWebhooks
, 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: