Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
theme system
Priority:
Major
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
6 Jun 2015 at 17:42 UTC
Updated:
28 Jun 2015 at 03:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
tetranz commentedComment #2
tetranz commentedComment #3
tetranz commentedComment #4
tetranz commentedPatch #2 was calling checkPlain unnecessarily for URL.
Tidied up comments.
Comment #5
dawehner80 chars exceeded ... :(
Comment #6
star-szrThanks @tetranz!
SafeMarkup::format rather than SafeFormat::format.
Also this is now longer than 80 character so should be wrapped per https://www.drupal.org/node/1354#drupal.
Maybe you tried this but I don't think we can concatenate in the attributes like this. Can it be passed in as a @token as well?
Comment #7
star-szr@dawehner jinx :)
Comment #8
tetranz commentedFixed the comments.
Changed attributes to a @token for consistency although perhaps not strictly necessary.
Comment #9
tetranz commentedComment #10
tetranz commentedComment #11
star-szrGoing to review this again.
Comment #12
joelpittetI think we can do these
checkPlainremovals. It will likely still escape the value correctly under most conditions and the URL is already Url encoded.Example test:
Something like this likely needs to be added to a test in LinkGeneratorTest. To ensure we don't have " breaking the href attribute.
Comment #13
tetranz commentedThanks. That's a good point about the double quote in the URL. I think it might break it but I will do a test.
It will be a few days before I get back to this.
Comment #14
joelpittetThanks for letting us know. For now I'll unassign you until a few days and please grab it again if it's not been completed by then.
Comment #15
tetranz commentedI have tests which I will upload tomorrow night.
Comment #16
tetranz commentedThis is my first ever attempt at creating a test.
I'm not sure if I've done the right thing but I also added a test to UnroutedUrlAssemblerTest to show that the url encoding works correctly. I think I needed this to be sure that my mock for the assembler is valid in my new test in LinkGeneratorTest.
Comment #17
tetranz commentedI messed up the interdiff. I think #17 is better.
Comment #18
tetranz commentedComment #21
xjmI marked #2502035: Document SafeMarkup::set() in testGenerateWithHtml() as a duplicate of this issue, since I'm fairly certain that's test coverage for the lines we're changing here. Either we add a comment to the test to document why that call was appropriate, or we change the test so that it's testing the exact right thing for this issue.
Based on what the patch here is doing, I think that the intent of the test is still to ensure that the
$safe_textdoesn't get escaped a second time when it's already in the safe list, so I think theSafeMarkup::set()call in the test should still be retained and documented as an intentional unit test for the interaction between SafeMarkup and the LinkGenerator. See my comment on #2502035: Document SafeMarkup::set() in testGenerateWithHtml() for more background info.Meanwhile, couple of nitpicks I noticed while scanning this patch to decide what to do with the test:
Minor: there should be parens on method names in comments.
Minor: We should have a blank line between the one-line summary and the trst of the docs.
Comment #22
pwolanin commentedLet me re-roll this with those fixes.
Comment #23
pwolanin commentedI'm really not seeing why the added test case adds value. Certainly setting the url-encoded value as safe won't have an effect.
Also, href is just an attribute, so I think we can just more consistently manage it through the Attribute class.
Comment #25
pwolanin commentedtweak the code so href attribute is first.
Comment #26
xjmStill need the added inline comment on the existing
SafeMarkup::set()call inLinkGeneratorTest.Comment #27
xjmComment #28
pwolanin commentedSo, I don't see why the patch was calling SafeMarkup::set() in LinkGeneratorTest. My last patch doesn't have it.
Comment #29
xjm@pwolanin was a bit confused at my comments; we sorted it out in IRC. The added scope is to do with the existing
SafeMarkup::set()in HEAD in the test.Comment #30
pwolanin commentedadding the test change from: #2502035: Document SafeMarkup::set() in testGenerateWithHtml()
[edit] Oops - that wasy the wrong thing
Comment #31
pwolanin commentedFix comments in test and elsewhere.
Comment #34
pwolanin commentedComment #35
xjmYay, that! Thanks. +1.
Comment #36
akalata commentedThis patch removes one instance SafeMarkup::set, replacing it with SafeMarkup::format as part of a refactoring of how link item attributes (including the href) are generated.
There are also two new tests (one for external URLs and one for local) to ensure that the URL generator correctly escapes characters, and an update to an existing test to ensure that previously-sanitized output (for example, the text within the ) is not affected by the change. The use of SafeMarkup::set in this test case is properly documented.
I've updated the issue summary, and manually tested with both a menu link with HTML in the link text and double quotes in the URL, noting no change between HEAD and this patch.
Comment #37
xjmIt's great that we are able to get rid of two
checkPlain()and anescape()in addition to theset(). Given how frequently the LinkGenerator is used, this patch might actually make a slight dent in the callstack and memory overhead in addition to being security hardening.Thanks @akalata also for the excellent review.
I discussed this patch in IRC with @alexpott as well. I am somewhat cautious about the use of
SafeMarkup::format()to assemble HTML tags since used incorrectly it can give the illusion of sanitization while actually generating markup that is unsafe, but in this case it is safe, and it is internal enough to the core API that I think there is a low risk of contrib misusing the pattern seen here. The tag can only be<a>, the attributes are safely assembled with theAttributeclass, and the link content is also sanitized because it is used with an@placeholder.As a required part of a critical issue, this patch can be committed any time during the beta phase. Committed and pushed to 8.0.x. Awesome work!