I just tried to make an issue that described an encoding issue I was experiencing with a contrib module: #359265: Instance Titles improperly escaped. As part of this, I wanted to include the literal text as shown in the first couple of lines of http://drupal.org/files/issues/Picture%204_0.JPG
ie (double-spaced): W h o & # 0 3 9 ; s O n l i n e 1
However the preview showed this as : Who's Online 1
Fine, I figured I'd replace the & with an "& a m p ;", making the string:
W h o & a m p ; # 0 3 9 ; s O n l i n e 1
But this still showed : Who's Online 1
Eh? Is htmlspecialchars_decode() called _twice_ on the text? Maybe three?!?!
W h o & a m p ; a m p ; # 0 3 9 ; s O n l i n e 1
But that shows Who's Online 1
Uugugugh
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | filter_xss_entities-D6.patch | 977 bytes | lyricnz |
| #17 | filter-html-entities.patch | 1.82 KB | lyricnz |
| #15 | Preview | localhost.jpg | 40.24 KB | lyricnz |
| #12 | 359276-filter_xss_entities-11-d7.patch | 2.59 KB | Freso |
| #4 | filter_xss_entities.patch | 1013 bytes | heine |
Comments
Comment #1
lyricnz commentedPS: wrapping the HTML in <code> doesn't help :
Who's Online 1Comment #2
lyricnz commentedHere's a string that DOES deliver the right output
Who&#039;s Online 1That's
W h o & # 3 8 ; # 0 3 9 ; s O n l i n e 1
Comment #3
heine commentedThis is caused by filter_xss:
Comment #4
heine commentedRequires extremely thorough review.
Comment #5
damien tournoud commentedBumping all the way to D7.
Comment #6
heine commentedThis isn't right either.
Comment #7
david straussSubscribing.
Comment #8
heine commentedSlept on it, still makes sense.
Comment #9
c960657 commentedI think it looks good. Now neither of the first two preg_replace() calls can generate a substring that - together with any prefix or suffix - matches the following preg_replace patterns.
As an alternative approach, the lines visible in the patch can be replaced by a single preg_replace that uses a negative look-ahead assertion (the pattern for hexadecimal entities is modified to also allow characters with an odd number of digits, e.g.
Օ):$string = preg_replace('/&(?![a-z][a-z0-9]*;|#[0-9]+;|#x[0-9a-f]+;)/i', '&', $string);Comment #11
Freso commentedHere's the patch from #4 plus some unit testing of
filter_xss(). The third test/assert currently fails, but is fixed by the patch. I can't think of any things that should break by this patch (or I would've tested them :)), nor can I think of any XSS flaws that should be introduced by this. I'm not confident enough to RTBC it though. :)(Also, the tests probably need some touching up, so please do that. It would also be good with some more strings to test. E.g. with some HTML and stuff.)
Comment #12
Freso commentedD'oh. And the patch. -.-
Comment #13
catchThere's a bunch of XSS examples on this issue which never made it into the committed patch if that helps with test fodder - http://drupal.org/node/354812
Comment #15
lyricnz commentedIssue still exists with current D7 head (see screenshot)
Comment #16
lyricnz commentedImplementation aside, a more fundamental question is: what is the correct post-filter text for each of these cases?
Right now, you get what was in the previous screenshot. It feels like that HTML is safe as-is, so shouldn't be modified by filter_xss(), and so should appear on the page like:
(ie: no changes from filtering) but.... doesn't
Comment #17
lyricnz commentedHere's a patch that implements the actual change used in #4 and #12 above, along with a patch to the recently-committed filter module tests : #276597: TestingParty08: filter.module.
With this, the "Core Filters" test runs: 165 passes, 0 fails, and 0 exceptions
Comment #19
lyricnz commentedResubmtting, "test bot issues"
Comment #20
chx commentedI do not see anything immediately wrong in here... the code looks ok, the tests pass.
Comment #21
dries commentedAfter looking at the function for a while, I can't see anything wrong with this either. Committed it.
Comment #22
heine commentedPatch from #4 should apply to Drupal 6 with a 15 line offset.
Comment #23
heine commentedSorry, needs review
Comment #24
lyricnz commentedRerolled patch from #4 for D6 CVS (without the whitespace change). RTBC because it's the same as already committed to D7.
Comment #25
gábor hojtsyCommitted to Drupal 6 too, thanks. Bug applies to Drupal 5 too as said above.
Comment #26
marcingy commentedMarking as won't fix as d5 is end of life.