Webhook icon
Schedule icon
WorkingDirectory icon
Script icon
Process icon
If icon
SlackIncomingWebhook icon
Request icon
Log icon
Loop icon

Guard User-Supplied URLs Against SSRF Before Fetching Them

Resolve and vet user-supplied URLs against SSRF rules, block private or off-allowlist targets with a Slack alert, fetch the rest, and publish the verdict.

Categories
Infrastructure

Anything that fetches a URL on behalf of a user - a webhook deliverer, an import job, an avatar fetcher - is a door into your internal network, and the dangerous part of the URL is rarely the string itself but where it resolves. This blueprint puts a guard in front of every fetch. The application POSTs the URL and its tenant to a keyed webhook, the guard resolves the hostname and judges it with the ipaddress module, a URL that fails any rule raises a Slack alert with the reason and the resolved IP, and a clean URL is fetched with a hard timeout. A disabled daily schedule sweeps a standing URL inventory through the same rules and counts what it blocks.

How it works

  1. on_url_submission (io.kestra.plugin.core.trigger.Webhook, keyed) receives a JSON body of url and tenant every time the application wants to retrieve a user-supplied URL.
  2. inventory_scan (io.kestra.plugin.core.trigger.Schedule, cron 0 6 * * *) is a disabled daily net that sweeps the URL inventory through the same rules; switch it on once the webhook path is trusted.
  3. guard_workspace (io.kestra.plugin.core.flow.WorkingDirectory) gives the whole chain one directory, so the rule module written once is reused and every inventory verdict line lands in one file.
  4. evaluate_url (io.kestra.plugin.scripts.python.Script on the Process runner) writes the ssrf_rules module, resolves the hostname with socket.getaddrinfo in a try/except, and denies non-http(s) schemes, private, loopback, link-local, and reserved ranges (10/8, 172.16/12, 192.168/16, 127/8, 169.254/16, ::1, fc00::/7), and hosts that match no allowlist suffix. It emits safe, reason, resolved_ip, and url through the repo outputs protocol.
  5. check_ssrf_verdict (io.kestra.plugin.core.flow.If) branches on safe == false. Blocked: alert_blocked_url (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) posts the tenant, the reason, and the resolved IP, and the alert is skipped when no URL was submitted so the schedule never raises an empty-target alarm. Clean: fetch_allowed_url (io.kestra.plugin.core.http.Request) fetches the URL with a hard timeout and allowFailed, then log_fetch_result records the status.
  6. scan_url_inventory (io.kestra.plugin.core.flow.Loop) walks the inline inventory one entry at a time, and check_inventory_entry runs each entry through the same module, appending one verdict line per entry to inventory-verdicts.ndjson.
  7. publish_verdict counts the blocked lines and combines them with the webhook verdict and the fetch status into verdict, blocked_count, resolved_ip, and reason, which the flow publishes as outputs.
  8. The errors block alerts Slack when the guard itself breaks, because a crashed guard must never read as an allowed URL.

What you get

  • SSRF vetting before any user-supplied URL is fetched: DNS resolution, denied range checks, scheme checks, and a suffix allowlist, all in one file your reviewers can read.
  • A Slack alert on every blocked URL naming the tenant, the reason, and the IP the hostname resolved to, so an attempted internal probe is visible while it is fresh.
  • A hard-timeout fetch of allow-listed URLs whose HTTP status feeds the final verdict instead of crashing the run.
  • verdict, blocked_count, resolved_ip, and reason as typed flow outputs for downstream checks and dashboards.
  • A daily inventory sweep, shipped disabled, that keeps a running count of blocked known targets.

Who it's for

  • Product teams that fetch user-supplied URLs for webhooks, imports, or profile images and need a defensible vetting step.
  • Security engineers who want SSRF rules in version control next to the orchestration instead of buried in application middleware.
  • Platform teams standardizing on one allowlist of host suffixes across every service that makes outbound requests.

Why orchestrate this with Kestra

SSRF guards usually live as a helper function in one service, so every other service re-implements them and the inventory nobody checks drifts out of date. Kestra puts the rules, the gate, the alert, the fetch, and the scheduled sweep into one versioned file: the blocked or allowed branch is declarative, every decision lands in execution history with its reason, and the disabled schedule adds a second pair of eyes over the inventory. A library call gives you a boolean and no memory.

Prerequisites

  • Python 3 on the Kestra worker for the Process runner, or switch the script tasks to a Docker task runner.
  • Outbound access from the worker to the hosts you intend to fetch.
  • The application POSTing a JSON body of url and tenant to the webhook URL.
  • A Slack incoming webhook for blocked-URL alerts and failure alerts.

Secrets

  • SSRF_WEBHOOK_KEY: key segment guarding the webhook URL, anyone holding it can submit URLs for vetting.
  • SLACK_WEBHOOK_URL: Slack incoming webhook URL for blocked-URL alerts and failure alerts.

Quick start

  1. Add both secrets to your Kestra namespace and set allowlist_domains to the host suffixes your integrations actually fetch.
  2. Point the application at /api/v1/{tenant}/executions/webhook/{namespace}/ssrf-guard-allowlist/{SSRF_WEBHOOK_KEY} with a body like {"url": "https://raw.githubusercontent.com/org/repo/main/file.json", "tenant": "acme"}.
  3. Confirm a clean run reports verdict: fetched, then POST http://169.254.169.254/latest/meta-data/ and confirm verdict: blocked, the Slack alert, and the metadata IP in resolved_ip.
  4. Enable inventory_scan once the webhook path is trusted and watch blocked_count track the inventory.

How to extend

  • Deny more ranges, for example carrier-grade NAT 100.64.0.0/10, by appending entries to DENIED_NETWORKS in the rule module.
  • Per-tenant allowlists: read the suffix list from the KV store instead of the input.
  • Make blocked requests fail hard with io.kestra.plugin.core.execution.Fail under the gate when the guard should be a stop, not a signal.
  • File an issue for every blocked URL with io.kestra.plugin.github.issues.Create in audited environments.
  • Re-resolve the host immediately before the fetch with a second evaluation task to close the DNS rebinding window.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.