Neutralize formula injection in the SQL manager CSV export by ManoharPaturi · Pull Request #43083 · PrestaShop/PrestaShop · GitHub
Skip to content

Neutralize formula injection in the SQL manager CSV export - #43083

Open
ManoharPaturi wants to merge 1 commit into
PrestaShop:developfrom
ManoharPaturi:sanitize-sql-manager-csv-export
Open

ManoharPaturi wants to merge 1 commit into
PrestaShop:developfrom
ManoharPaturi:sanitize-sql-manager-csv-export

Conversation

@ManoharPaturi

@ManoharPaturi ManoharPaturi commented Oct 4, 2026 •

Copy link
Copy Markdown
Questions Answers
Branch? develop
Description? See below
Type? improvement
Category? BO
BC breaks? no
Deprecations? no
How to test? See below
UI Tests This change does not touch any interface, so no UI test campaign was run.
Fixed issue or discussion? #43088
Related PRs
Sponsor company

Description

The SQL manager CSV export writes each cell value through fputcsv() without inspecting the content. When a query result cell begins with =, +, -, @, a tab or a carriage return, spreadsheet applications interpret the cell as a formula when the exported file is opened, which is the classic CSV injection pattern. PrestaShop already neutralizes this pattern in other export paths, and the published advisory about CSV injection in exports describes the same prefix set.

This change neutralizes leading formula characters in the SQL manager export by prefixing an apostrophe when a cell value starts with one of those characters, matching the approach used elsewhere in the project.

How to test

In the advanced parameters SQL manager, run a query returning a value that starts with =SUM(1+1) and export the result as CSV. Open the file in a spreadsheet application: the cell shows the literal text instead of evaluating a formula. Values without leading formula characters are unchanged.

Verified with php -l and by comparing fputcsv output for a matrix of cell values before and after the change: only cells with leading = + - @, tab or carriage return gain the apostrophe prefix.

Fixes #43088

@ManoharPaturi
ManoharPaturi requested a review from a team as a code owner October 4, 2026 02:21
Copilot AI balanced review requested due to automatic review settings October 4, 2026 02:21
@ps-jarvis ps-jarvis added the Bug fix Type: Bug fix label Oct 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ps-jarvis

Copy link
Copy Markdown

Hello @ManoharPaturi!

This is your first pull request on PrestaShop repository of the PrestaShop project.

Thank you, and welcome to this Open Source community!

@ManoharPaturi
ManoharPaturi changed the base branch from 9.2.x to develop October 4, 2026 02:33
@ManoharPaturi
ManoharPaturi requested a review from a team as a code owner October 4, 2026 02:33
@ps-jarvis ps-jarvis added Improvement Type: Improvement develop Branch and removed Bug fix Type: Bug fix labels Oct 4, 2026
ExportCsvFileWriter writes the rows of a SQL manager export into the CSV
file exactly as the database returned them. A saved request that selects
text written by a customer, such as a message or an address field, can
therefore place a value starting with =, +, -, @, a tab or a carriage
return into the file, and whoever opens the export in a spreadsheet
application executes it as a formula.

The streamed CSV exports already neutralize those leading characters in
CsvResponse::sanitizeRow. This applies the same policy to the file based
export path, on the title row and on every data row, so both export
components behave the same way.
@ManoharPaturi
ManoharPaturi force-pushed the sanitize-sql-manager-csv-export branch from 9442c75 to d9fef21 Compare October 4, 2026 02:39
@ManoharPaturi

Copy link
Copy Markdown
Author

Thank you for the pointers. The pull request is now based on develop, the description table is filled in, and a matching issue has been opened and linked in the description. Please let me know if anything else is needed.

@Hlavtox Hlavtox left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nonsense, formulas have nothing to do with CSV. CSV can be opened in a text editor.

@ps-jarvis ps-jarvis added the Waiting for author Status: action required, waiting for author feedback label Oct 6, 2026
@ManoharPaturi

Copy link
Copy Markdown
Author

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

Labels

develop Branch Improvement Type: Improvement Waiting for author Status: action required, waiting for author feedback

Projects

Status: Waiting for author

Development

Successfully merging this pull request may close these issues.

CSV export from the SQL manager can carry spreadsheet formulas

4 participants