fix(deps): update dependency phpoffice/phpspreadsheet to v1.29.2 [security] - autoclosed #607
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
1.25.2
->1.29.2
GitHub Vulnerability Alerts
CVE-2024-45048
Summary
Bypassing the filter allows a XXE-attack. Which is turn allows attacker to obtain contents of local files, even if error reporting muted by @ symbol. (LFI-attack)
Details
Check
$pattern = '/encoding="(.*?)"/';
easy to bypass. Just use a single quote symbol'
. So payload looks like this:If you add this header to any XML file into xlsx-formatted file, such as sharedStrings.xml file, then xxe will execute.
PoC
xl/sharedStrings.xml
file in edit mode.<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
tosharedStrings.xml
file and rename zip back to xlsx.http://%webhook%/file.dtd
Impact
Read local files
CVE-2024-45046
Summary
\PhpOffice\PhpSpreadsheet\Writer\Html
doesn't sanitize spreadsheet styling information such as font names, allowing an attacker to inject arbitrary JavaScript on the page.PoC
Example target script:
Save this file in the same directory:
book.xlsx
Open index.php in a web browser. An alert should be displayed.
Impact
Full takeover of the session of users viewing spreadsheet files as HTML.
CVE-2024-45060
Summary
One of the sample scripts in PhpSpreadsheet is susceptible to a cross-site scripting (XSS) vulnerability due to improper handling of input where a number is expected leading to formula injection.
Details
The following code in
45_Quadratic_equation_solver.php
concatenates the user supplied parameters directly into spreadsheet formulas. This allows an attacker to take control over the formula and output unsanitized data into the page, resulting in JavaScript execution.PoC
45_Quadratic_equation_solver.php
in a browserb
andc
, and enter the following fora
Impact
The impact of this vulnerability on the project is expected to be relatively low since these are sample files that should not be included when the library is used properly (e.g., through composer). However, at least two instances of popular WordPress plugins have unintentionally exposed this file by including the entire git repository. Since these files also serve as reference points for developers using the library, addressing this issue can enhance security for users.
A solution to fix the vulnerability is proposed below, and a request for a CVE assignment has been made to facilitate responsible disclosure of the security issue to the affected WordPress plugins.
Remediation
A quick and easy solution to prevent this attack is to force the parameters to be numerical values:
Thank you for your time!
CVE-2024-45291
Summary
It's possible for an attacker to construct an XLSX file that links images from arbitrary paths. When embedding images has been enabled in HTML writer with
$writer->setEmbedImages(true);
those files will be included in the output asdata:
URLs, regardless of the file's type. Also URLs can be used for embedding, resulting in a Server-Side Request Forgery vulnerability.Details
XLSX files allow embedding or linking media. When
In
xl/drawings/drawing1.xml
an attacker can do e.g.:And then, in
xl/drawings/_rels/drawing1.xml.rels
they can set the path to anything, such as:or
When the HTML writer is outputting the image, it does not check the path in any way. Also the
getimagesize()
call does not mitigate this, because whengetimagesize()
returns false, an empty mime type is used.PoC
Add this file in the same directory:
book.xlsx
Run with:
php index.php
Impact
When embedding images has been enabled, an attacker can read arbitrary files on the server and perform arbitrary HTTP GET requests, potentially e.g. revealing secrets. Note that any PHP protocol wrappers can be used, meaning that if for example the
expect://
wrapper is enabled, also remote code execution is possible.CVE-2024-45290
Summary
It's possible for an attacker to construct an XLSX file which links media from external URLs. When opening the XLSX file, PhpSpreadsheet retrieves the image size and type by reading the file contents, if the provided path is a URL. By using specially crafted
php://filter
URLs an attacker can leak the contents of any file or URL.Note that this vulnerability is different from GHSA-w9xv-qf98-ccq4, and resides in a different component.
Details
When an XLSX file is opened, the XLSX reader calls
setPath()
with the path provided in thexl/drawings/_rels/drawing1.xml.rels
file in the XLSX archive:setPath()
then reads the file in order to determine the file type and dimensions, if the path is a URL:It's important to note here, that
filter_var
considers alsofile://
andphp://
URLs valid.The attacker can set the path to anything:
The contents of the file are not made available for the attacker directly. However, using PHP filter URLs it's possible to construct an error oracle which leaks a file or URL contents one character at a time. The error oracle was originally invented by @hash_kitten, and the folks at Synacktiv have developed a nice tool for easily exploiting those: https://github.com/synacktiv/php_filter_chains_oracle_exploit
PoC
Target file:
Add this file in the same directory:
book.xlsx
Serve the PoC from a web server. Ensure your PHP memory limit is <= 128M - otherwise you'll need to edit the Python script below.
Download the error oracle Python script from here: https://github.com/synacktiv/php_filter_chains_oracle_exploit. If your memory limit is greater than 128M, you'll need to edit the Python script's
bruteforcer.py
file to changeself.blow_up_inf = self.join(*[self.blow_up_utf32]*15)
toself.blow_up_inf = self.join(*[self.blow_up_utf32]*20)
. This is needed so that it generates large-enough payloads to trigger the out of memory errors the oracle relies on. Also install the script's dependencies withpip
.Then run the Python script with:
Note that the attack relies on certain character encodings being supported by the system's
iconv
library, because PHP uses that. As far as I know, most Linux distributions have them, but notably MacOS does not. So if you're developing on a Mac, you'll want to run your server in a virtual machine with Linux.Here's the results I got after about a minute of bruteforcing:
Impact
An attacker can access any file on the server, or leak information form arbitrary URLs, potentially exposing sensitive information such as AWS IAM credentials.
CVE-2024-45292
Summary
\PhpOffice\PhpSpreadsheet\Writer\Html
does not sanitize "javascript:" URLs from hyperlinkhref
attributes, resulting in a Cross-Site Scripting vulnerability.PoC
Example target script:
Save this file in the same directory:
book.xlsx
Open index.php in a web browser and click on both links. The first demonstrates the vulnerability in a regular hyperlink and the second in a HYPERLINK() formula.
CVE-2024-45293
Summary
The security scanner responsible for preventing XXE attacks in the XLSX reader can be bypassed by slightly modifying the XML structure, utilizing white-spaces. On servers that allow users to upload their own Excel (XLSX) sheets, Server files and sensitive information can be disclosed by providing a crafted sheet.
Details
The security scan function in
src/PhpSpreadsheet/Reader/Security/XmlScanner.php
contains a flawed XML encoding check to retrieve the input file's XML encoding in thetoUtf8
function.The function searches for the XML encoding through a defined regex which looks for
encoding="*"
and/orencoding='*'
, if not found, it defaults to the UTF-8 encoding which bypasses the conversion logic.This logic can be used to pass a UTF-7 encoded XXE payload, by utilizing a whitespace before or after the
=
in the attribute definition.PoC
Needed:
Unzip the excel sheet, and modify the
xl/SharedStrings.xml
file with the following value (note the space afterencoding=
):Step-by-step
Resulting in:
When this file is parsed by the library, the value
abc
should be in the original filled cell.With the help of the PHP filter wrapper, this can be escalated to information disclosure/file read.
Impact
Sensitive information disclosure through the XXE on sites that allow users to upload their own excel spreadsheets, and parse them using PHPSpreadsheet's Excel parser.
Release Notes
PHPOffice/PhpSpreadsheet (phpoffice/phpspreadsheet)
v1.29.2
Compare Source
1.29.2 - 2024-09-29
Fixed
Changed
v1.29.1
: Security PatchCompare Source
1.29.1 - 2024-09-03
Fixed
v1.29.0
Compare Source
Added
toArray()
methods. PR #3494Changed
CellRange
andCellAddress
objects for therange
argument in therangeToArray()
method. PR #3494upDownBars
and subsidiary tags; these were previously ignored on read and hard-coded on write. PR #3515Deprecated
Removed
Fixed
v1.28.0
Compare Source
Added
Changed
toFormattedString
will now always return a string. This can affect the results oftoArray
,namedRangeToArray
, andrangeToArray
. PR #3304Deprecated
Removed
Fixed
v1.27.1
Compare Source
Added
Changed
Deprecated
Removed
Fixed
master
branch tomain
v1.27.0
Compare Source
Added
isEmpty()
methods PR #3315Changed
Deprecated
Removed
Fixed
v1.26.0
Compare Source
Added
load()
and Writersave()
methods1048576
and XFD) in ReferenceHelper PR #3213Changed
Deprecated
Removed
Fixed
_xlws
prefixed functions from Office365 Issue #3245 PR #3247__destruct()
calls PR #3092Configuration
📅 Schedule: Branch creation - "" (UTC), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.