Remote Images & SSRF Defense
Rules, size limits, allowed image formats, and multi-layered SSRF defense for logos and user avatars.
The Open Graph Image Generator allows embedding remote brand logos (logo) and author avatars (avatar) directly into generated social cards.
Because fetching arbitrary user-supplied URLs introduces security risks, all remote asset requests pass through a hardened, fail-closed security gateway with strict limits and comprehensive Server-Side Request Forgery (SSRF) defenses.
Remote Asset Constraints
All remote images must satisfy the following technical constraints:
| Constraint | Limit | Violation Error Code |
|---|---|---|
| Protocol | HTTPS only (https://...). Unencrypted HTTP is prohibited. | remote_asset_blocked (422) |
| Port | Port 443 (Standard HTTPS only). Non-standard ports are blocked. | remote_asset_blocked (422) |
| Max File Size | 2,097,152 bytes (2 MB). Enforced via Content-Length and byte counting. | remote_asset_failed (422) |
| Allowed Formats | image/png, image/jpeg. (SVG, GIF, WebP are not supported). | remote_asset_failed (422) |
| Max Dimensions | 4,096 × 4,096 pixels (max 16,777,216 total pixels). | remote_asset_failed (422) |
| Fetch Timeout | 3,000 milliseconds (3 seconds). | upstream_timeout (504) |
| Max Redirects | 3 hops maximum. Redirect targets are re-evaluated against SSRF rules. | remote_asset_failed (422) |
Server-Side Request Forgery (SSRF) Defense
To prevent malicious actors from using the generator as an internal port scanner or proxy to access private cloud infrastructure, the safe fetch pipeline executes multi-layered checks prior to initiating any socket connection:
- DNS Resolution & IP Validation:
The host domain is resolved to its underlying IP addresses before connection. The IP is checked against comprehensive blacklists:
- RFC 1918 Private Ranges:
10.0.0.0/8,172.16.0.0/12,192.168.0.0/16. - Loopback Addresses:
127.0.0.0/8,::1. - Link-Local & Cloud Metadata:
169.254.0.0/16(including AWS/GCP/Azure instance metadata at169.254.169.254). - Carrier-Grade NAT & Shared:
100.64.0.0/10. - IPv6 Private & Link-Local:
fc00::/7,fe80::/10. - Broadcast & Multicast:
224.0.0.0/4,240.0.0.0/4,255.255.255.255.
- RFC 1918 Private Ranges:
- DNS Rebinding Prevention: The socket connection is bound specifically to the validated IP address, preventing time-of-check to time-of-use (TOCTOU) DNS rebinding attacks.
- Redirect Evaluation: HTTP 301, 302, 307, and 308 redirects are never followed blindly. Each redirect URL is parsed, its hostname re-resolved, and its target IP independently re-validated.
If any check fails, the request immediately terminates with HTTP 422 remote_asset_blocked.
Best Practices for Logos and Avatars
- Host on a CDN: Host logos on a reliable, public CDN (such as Cloudflare, AWS CloudFront, GitHub raw, or your production web domain).
- Square Aspect Ratio: For author avatars (
avatar), provide a square image (e.g. 256×256 or 512×512 px) for optimal circular clipping. - Transparent PNG for Logos: For company or project logos (
logo), use a high-resolution transparent PNG with tight bounding boxes. - Cache Friendly: Remote assets are cached in memory during image rendering. Ensure your origin CDN serves standard
Cache-Controlheaders.