Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double escaping bug #7552

Merged
merged 2 commits into from Apr 16, 2015
Merged

Fix double escaping bug #7552

merged 2 commits into from Apr 16, 2015

Conversation

mnapoli
Copy link
Contributor

@mnapoli mnapoli commented Mar 27, 2015

Fixes #7531

More explanation in #7531 (comment)

I've also edited the CustomAlerts plugin and made a new release.

@mnapoli mnapoli added Bug For errors / faults / flaws / inconsistencies etc. Needs Review PRs that need a code review labels Mar 27, 2015
@mnapoli mnapoli added this to the Piwik 2.13.0 milestone Mar 27, 2015
@mnapoli mnapoli force-pushed the double-escaping-bug branch 2 times, most recently from 8380e91 to 28c3cd1 Compare March 27, 2015 03:00
@mnapoli
Copy link
Contributor Author

mnapoli commented Mar 27, 2015

UI tests show it broke the highlighting of the current searched site…

@mnapoli mnapoli self-assigned this Mar 27, 2015
@mnapoli
Copy link
Contributor Author

mnapoli commented Mar 27, 2015

It turns out autocompletion highlighting is broken on master. Go on the demo and try to autocomplete sp and some HTML code shows up briefly. Same for la and other combinations.

I think the problem is that the current autocomplete doesn't clear previous highlighted stuff, so it keeps adding <span> tags again and again (nesting them), messing up the HTML.

What I suggest is to disable the autocompletion highlighting for now in this pull request and try to fix it later?

@diosmosis
Copy link
Member

(quoted from the other issue)

That being said what do we do? I'm guessing fixing #6714 is not gonna happen. Fixing 1. and 2. to bypass Twig's escaping could make sense but 1. is used by other JS components so making it non-escaped anymore might break something else…

Here's an idea for a simpler hack that doesn't require skipping escaping via twig/angular (I think that's what's going on in this pull request): For 1), maybe we can create a new global var that uses the correct, unescaped site name. And for 2) can we fix users of the sitename attribute? Do you think this would be a better solution?

@mnapoli
Copy link
Contributor Author

mnapoli commented Mar 29, 2015

A slight precision on what this PR is doing: escaping manually the sites returned by the HTTP API (in the Angular directive) so that they are over-escaped like the other variables. Then I can echo those variables in Angular by skipping escaping (because all of them are already escaped).

Does this mean they are double encoded? Or I guess escaped once so it can be just inserted in HTML? I don't know what over-escaped means.

Your suggestion is nice, except for the new global variable that duplicates the existing one, that's adding clutter and confusion. E.g. how do we name the new variable? siteRaw and siteNameRaw (I think both of these exist)? Reminds me a bit of mysql_real_escape_string() that fixes mysql_escape_string() :p But maybe that's still a better way so why not!

Maybe siteNameUnescaped? I was thinking the old variable could be deprecated (in some manner), and maybe put out of use eventually when angular is used more in the UI. Of course that's quite a long way away, and #6714 could be accomplished well before then, so I guess it doesn't really matter how this is solved right now :)

@mnapoli
Copy link
Contributor Author

mnapoli commented Mar 29, 2015

Answering @diosmosis's comments which for some reason ended up in my comment :)

Does this mean they are double encoded? Or I guess escaped once so it can be just inserted in HTML? I don't know what over-escaped means.

No basically they are fetched from the HTTP API not escaped, i.e. once in the Javascript variable (in the Angular directive) they are not escaped, which is correct (no reason for a value to be stored escaped). At that point I manually escape them, so they end up "escaped" in the javascript variable, which I call "over-encoded" because at that point there is no reason that they should be escaped.

I do that because all other variables are stored escaped in memory (which they shouldn't ideally, but…): that way everything is consistently escaped in memory.

So when the variable is echo'ed by Angular into the HTML, it is normally escaped first (by Angular) but I disable that (given variables are already all escaped).

Maybe siteNameUnescaped? I was thinking the old variable could be deprecated (in some manner), and maybe put out of use eventually when angular is used more in the UI. Of course that's quite a long way away, and #6714 could be accomplished well before then, so I guess it doesn't really matter how this is solved right now :)

Yep why not. As you said "I guess it doesn't really matter how this is solved right now" I agree :) I've already spent 2 days of work on this bug (which is kind of depressing) I'd rather leave it be with the currently implemented solution unless we think another solution is much better

@diosmosis
Copy link
Member

I'd rather leave it be with the currently implemented solution unless we think another solution is much better

I think it's a good solution that fixes the bug + introduces some consistency, so 👍 from me

@mattab
Copy link
Member

mattab commented Apr 1, 2015

@tsteur would you mind review this one and +1 if it's valid solution (and xss safe)?

@tsteur
Copy link
Member

tsteur commented Apr 7, 2015

I think it's XSS safe.

For a better understanding: Could the AngularJS part be also solved by using selectedSiteNameHtml here? https://github.com/piwik/piwik/pull/7552/files#diff-df586ad4d60f9625a811f797e5547ea6R33 then it should be safe I reckon.

Not sure how the SitesManager Controller change https://github.com/piwik/piwik/pull/7552/files#diff-d4d6201aa71999510eb45b144a549ef3R129 is related or whether it introduces any XSS. Couldn't find where it is used.

@@ -449,7 +449,7 @@ public function generateReport($idReport, $date, $language = false, $outputType
// render report
$description = str_replace(array("\r", "\n"), ' ', $report['description']);

list($reportSubject, $reportTitle) = self::getReportSubjectAndReportTitle(Site::getNameFor($idSite), $report['reports']);
list($reportSubject, $reportTitle) = self::getReportSubjectAndReportTitle(html_entity_decode(Site::getNameFor($idSite)), $report['reports']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should Piwik::unsanitizeInputValue be used instead of html_entity_decode?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 will do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsteur This part is to fix the double-escaping issues in scheduled reports (#7531)

@mnapoli
Copy link
Contributor Author

mnapoli commented Apr 7, 2015

@tsteur I have answered your comment in the code parts you mentionned

@mnapoli
Copy link
Contributor Author

mnapoli commented Apr 7, 2015

I have fixed the html_entity_decode and rebased to be able to merge.

@mnapoli mnapoli removed their assignment Apr 12, 2015
diosmosis added a commit that referenced this pull request Apr 16, 2015
Fix double escaping bug in site selector (when selecting site w/ special html chars, the name appears escaped). Includes small refactor to site selector, now instead of escaping selected site name on demand, site names are stored escaped in memory, and we bypass angular.js escaping. Also includes fix for related double encode bug in scheduled reports title.
@diosmosis diosmosis merged commit 8fec3c3 into master Apr 16, 2015
@diosmosis diosmosis deleted the double-escaping-bug branch April 16, 2015 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants