Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 UTC on 18 March 2024, to get $100 off your ticket.
Follow-up to #2501705: Remove SafeMarkup::set() in LinkGenerator and document SafeMarkup::set() in LinkGeneratorTest
Problem/Motivation
LinkGeneratorTest 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.
- 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
N/A
API changes
N/A
Comment | File | Size | Author |
---|---|---|---|
use_checkAdminXss.patch | 830 bytes | lokapujya | |
Comments
Comment #1
lokapujyaComment #2
joelpittetIt's in a test and
em
is a safe admin XSS tag so this seems very appropriate.Thank you @lokapujya
Comment #3
xjmSo, since this is a test, I looked at what the intent of the test is.
It was added in #2047619: Add a link generator service for route-based links to test the good old
'html' => TRUE
option, which, sensibly enough, got changed when we removed that in #2273923: Remove html => TRUE option from l() and link generator.. In that issue, both this unit test and the code it tests inLinkGenerator::generate()
we updated to useSafeMarkup::set()
. As @alexpott pointed out to me this morning, since this is a unit test, the correct thing to do with HEAD would actually be to keep the call. So, we would document this call instead based on that. Unit tests should test exactly the thing they're testing, notfilterXss()
which is not called by the tested method and therefore not something we should add to the unit test either.However, there's probably another issue for that
SafeMarkup::set()
call in theLinkGenerator
. Let's merge them, and either add a comment for this line of the test in that issue, or update it as appropriate.So, marking as a duplicate of #2501705: Remove SafeMarkup::set() in LinkGenerator and document SafeMarkup::set() in LinkGeneratorTest.
Comment #4
xjmAnd, titling correctly for posterity. :)