Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magento Framework Escaper - Critical log with special symbols #13269

Closed
ihor-sviziev opened this issue Jan 19, 2018 · 26 comments
Closed

Magento Framework Escaper - Critical log with special symbols #13269

ihor-sviziev opened this issue Jan 19, 2018 · 26 comments
Assignees
Labels
Component: Framework/Escaper Fixed in 2.4.x The issue has been fixed in 2.4-develop branch good first issue Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Jan 19, 2018

Preconditions

  1. Magento 2.3.3

Steps to reproduce

Case 1

  1. Register a new customer from frontend;
  2. Created one order from frontend;
  3. Add & to store view name
  • Go to Admin >> Stores >> All Stores
  • Click on "Default Store View"
  • Change Name field to "Default & Store View"
  • Click "Save Store View" button
  1. Remove all log files from magento2/var/log directory (in order to have only needed logs)
  2. Go to Frontend >> [user name] >> My Account >> My Orders;
  3. Click on "View Order" link for our order that was created in step 2;
  4. See magento2/var/log directory;

Expected result

  1. No exception logs should be there

Actual result

  1. exception.log file appeared with one line:
[[2019-12-03 10:47:42] main.CRITICAL: DOMDocument::loadHTML(): Tag date invalid in Entity, line: 1 {"exception":"[object] (InvalidArgumentException(code: 2): DOMDocument::loadHTML(): Tag date invalid in Entity, line: 1 at /home/arthur/sites/magento/magento233/vendor/magento/framework/Escaper.php:89)"} []

Case 2

  1. Register a new customer from frontend;
  2. Created one order from frontend;
  3. Go to Admin->Sales->Orders;
  4. Click on the "View" link for our order that was created in step 2;
  5. In "Order Total" block add comment "&";
  6. Click on the "Submit Comment" button;
  7. Remove all log files from magento2/var/log directory (in order to have only needed logs)
  8. Go to Frontend >> [user name] >> My Account >> My Orders;
  9. Click on "View Order" link for our order that was created in step 2;
  10. See magento2/var/log directory;

Expected result

  1. No exception logs should be there

Actual result

  1. exception.log file appeared with one line:
[[2019-12-03 10:55:22] main.CRITICAL: DOMDocument::loadHTML(): Tag date invalid in Entity, line: 1 {"exception":"[object] (InvalidArgumentException(code: 2): DOMDocument::loadHTML(): Tag date invalid in Entity, line: 1 at /home/arthur/sites/magento/magento233/vendor/magento/framework/Escaper.php:89)"} []

Reason: On View order page in the admin we have "Purchased From" block.
image

This block uses \Magento\Framework\Escaper::escapeHtml with string that contains ampersand and allowed tags is "br". In this case it writes critical log. This issue appeared in Magento 2.2.0, it was introduced in 59c2c9e + df261e7 + 624ee86.

For someone who will fix this issue:
I prepared tests for this fix in my branch that are currently fails (not only this case):
2.2-develop...ihor-sviziev:escaper-critical-log-when-ampersand-is-present

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Jan 19, 2018
@magento-engcom-team
Copy link
Contributor

@ihor-sviziev, thank you for your report.
We've acknowledged the issue and added to our backlog.

@magento-engcom-team magento-engcom-team added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed and removed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release labels Jan 19, 2018
@oleksandr-butenko
Copy link

oleksandr-butenko commented Aug 13, 2018

hi
We have the same issue with comments in order.
The version of Magento is 2.2.5
Admin user can write an order comment with "&" for example.
Then, during load of the order page, we will have errors about using &.

Have you fixed this issue in one the next releases?
Maybe there is a patch to fix it?

Thanks.

@simonmaass
Copy link

have the same issue in 2.2.6

@TimQSO
Copy link

TimQSO commented Nov 27, 2018

Any news on this one? As this error floods our logfile.

@joris-ati4
Copy link
Member

joris-ati4 commented Dec 13, 2018

I just did some testing and the problem seems to come from the \Magento\Framework\Escaper::escapeHtml.

The line 74 should convert the data to htmlentities

$string = mb_convert_encoding($data, 'HTML-ENTITIES', 'UTF-8');

Edit: I just found in the documentation of mb_convert_encoding that it won't escape the following characters: ''', '"', '<', '>', or '&'. I will look at how this function evolved since 2.1.x

@dan-ding
Copy link

change:
$string = mb_convert_encoding($data, 'HTML-ENTITIES', 'UTF-8');
to:
$string = mb_convert_encoding(preg_replace('/&/', '&amp;', html_entity_decode($data)), 'HTML-ENTITIES', 'UTF-8');

in 2.3:

$string = mb_convert_encoding($data, 'HTML-ENTITIES', 'UTF-8');

in 2.2:

$string = mb_convert_encoding($data, 'HTML-ENTITIES', 'UTF-8');

i think will cover most cases. if there you have codepoints that html_entity_decode doesn't handle, then i think you'll need your own lookup table to replace that.

@ihor-sviziev
Copy link
Contributor Author

This issue was fixed in 2.3-develop branch in following commits:

Probably it will be included into release 2.3.1.

@ihor-sviziev ihor-sviziev added Fixed in 2.3.x The issue has been fixed in 2.3 release line Component: Framework/Escaper labels Dec 26, 2018
@ghost ghost closed this as completed Dec 27, 2018
@TimQSO
Copy link

TimQSO commented Jan 27, 2019

This ticket had been closed? It isn't the intention to fix this in 2.2?

@ihor-sviziev
Copy link
Contributor Author

(From #19884 (comment)):
This issue was fixed in 2.2-develop branch in following commits:

Probably it will be included into release 2.2.8.

@ihor-sviziev ihor-sviziev added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Mar 12, 2019
@robyerevan
Copy link

not fixed.
Reproduced in 2.3.1

@TimQSO
Copy link

TimQSO commented Dec 1, 2019

Also reproduced in 2.3.3

@ihor-sviziev
Copy link
Contributor Author

Hi @engcom-Alfa,
People still reporting that issue reproducing. Could you double check if this issue reproducing on 2.3-develop?

@ihor-sviziev ihor-sviziev reopened this Dec 1, 2019
@m2-assistant
Copy link

m2-assistant bot commented Dec 2, 2019

Hi @engcom-Alfa. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Alfa
Copy link
Contributor

@ihor-sviziev Unfortunately, we are not able to reproduce this issue on fresh 2.3-develop and 2.3.3 instances.

Manual testing scenario:

  1. Create order from frontend;

  2. Add & to store view name

  • Go to Admin >> Stores >> All Stores

  • Click on "Default Store View"

  • Change the Name field to "Default & Store View"

  • Click "Save Store View" button

  1. Remove all log files from magento2/var/log directory;

  2. Go to Admin >> Sales >> Orders >> Click to "View" for our order;

  3. See magento2/var/log directory;

Actual Result: No exceptions in the log file.

So, I have to close this issue.

Thank you!

@gerben86
Copy link

gerben86 commented Dec 2, 2019

@ihor-sviziev Unfortunately, we are not able to reproduce this issue on fresh 2.3-develop and 2.3.3 instances.

Manual testing scenario:

  1. Create order from frontend;
  2. Add & to store view name
  • Go to Admin >> Stores >> All Stores
  • Click on "Default Store View"
  • Change the Name field to "Default & Store View"
  • Click "Save Store View" button
  1. Remove all log files from magento2/var/log directory;
  2. Go to Admin >> Sales >> Orders >> Click to "View" for our order;
  3. See magento2/var/log directory;

Actual Result: No exceptions in the log file.

So, I have to close this issue.

Thank you!

Did you also check it with this instruction?: #13269 (comment)
Because that makes more sense then updating the name of the store.

@engcom-Alfa
Copy link
Contributor

@gerben86 Yes, of course. We also tested this scenario and no exceptions occurred. Thanks!

@TimQSO
Copy link

TimQSO commented Dec 2, 2019

@engcom-Alfa It can be reproduced by adding an order comment with just: "&". Same exception will show up in the logfile.

@engcom-Alfa engcom-Alfa reopened this Dec 2, 2019
@ghost ghost unassigned engcom-Alfa Dec 2, 2019
@engcom-Alfa engcom-Alfa self-assigned this Dec 2, 2019
@engcom-Alfa engcom-Alfa added Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed and removed Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line labels Dec 3, 2019
@ghost ghost unassigned engcom-Alfa Dec 3, 2019
@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Dec 3, 2019
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-Alfa
Thank you for verifying the issue. Based on the provided information internal tickets MC-29328 were created

Issue Available: @engcom-Alfa, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@arendarenko
Copy link
Contributor

I can confirm that issue is still happening on Magento 2.3.4

@ihor-sviziev
Copy link
Contributor Author

Hi @engcom-Alfa,
Looks like this issue was fixed in #25895
Could you double check if issue still there?

@ihor-sviziev
Copy link
Contributor Author

@magento give me 2.4-develop instance

@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev. Thank you for your request. I'm working on Magento 2.4-develop instance for you

@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, here is your Magento instance.
Admin access: https://i-13269-2-4-develop.instances.magento-community.engineering/admin_57d3
Login: 9d102703 Password: f7abb8f53530
Instance will be terminated in up to 3 hours.

@ihor-sviziev ihor-sviziev added the Fixed in 2.4.x The issue has been fixed in 2.4-develop branch label Mar 5, 2020
@ihor-sviziev ihor-sviziev self-assigned this Mar 5, 2020
@m2-assistant
Copy link

m2-assistant bot commented Mar 5, 2020

Hi @ihor-sviziev. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 2. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


@ihor-sviziev
Copy link
Contributor Author

I can confirm - the issue was fixed in 2.4-develop branch by following changes: #25895

I'm closing this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Framework/Escaper Fixed in 2.4.x The issue has been fixed in 2.4-develop branch good first issue Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests