Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

fix: webhooks + ssrf protection

Nevo David1e4c8dd5c4f7
diff --git a/apps/backend/src/api/routes/no.auth.integrations.controller.ts b/apps/backend/src/api/routes/no.auth.integrations.controller.ts
index 3f048937c..3ac67cb54 100644
--- a/apps/backend/src/api/routes/no.auth.integrations.controller.ts
+++ b/apps/backend/src/api/routes/no.auth.integrations.controller.ts
@@ -23,6 +23,7 @@ import {
} from '@gitroom/backend/services/auth/permissions/permission.exception.class';
import { RefreshIntegrationService } from '@gitroom/nestjs-libraries/integrations/refresh.integration.service';
import { OrganizationService } from '@gitroom/nestjs-libraries/database/prisma/organizations/organization.service';
+import { getSsrfSafeDispatcher } from '@gitroom/nestjs-libraries/dtos/webhooks/ssrf.safe.dispatcher';
@ApiTags('Integrations')
@Controller('/integrations')
@@ -277,6 +278,8 @@ export class NoAuthIntegrationsController {
apiKey: org.apiKey,
}),
}),
+ // @ts-ignore β€” undici option, not in lib.dom fetch types
+ dispatcher: getSsrfSafeDispatcher(),
});
} catch (err) {}
diff --git a/apps/orchestrator/src/activities/post.activity.ts b/apps/orchestrator/src/activities/post.activity.ts
index a3abc344e..cd7eefd82 100644
--- a/apps/orchestrator/src/activities/post.activity.ts
+++ b/apps/orchestrator/src/activities/post.activity.ts
@@ -17,6 +17,7 @@ import { RefreshIntegrationService } from '@gitroom/nestjs-libraries/integration
import { timer } from '@gitroom/helpers/utils/timer';
import { IntegrationService } from '@gitroom/nestjs-libraries/database/prisma/integrations/integration.service';
import { WebhooksService } from '@gitroom/nestjs-libraries/database/prisma/webhooks/webhooks.service';
+import { getSsrfSafeDispatcher } from '@gitroom/nestjs-libraries/dtos/webhooks/ssrf.safe.dispatcher';
import { TypedSearchAttributes } from '@temporalio/common';
import {
organizationId,
@@ -372,31 +373,46 @@ export class PostActivity {
@ActivityMethod()
async sendWebhooks(postId: string, orgId: string, integrationId: string) {
- const webhooks = (await this._webhookService.getWebhooks(orgId)).filter(
- (f) => {
- return (
- f.integrations.length === 0 ||
- f.integrations.some((i) => i.integration.id === integrationId)
- );
+ // Webhooks are best-effort and run after the post already published, so a
+ // failure here must not fail the workflow.
+ try {
+ const webhooks = (await this._webhookService.getWebhooks(orgId)).filter(
+ (f) => {
+ return (
+ f.integrations.length === 0 ||
+ f.integrations.some((i) => i.integration.id === integrationId)
+ );
+ }
+ );
+
+ if (webhooks.length === 0) {
+ return;
}
- );
- const post = await this._postService.getPostByForWebhookId(postId);
- await Promise.all(
- webhooks.map(async (webhook) => {
- try {
- await fetch(webhook.url, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify(post),
- });
- } catch (e) {
- /**empty**/
- }
- })
- );
+ const post = await this._postService.getPostByForWebhookId(postId);
+ await Promise.all(
+ webhooks.map(async (webhook) => {
+ try {
+ // webhook.url is validated at save time, but DNS can change
+ // between then and now - pin resolution like every other
+ // user-influenced outbound request.
+ await fetch(webhook.url, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify(post),
+ // @ts-ignore β€” undici option, not in lib.dom fetch types
+ dispatcher: getSsrfSafeDispatcher(),
+ });
+ } catch (e) {
+ /**empty**/
+ }
+ })
+ );
+ } catch (err) {
+ /**empty**/
+ }
}
@ActivityMethod()
async processPlug(data: {