Summary
Spatie Laravel Media Library versions before 11.23.0 contain a server-side request forgery (SSRF) vulnerability in the addMediaFromUrl() method, which allows user-controlled URLs to be fetched by the server.
An attacker can abuse this behavior to make the application issue arbitrary outbound HTTP requests, potentially targeting internal services or cloud metadata endpoints that are not directly reachable from the internet.
Affected context
This vulnerability arises in applications using Spatie Laravel Media Library where user input is passed directly or indirectly to addMediaFromUrl() in InteractsWithMedia.php.
It becomes relevant when:
- User-supplied URLs are accepted for adding media from remote locations.
- There is no strict allowlist, network segmentation, or URL validation applied before invoking
addMediaFromUrl(). - The application server has network access to internal services (e.g., internal APIs, databases with HTTP interfaces, admin panels, or cloud instance metadata endpoints).
In such deployments, the library can be leveraged as an HTTP client to pivot into internal or otherwise restricted network locations.
Exploit preconditions
- Attack surface: Application endpoints or flows that call
addMediaFromUrl()with data derived from user-controlled input (e.g., forms, APIs, file-upload dialogs that accept URLs). - Required access: Ability to submit or influence the URL parameter used by
addMediaFromUrl(); this can be unauthenticated or authenticated depending on how the host application exposes the feature. - Trigger point: A server-side call to
addMediaFromUrl()that performs an outbound HTTP request to the user-provided URL without sufficient validation or restriction. - Why exploitation is possible: The library trusts the supplied URL and forwards it to an HTTP client, allowing requests to arbitrary schemes, hosts, or IP addresses reachable from the server, including internal or non-public endpoints, without enforcing a safe network boundary.
Why this happens
The underlying bug class is server-side request forgery (SSRF), as described in CWE-918.
The addMediaFromUrl() method accepts URLs derived from user input and initiates outbound HTTP requests without adequately constraining the destination.
From an abstract perspective, this is an insecure pattern where:
- Untrusted input is directly embedded into a network request.
- There is no robust allowlist of permitted hosts or networks.
- URL-parsing and scheme/host validation either do not exist or are insufficient to prevent access to internal resources.
As a result, the application server becomes an unintended HTTP proxy capable of reaching targets that users cannot directly access.
Potential impact
- The application may be used to send HTTP requests to internal network services (e.g., internal APIs, admin dashboards, monitoring systems).
- Attackers could query cloud metadata services to retrieve credentials, tokens, or other sensitive configuration.
- Internal HTTP-based services can be probed for open ports, endpoints, or misconfigurations, aiding further attack chains.
- Sensitive data reachable over HTTP (status pages, diagnostics, configuration endpoints) may be exposed to remote attackers.
- If internal endpoints allow state-changing operations via HTTP, attackers could trigger unintended actions (e.g., configuration changes, job executions) through crafted requests.
General mitigation guidance
Effective mitigation centers on tightening trust boundaries for outbound HTTP requests and restricting URL inputs:
- Introduce a strict allowlist of permitted domains or hosts that
addMediaFromUrl()can contact, and enforce it before any request is issued. - Apply robust URL validation that:
- Resolves hostnames and rejects private, loopback, link-local, and non-routable IP ranges.
- Restricts to expected schemes (typically
http/https) and disallows others. - Implement network-level controls such as firewall rules, egress filters, or service meshes to prevent the application server from reaching sensitive internal or metadata addresses.
- Treat all URLs as untrusted input:
- Normalize and re-parse them server-side.
- Avoid passing user-supplied URLs directly into HTTP clients without sanitization or policy checks.
- Where possible, design the application to minimize reliance on user-provided remote URLs, preferring controlled upload mechanisms or curated sources.
How teams detect issues like this
Organizations can identify and monitor SSRF risks through a combination of code-centric and operational measures:
- Static analysis and code review:
- Search for usages of
addMediaFromUrl()and similar APIs that accept URLs from request parameters or user-controlled sources. - Flag patterns where URLs are passed directly from controllers, request DTOs, or form fields into outbound HTTP clients without validation.
- Review for absence of allowlists or IP range checks around outbound request construction.
- Security testing and fuzzing:
- Perform dynamic application security testing (DAST) using crafted URLs targeting internal IP ranges (e.g.,
127.0.0.1,169.254.169.254, RFC1918 ranges) to observe server behavior. - Use test environments with instrumented logging to detect unexpected internal or metadata requests.
- Policy and tooling:
- Enforce secure coding guidelines that prohibit direct use of untrusted URLs in HTTP clients.
- Leverage automated code review tools or CI hooks that identify SSRF patterns, particularly around media or file fetching functionality.

