Escape the download error alert message for JavaScript by ManoharPaturi · Pull Request #43082 · PrestaShop/PrestaShop · GitHub
Skip to content

Escape the download error alert message for JavaScript - #43082

Open
ManoharPaturi wants to merge 1 commit into
PrestaShop:developfrom
ManoharPaturi:escape-download-error-alert
Open

ManoharPaturi wants to merge 1 commit into
PrestaShop:developfrom
ManoharPaturi:escape-download-error-alert

Conversation

@ManoharPaturi

@ManoharPaturi ManoharPaturi commented Oct 4, 2026 •

Copy link
Copy Markdown
Questions Answers
Branch? develop
Description? See below
Type? improvement
Category? FO
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? #43087
Related PRs
Sponsor company

Description

In GetFileControllerCore::displayError() the error message is embedded into the JavaScript alert of the error page through Tools::displayError() output that is placed inside a single quoted JavaScript string context in the template. A message containing a single quote, a backslash or a closing script tag breaks out of that string and can inject script into the page when a translation or an error text contains such characters.

This change escapes the message for the JavaScript string context before it is passed to the template, so quotes, backslashes, angle brackets and line terminators are encoded and the message can never terminate the surrounding string or tag.

How to test

Trigger a download error (for example by requesting a file name that does not exist) and view the page source around the alert call: the message appears escaped. A message containing a single quote or a script tag renders inside the alert text instead of breaking the script context.

Verified with php -l and by rendering the error page with hostile message content under both the old and the new expression: the old output terminates the JavaScript string, the new output stays inside it.

Fixes #43087

Copilot AI balanced review requested due to automatic review settings October 4, 2026 02:21
@ManoharPaturi
ManoharPaturi requested a review from a team as a code owner October 4, 2026 02:21
@github-project-automation github-project-automation Bot moved this to Ready for review in PR Dashboard Oct 4, 2026
@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:32
@ManoharPaturi
ManoharPaturi requested a review from a team as a code owner October 4, 2026 02:32
@ps-jarvis ps-jarvis added Improvement Type: Improvement develop Branch and removed Bug fix Type: Bug fix labels Oct 4, 2026
The message shown in the alert of the virtual product download error page
was printed inside a JavaScript string literal without any escaping. A
translation containing a double quote, a closing tag or a backslash broke
the string and produced a syntax error on the page, and any markup placed
in a translation was interpreted as script by the browser.

The message and the redirect target are now encoded with json_encode
using the hex flags, so quotes, angle brackets and ampersands survive any
translation content.
@ManoharPaturi
ManoharPaturi force-pushed the escape-download-error-alert branch from ef05255 to 24c4b1b 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.

@ManoharPaturi

Copy link
Copy Markdown
Author

@LameuleFR LameuleFR left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, the JSON_HEX_* flags keep any translation inside the string literal and the <script> block.

Small thing: the description doesn't match the diff (the method is displayCustomError(), the alert used a double-quoted string, and Tools::displayError() isn't involved), worth fixing so the changelog is accurate.

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

Labels

develop Branch Improvement Type: Improvement

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

Download controller error message is not escaped for JavaScript

4 participants