Repository navigation
Escape the download error alert message for JavaScript - #43082
ManoharPaturi wants to merge 1 commit into
Conversation
|
Hello @ManoharPaturi! This is your first pull request on PrestaShop repository of the PrestaShop project. Thank you, and welcome to this Open Source community! |
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.
ef05255 to
24c4b1b
Compare
|
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. |
There was a problem hiding this comment.
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.

Description
In
GetFileControllerCore::displayError()the error message is embedded into the JavaScript alert of the error page throughTools::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 -land 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