Skip to content

Should we filter for SSRF by default? #968

Closed

Description

@jtojnar

SimplePie allows loading feeds from local files. If a malicious user can provide URI to fetch and the library consumer exposes raw data on error, it can lead to exfiltration of privileged information (e.g. /etc/passwd). This is also known as Server-Side Request Forgery.

Affected classes

  • I consider File class to be a low-level API mostly meant for SimplePie itself so it is probably should not be considered a security issue. It will be deprecated soon anyway.
  • On the other hand the SimplePie class is high-level API and as such, it would make sense for it to be safe-by-default (for example, we already escape every string for HTML-special characters by default).
  • The new PSR-18 wrappers are also low-level.

Severity

I am not that concerned, generally, only a trusted user should be able to provide the URL (citation needed, we do not have formal security model AFAIK). And even if a malicious user can inject a local URI, the file will most likely not parse as RSS, and the error message will not leak the content in recommended usage:

<?php

require_once __DIR__ . '/vendor/autoload.php';
$feed = new \SimplePie\SimplePie();
$feed->set_feed_url('/etc/passwd');
$feed->set_cache_duration(0);
$feed->init();
var_dump($feed->error()); // "/etc/passwd is invalid XML, likely due to invalid characters. XML error: Not well-formed (invalid token) at line 1, column 6601"
var_dump($feed->get_title()); // NULL
var_dump($feed->get_items()); // []

It would require something like the following:

var_dump($feed->get_raw_data()); // this would leak the data

Of course, there might be other ways to leak the data I am not aware of, which would make it more serious.

Problematic URIs

Local files (without URI scheme) as well as addresses like localhost or other private addresses.

At least SimplePie::set_feed_url() only allows http and https schemes and local files (with empty scheme).

$this->feed_url = $this->registry->call(Misc::class, 'fix_protocol', [$url, 1]);

return Misc::fix_protocol(Misc::compress_parse_url('http', $parsed['authority'], $parsed['path'], $parsed['query'], $parsed['fragment']), $http);

So PHP protocols/wrappers will not be an issue.

Possible solutions

We could add local IP and path allowlist and deny all URIs that resolve to local IPs/paths not allowed. It would be a BC break but having it opt-in would make it too easy to be insecure by accident.

Ideally, we would use https://github.com/j0k3r/httplug-ssrf-plugin but that would require switching from plain PSR-18 to HTTPlug. And it would probably be too involved for Composer-averse people.

Activity

  1. Alkarex commented on May 25, 2026

    @Alkarex
    Contributor

    Downstream PR:

    But we have a bunch of other PRs waiting to be merged, so waiting for them first, and then feel free to say whether there is interest.

  2. ziegenberg commented on Sep 23, 2026

    @ziegenberg
    Contributor

    We hit this issue from a different angle while implementing the switch to a PSR-18 client for SimplePie in Moodle.

    The issue, as written, focuses on the direct set_feed_url() vector, but the same vanilla configuration is also exploitable through feed autodiscovery candidate URLs, which the issue does not enumerate. Since that vector is arguably easier to reach (it does not require the attacker to control the configured feed URL, only the fetched page), I want to record it here.

    Disclaimer: This report was compiled with the help of AI.

    Autodiscovery candidate URL vector

    With the default SimplePie::LOCATOR_ALL (SimplePie::$autodiscovery) and a PSR-18 client set via set_http_client(), SimplePie::init() hands the client to the Locator when the fetched document is not itself a feed (see SimplePie\SimplePie::fetch_data()):

    $http_client = $this->get_http_client();
    if ($http_client instanceof Psr18Client) {
        $locate->set_http_client(
            $http_client->getHttpClient(),
            $http_client->getRequestFactory(),
            $http_client->getUriFactory()
        );
    }

    The Locator then requests every <link rel="alternate|feed">, <a> and <area> href parsed from the remote page. Unlike get_links() (which restricts schemes to https?|feed|'' before building the candidate lists), the autodiscovery path applies no scheme check — it only absolutises the href
    and fetches it (see SimplePie\Locator::search_elements_by_tag()):

    $href = $this->registry->call(Misc::class, 'absolutize_url',
        [trim($link->getAttribute('href')), $this->base]);
    ...
    $feed = $this->get_http_client()->request(Client::METHOD_GET, $href, $headers);

    An absolute file:// href survives absolutize_url() unchanged. Psr18Client::request() routes anything that is not http(s):// to requestLocalFile() and never invokes the injected PSR-18 client (SimplePie\HTTP\Psr18Client::request()):

    if (Misc::is_remote_uri($url)) {   // is_remote_uri() is only /^https?:\/\//i (Misc.php:63-66)
        return $this->requestUrl($method, $url, $headers);
    }
    return $this->requestLocalFile($url);

    requestLocalFile() runs is_readable() + file_get_contents() on the (possibly file://-prefixed) path and returns the content as a RawTextResponse. The discovered candidate is accepted because Locator::is_feed() treats any local file as a feed (SimplePie\Locator::is_feed()), and the acceptance condition at src/Locator.php:272 lets local responses through unconditionally:
    !Misc::is_remote_uri($feed->get_final_requested_uri()) || ($feed->get_status_code() === 200 …).

    So a single remote page someone subscribed to (or that a configured feed redirects to / is compromised) containing:

    <link rel="alternate" type="application/rss+xml" href="file:///etc/passwd">

    makes the server read an arbitrary readable local file. Content is exposed when it parses as XML/RSS (via the item APIs / get_raw_data()); for non-XML files, the read still happens server-side, and any path the process can read is in scope.

    Wider implications

    • Not limited to the direct URL vector. The autodiscovery path means the configured URL only needs to point at attacker-influenced HTML; the attacker does not need to control the feed URL itself.
    • Any PSR-18 boundary offers no protection. The Psr18Client performs its own local-file fallback before sendRequest() is ever called. A consumer that hardens its HTTP layer (URL allowlists, proxy filtering, a custom client that rejects non-HTTP(s) URIs) still cannot intercept these requests, because
      requestLocalFile() bypasses the injected client entirely. The abstraction gives a false sense of a network boundary.
    • Newly reachable for consumers migrating to 1.9. Consumers that previously relied on a curl-based FileClient (as Moodle did) had their requests proxied through the consumer's transport layer; swapping in a PSR-18 client changes which code actually issues the read with no change to SimplePie's external behaviour.

    Suggestion

    At minimum the autodiscovery candidate path should apply the same scheme restriction that get_links() already applies (https?|feed|''), and the local-file fallback in Psr18Client::request() (and by extension the equivalent path in FileClient) should be explicit opt-in rather than the default behavior.
    That keeps the legacy local-file feature available while making the safe default hold for everyone who does not ask for it.

    Happy to turn this into a patch if the scheme-filtering approach is welcome.

  3. ziegenberg commented on Sep 23, 2026

    @ziegenberg
    Contributor

    Hi @jtojnar,

    I created a fix. You might wanna release that sooner rather than later.

    Greetings,
    Daniel

  4. jtojnar commented on Sep 23, 2026

    @jtojnar
    MemberAuthor

    I am starting to think this might need to be handled by the consumer since they control the PSR-18 client. For example, if they pass GuzzleHttp\Client with redirects enabled, it would bypass our checks anyway. Maybe we should stop trying to do everything and just suggest a suitable library client can use like https://github.com/j0k3r/httplug-ssrf-plugin.

  5. ziegenberg commented on Sep 23, 2026

    @ziegenberg
    Contributor

    That would not help, cause SimplePie fetches lokal stuff before it even reaches any PSR18-client. Cause that's what I tried to do first and I realised I would need to override parts of SimplePie to fix it for good.

    See second bullet point of "Wider implications" in my first comment.

  6. ziegenberg commented on Oct 16, 2026

    @ziegenberg
    Contributor

    Any news on this?

  7. jtojnar commented on Nov 2, 2026

    @jtojnar
    MemberAuthor

    Looks like the redirect/autodiscovery part was assigned a CVE-2026-111234. In #994, I am dropping the support for fetching local files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions