Problem/Motivation
SearchExtraTypeSearch::execute() calls SafeMarkup::set() which is meant to be for internal use only.
Proposed resolution
- Remove the call by refactoring the code.
- If refactoring is not possible, thoroughly document where the string is coming from and why it is safe, and why SafeMarkup::set() is required.
Remaining tasks
- Evaluate whether the string can be refactored to one of the formats outlined in this change record: https://www.drupal.org/node/2311123
- Identify whether there is existing automated test coverage for the sanitization of the string. If there is, list the test in the issue summary. If there isn't, add an automated test for it.
- If the string cannot be refactored, the SafeMarkup::set() usage needs to be thoroughly audited and documented.
Manual testing steps (for XSS and double escaping)
Do these steps both with HEAD and with the patch applied:
- Clean install of Drupal 8.
- Install the
search_extra_typemodule - Go to
/search, click the "Dummy search type" tab, and enter<test> - Compare the output above in HEAD and with the patch applied. Confirm that there is no double-escaping.
- If there is any user or calling code input in the string, submit
alert('XSS');and ensure that it is sanitized.
User interface changes
None.
API changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 2502009-after.png | 230.37 KB | wim leers |
| #7 | 2502009-before.png | 212.74 KB | wim leers |
| #4 | interdiff.txt | 1.11 KB | joelpittet |
| #4 | remove_safemarkup_set-2502009-4.patch | 1.99 KB | joelpittet |
| #2 | remove_safemarkup_set-2502009-2.patch | 1.03 KB | star-szr |
Comments
Comment #1
star-szrComment #2
star-szrCompletely untested, letting testbot do the work for now.
Comment #4
joelpittetSo close, here's the other side that needs escaping because of the
=>returned from checkPlain'dprint_r(array(), TRUE)Comment #6
lauriiiThe IS is missing steps to reproduce..
Comment #7
wim leersFigured out the STR myself, added them to the IS.
Manually tested.
Comment #8
alexpottIf this was
'snippet' => "Dummy search snippet to display. Keywords: {$this->keywords}\n\nConditions: " . print_r($this->searchParameters, TRUE),instead it would still work because Twig auto-escape would just kick in. I think we should reserve SafeMarkup::format() for joining markup that needs to be marked safe together. Here the whole point is that you want the result checkplain-ed...That said... if it used
<br/>instead of\nyou'd need to use SafeMarkup::format... why are we using\n?But meh this is test code and generally a search snippet would need to be marked as safe (see search_excerpt) so let's proceed here. Committed d7ab90d and pushed to 8.0.x. Thanks!