-
Notifications
You must be signed in to change notification settings - Fork 51.5k
fix(Stripe Trigger Node): Add Stripe signature verification #22764
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
base: master
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
4 issues found across 2 files
Prompt for AI agents (all 4 issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/nodes-base/nodes/Stripe/StripeTrigger.node.ts">
<violation number="1" location="packages/nodes-base/nodes/Stripe/StripeTrigger.node.ts:952">
P1: Rule violated: **Tests**
Add workflow or unit tests that cover both valid and invalid Stripe webhook signatures for the newly added verification logic to comply with the Community PR Guidelines testing requirement.</violation>
<violation number="2" location="packages/nodes-base/nodes/Stripe/StripeTrigger.node.ts:955">
P1: Rule violated: **Prefer Typeguards over Type casting**
Avoid narrowing the Stripe signature header with `as`; validate the value with a type guard before using it to satisfy the “Prefer Typeguards over Type casting” rule.</violation>
<violation number="3" location="packages/nodes-base/nodes/Stripe/StripeTrigger.node.ts:960">
P1: Rule violated: **Prefer Typeguards over Type casting**
Replace this `as` cast on the stored webhook secret with an explicit type guard so the secret is only treated as a string when it actually is one, per the “Prefer Typeguards over Type casting” rule.</violation>
<violation number="4" location="packages/nodes-base/nodes/Stripe/StripeTrigger.node.ts:991">
P1: Rule violated: **Prefer Typeguards over Type casting**
Do not cast the `events` parameter to `string[]` with `as`; narrow it using a runtime guard (e.g., check that the parameter is an array of strings) to comply with the “Prefer Typeguards over Type casting” rule.</violation>
</file>
Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR
| return {}; | ||
| } | ||
|
|
||
| const events = this.getNodeParameter('events', []) as string[]; |
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.
P1: Rule violated: Prefer Typeguards over Type casting
Do not cast the events parameter to string[] with as; narrow it using a runtime guard (e.g., check that the parameter is an array of strings) to comply with the “Prefer Typeguards over Type casting” rule.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/nodes-base/nodes/Stripe/StripeTrigger.node.ts, line 991:
<comment>Do not cast the `events` parameter to `string[]` with `as`; narrow it using a runtime guard (e.g., check that the parameter is an array of strings) to comply with the “Prefer Typeguards over Type casting” rule.</comment>
<file context>
@@ -948,9 +949,46 @@ export class StripeTrigger implements INodeType {
+ return {};
+ }
+
+ const events = this.getNodeParameter('events', []) as string[];
const eventType = bodyData.type as string | undefined;
</file context>
| return {}; | ||
| } | ||
|
|
||
| const webhookSecret = webhookData.webhookSecret as string | undefined; |
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.
P1: Rule violated: Prefer Typeguards over Type casting
Replace this as cast on the stored webhook secret with an explicit type guard so the secret is only treated as a string when it actually is one, per the “Prefer Typeguards over Type casting” rule.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/nodes-base/nodes/Stripe/StripeTrigger.node.ts, line 960:
<comment>Replace this `as` cast on the stored webhook secret with an explicit type guard so the secret is only treated as a string when it actually is one, per the “Prefer Typeguards over Type casting” rule.</comment>
<file context>
@@ -948,9 +949,46 @@ export class StripeTrigger implements INodeType {
+ return {};
+ }
+
+ const webhookSecret = webhookData.webhookSecret as string | undefined;
+ if (!webhookSecret) {
+ return {};
</file context>
| const webhookData = this.getWorkflowStaticData('node'); | ||
|
|
||
| const events = this.getNodeParameter('events', []) as string[]; | ||
| const stripeSignature = headerData['stripe-signature'] as string | undefined; |
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.
P1: Rule violated: Prefer Typeguards over Type casting
Avoid narrowing the Stripe signature header with as; validate the value with a type guard before using it to satisfy the “Prefer Typeguards over Type casting” rule.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/nodes-base/nodes/Stripe/StripeTrigger.node.ts, line 955:
<comment>Avoid narrowing the Stripe signature header with `as`; validate the value with a type guard before using it to satisfy the “Prefer Typeguards over Type casting” rule.</comment>
<file context>
@@ -948,9 +949,46 @@ export class StripeTrigger implements INodeType {
+ const webhookData = this.getWorkflowStaticData('node');
- const events = this.getNodeParameter('events', []) as string[];
+ const stripeSignature = headerData['stripe-signature'] as string | undefined;
+ if (!stripeSignature) {
+ return {};
</file context>
| async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> { | ||
| const bodyData = this.getBodyData(); | ||
| const req = this.getRequestObject(); | ||
| const headerData = this.getHeaderData(); |
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.
P1: Rule violated: Tests
Add workflow or unit tests that cover both valid and invalid Stripe webhook signatures for the newly added verification logic to comply with the Community PR Guidelines testing requirement.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/nodes-base/nodes/Stripe/StripeTrigger.node.ts, line 952:
<comment>Add workflow or unit tests that cover both valid and invalid Stripe webhook signatures for the newly added verification logic to comply with the Community PR Guidelines testing requirement.</comment>
<file context>
@@ -948,9 +949,46 @@ export class StripeTrigger implements INodeType {
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
const bodyData = this.getBodyData();
const req = this.getRequestObject();
+ const headerData = this.getHeaderData();
+ const webhookData = this.getWorkflowStaticData('node');
</file context>
|
E2E Tests: n8n tests failed after 10m 21.6s Run Details
Groups
This message was posted automatically by
currents.dev | Integration Settings
|
|
Found 1 test failure on Blacksmith runners: Failure
|
Summary
This PR implements proper Stripe webhook signature verification by validating the Stripe-Signature
header against the webhook secret using HMAC-SHA256. This ensures webhook authenticity and follows
Stripe's recommended verification process for incoming webhook events.
Related Linear tickets, Github issues, and Community forum posts
https://linear.app/n8n/issue/NODE-4018/missing-stripe-signature-verification
Review / Merge checklist
release/backport(if the PR is an urgent fix that needs to be backported)