Problem/Motivation
Similar to Validating String Encodings Before Insert, a malicious user tried to change an sql query by manipulating the url of an ajax call which resulted in the following error:
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation '=': SELECT "name", "data" FROM "config" WHERE "collection" = :collection AND "name" IN ( :names__0 ); Array
(
[:collection] =>
[:names__0] => views.view.awards鎈'"\(
)
in Drupal\Core\Config\DatabaseStorage->readMultiple() (line 111 of /var/www/<site>/public/core/lib/Drupal/Core/Config/DatabaseStorage.php).
Steps to reproduce
To reproduce this, you can just hit this url: https:///views/ajax?view_name=awards鎈'"\(&view_display_id=page_1&_drupal_ajax=1
..and pass in some weird character with the view name (in this case the user passed in the view name 'awards' with some (chinese??) character and some other characters after it.
Proposed resolution
Validate the view_name inside ViewAjaxController::ajaxView() before Drupal tries to use it to load a config entity.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 3457963-validate-ajaxview-arguments.patch | 2.26 KB | devdits |
Issue fork drupal-3457963
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
ramil g commentedComment #3
ramil g commentedComment #5
devdits commentedThis patch can solve the problem until someone will create better solution.
Comment #6
devdits commentedComment #7
joelpittetAdded devdits and ramil g to issue credit
Comment #8
ramil g commentedComment #12
joelpittetComment #13
smustgrave commentedSeems to have a test failure so probably need test coverage for this one please
thanks!
Comment #14
tobiasbThere are more use-cases
/node/add/öüä,/media/add/öüä,admin/structure/views/view/öüä. So any config name.Comment #16
arunkumarkI updated the condition to check for a valid name and path in
ViewAjaxController.php. The view may be without a path(In case of blocks).Added new test cases for the Malicious strings in Name, Display Id, and Path.
Comment #17
smustgrave commentedPipeline failures
Comment #18
arunkumarkThe pipeline issue has been resolved.
Moving status to Review.
Comment #19
smustgrave commentedTest-only job runs without issue so tests still need work.
Comment #20
jannakha commentedhere's a solution to the underlying problem (which also solves #14)
https://www.drupal.org/project/drupal/issues/3475540
Comment #21
arunkumark@jannakha The suggested fix for ASCII is already added,
Comment #22
smustgrave commentedIf #3475540: Use a route requirement to prevent non-ASCII characters causing an exception when looking up a config entity solves more problems including this one this should probably be closed.
Comment #23
arunkumark@smustgrave
The handling in special character on #3475540: Use a route requirement to prevent non-ASCII characters causing an exception when looking up a config entity for Configuration settings. But here we patched for Ajax views links. Is the fix on Config will help for the Views URLs?