Problem/Motivation
Currently code does:
$escaped_separator = Xss::filterAdmin($this->options['separator']);
However this is problematic as that means a malicious admin user can essentially get e.g. '>' marked as safe with that.
While in this special case, probably '>' should be converted to > there are other cases where safe_join is called with something that needs to be safe and HTML.
So while it is of great convenience that functions like filterAdminXss call SafeMarkup::set() we still need to ensure that we never set e.g. something lower than 3 characters as safe and b) we should add an API function to SafeMarkup that can be called to escape something, but do _not_ mark it as safe.
Proposed resolution
- Add a SafeMarkup::filterSeparator function to take that task
- Possibly use the filterSeparator function from safe_join by default, so that no one inputs
as separator.
- Consider not marking safe any strings that are lower than 3 characters.
This is critical due to the security implications.
Remaining tasks
- Discuss solutions
User interface changes
TBD
API changes
TBD
| Comment | File | Size | Author |
|---|---|---|---|
| #22 | create-2383009-22.patch | 4.78 KB | jain_deepak |
| #14 | create-2383009-14.patch | 5.5 KB | cilefen |
| #14 | interdiff-11-14.txt | 962 bytes | cilefen |
| #11 | create-2383009-11.patch | 5 KB | cilefen |
| #11 | interdiff-9-11.txt | 898 bytes | cilefen |
Comments
Comment #1
chx commented> Consider not marking safe any strings that are lower than 3 characters.
Most excellent suggestion!
Comment #2
cilefen commentedThis is just a sketch.
Comment #4
cilefen commentedComment #5
dawehnerMh, so we add a dependency from a component into a drupal specific function, not sure whether this is right and it should not be the other way round. Move the code of twig_drupal_join_filter here
On top of that, it could be also helpful to write a dedicated test for it.
Comment #6
dawehner.
Comment #7
cilefen commentedComment #9
cilefen commentedComment #10
dawehnerWe should explain why would never be a problem: ... there is no single html tag which has less than 3 chars:
<b>... already needs 3Comment #11
cilefen commented@dawehner: Thank you for reviewing.
Comment #12
dawehnerGreat!
Comment #13
alexpottThis test would be neater and more maintainable as a provider / test combination. But we can do that in followup as the patch adds the necessary test coverage.
Unicode::strlen()? And should we not move this further up into SafeMarkup::set()?twig_drupal_join_filter()? Shouldn't that use this?Comment #14
cilefen commentedThis is Unicode::strlen() and calling SafeMarkup::filterSeparator() from twig_drupal_join_filter(). There is still a problem here: twig_drupal_join_filter() sets the whole string as safe even though SafeMarkup::filterSeparator() may have considered the separator unsafe (such as "<").
As for whether we should move this to SafeMarkup::set(), perhaps.
Another issue is that in the first place we had been and still are using Xss:filterAdmin(), which itself would replace a lone "<" even if that was the actual character desired for the separator. It isn't clear if we want to allow that.
Comment #16
cilefen commentedI suppose SafeMarkup::filterSeparator() could return an escaped string if less than 3 characters.
Comment #18
cilefen commentedComment #19
davidhernandezI cannot reproduce a problem. I created Views with separators and the separators were escaped properly, including greater than or less than signs.
Note that depending on how you view the source code of a page, the less than/greater than might get processed and displayed as symbol.
Comment #20
cilefen commentedXss::filterAdmin does not mark '>' as safe, it escapes it, and marks that as safe. I tested this against HEAD and '>' gets escaped. Can we close this?
Comment #21
subhojit777Comment #22
jain_deepak commentedRerolled
Comment #23
manningpete commentedComment #24
jibran#NW for #13.3
Comment #25
alexpottDicussed with @xjm, @webchick, @catch, @effulgentsia. Based on #19 and #20 and looking at
twig_drupal_join_filter()I think we can downgrade this issue.Leaving to @cilefen to confirm if this can be closed.
Comment #26
xjmComment #27
cilefen commentedFrom the summary:
Manual testing showed that partial tags as separators are escaped, and this is why:
Field separators are passed through
Xss::filterAdminwhich restricts the allowed tags to 'a', 'em', 'strong', 'cite', 'blockquote', 'code', 'ul', 'ol', 'li', 'dl', 'dt', 'dd' by callingXss:filterwhich in turn replaces offending partial tags.