Do not replace special chars with HTML entities #14550
Merged
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.
Description:
When searching for a contact via API with a where condition value with some special character like
'
then it won't find such contact even if it exists. The problem is that we "clean" the values inapp/bundles/ApiBundle/Controller/FetchCommonApiController.php
which is then mutating the values with
filter_var($value, FILTER_SANITIZE_SPECIAL_CHARS);
:https://github.com/mautic/mautic/blob/6.x/app/bundles/CoreBundle/Helper/InputHelper.php#L175
The PHP docs aren't describing what this does very well, but here's an explanation from GPT:
Since these values from the where API condition aren't going to be visible in any UI we don't need to worry about XSS. Another security issue could be SQL injection but that is handled by Doctrine when setting the values as parameters to the query builder which is happening here:
https://github.com/mautic/mautic/blob/6.x/app/bundles/CoreBundle/Entity/CommonRepository.php#L1600
So from the security point of view we are OK and there is no need to encode characters into HTML entities.
Steps to test this PR:
https://mautic-cloud.ddev.site/api/contacts?start=0&orderBy=id&minimal=true&where[0][col]=email&where[0][expr]=like&where[0][val]=contac%27t%
it should return the contact details but it is returning 0 contacts.Other areas of Mautic that may be affected by the change:
List of areas covered by the unit and/or functional tests:
'
in the first name can be found with API.