Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
search_excerpt 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.
- create a node, enable search module, run cron, and search for a word in your article
- Compare the output of the snippet above in HEAD and with the patch applied. (You should see strongs wrapped around the keywords you searched for). 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
N/A
API changes
N/A
Comment | File | Size | Author |
---|---|---|---|
#5 | after-search.png | 121.24 KB | joelpittet |
#5 | before-search.png | 120.9 KB | joelpittet |
#2 | remove_or_document-2501747-2.patch | 890 bytes | chrisfromredfin |
Comments
Comment #1
chrisfromredfinComment #2
chrisfromredfinThe only tag that is expected to be in there is a strong, and it's put there via preg_replace. So we can run it through Xss:filter() instead rather than just assuming it safe.
Comment #3
joelpittetPerfect! Because the only tag that should be there is
strong
this is great. And it's checkplain'd right before.Comment #4
xjmNice -- this looks like an excellent solution.
Has this been tested manually? If so can we document it on the issue?
Comment #5
joelpittetAdded a couple pages with various HTML into the body of Article in full HTML filter.
Before:
After:
Comment #7
xjmExcellent, thanks for the manual testing with different markup in the content.
This issue is part of a critical task and is allowed per https://www.drupal.org/core/beta-changes. Committed and pushed to 8.0.x. Thanks @peezy, @joelpittet, and @cwells!