fix(webhooks): block SSRF to localhost, link-local, and private IP addresses

Open
#29 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
58/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript

Research direction

Start with apps/api/src/webhooks/dto/create-webhook.dto.ts and apps/api/src/webhooks/webhooks.service.ts, focusing on createWebhook, testWebhook, and dispatch. Check how the project handles DNS lookup and IP range validation, then verify URL checks cover creation and immediately before requests. Done when unsafe protocols and resolved addresses are rejected and redirects cannot reach unvalidated destinations.

Written by the indexing model from the issue text.

Description

backend bug
Problem Description

In apps/api/src/webhooks/dto/create-webhook.dto.ts, CreateWebhookDto validates url using @IsUrl({ require_tld: false }) without restricting URL protocols or blocking internal/private network addresses.

This allows users to register webhook URLs pointing to localhost, 127.0.0.1, 169.254.169.254 (cloud metadata), or private IP ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, ::1, fc00::/7).
In apps/api/src/webhooks/webhooks.service.ts, both testWebhook and dispatch call fetch(endpoint.url) directly with no IP/protocol/DNS blocklist and follow redirects by default, enabling Server-Side Request Forgery (SSRF).


Expected Behavior
  1. Webhook URLs must only allow http: and https: protocols.
  2. Loopback, link-local (169.254.0.0/16), private RFC1918/IPv6, multicast, and unspecified (0.0.0.0) addresses must be blocked both on creation and after DNS resolution right before fetch(...).
  3. Redirects on outbound webhook fetch requests should be disabled (redirect: 'error') or re-validated against the same blocklist.

Where to Look
  • apps/api/src/webhooks/dto/create-webhook.dto.ts
  • apps/api/src/webhooks/webhooks.service.ts (createWebhook, testWebhook, dispatch)

Solution / Implementation Guide
  1. In CreateWebhookDto, update @IsUrl(...) to enforce protocols: ['http', 'https'] and require_protocol: true.
  2. Add an assertSafeWebhookUrl(rawUrl: string) helper in webhooks.service.ts (or a shared utility) that:
    • Parses the URL with new URL(rawUrl) and checks protocol === 'http:' || protocol === 'https:'.
    • Resolves the hostname via dns.lookup and rejects private, loopback, link-local, multicast, and reserved IPv4/IPv6 ranges.
  3. Call assertSafeWebhookUrl in createWebhook, testWebhook, and dispatch before fetch(...), and set redirect: 'error' in fetch options.
Dominant language
TypeScript
Stars
2
Forks
1
Avg merge
6m
Merged PRs (30d)
27

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sumamakhan761/tryinstance

All issues in sumamakhan761/tryinstance

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.