Skip to content

Conversation

@benjaminapetersen
Copy link
Contributor

@jwforres @spadgett

Fix bugzilla #1388043 link and #1388017 link
Fixes overly aggressive escaping to ensure error messages are readable. Example:

screen shot 2016-10-24 at 5 08 44 pm

// NOTE: these could all be moved out into a strings service.
var messages = {
errorReason: _.template('Reason: "<%- httpErr %>"'),
errorReason: _.template('Reason: "<%= httpErr %>"'),
Copy link
Member

@spadgett spadgett Oct 25, 2016

Choose a reason for hiding this comment

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

We shouldn't keep some plain text messages and some HTML markup messages in the same messages object. It's going to get too confusing to know when the message needs to be escaped. I'd create separate messages objects for alerts / html dialog messages. Or simply inline the messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seems reasonable. I def prefer not going back to inline, I'd rather keep making steps to getting the alert handling in a service, probably the text string templates in another service.

Copy link
Member

Choose a reason for hiding this comment

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

At some point, we'll need a message catalog for translation. If we really want to pull the messages out of the controllers anyway, we should start using the format we'll eventually need for translation. But let's not worry about that for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the difference, for reference:

Escaping error messages from server:
screen shot 2016-10-25 at 9 50 43 am

Not escaping messages from server:
screen shot 2016-10-25 at 9 51 16 am

Copy link
Member

Choose a reason for hiding this comment

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

Sure, we only want to HTML escape messages that will be passed as detailsMarkup to the dialog. But I have no way to know which is which just looking at the messages object with no context.

Copy link
Member

Choose a reason for hiding this comment

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

Note that the getErrorDetails filter is not guaranteed to return anything, so in some cases this could show Reason: with no content following it.

@spadgett spadgett self-assigned this Oct 25, 2016
@benjaminapetersen benjaminapetersen force-pushed the bug-1388043-membership-escape-characters branch from fd20f61 to ec69fdd Compare October 25, 2016 14:15
@benjaminapetersen
Copy link
Contributor Author

@spadgett updated, split into escaped and unescaped message sets.

showAlert('rolebindingCreate', 'success', messages.update.subject.success({
showAlert('rolebindingCreate', 'success', escaped.update.subject.success({
roleName: role.metadata.name,
subjectName: _.escape(newSubject.name)
Copy link
Member

Choose a reason for hiding this comment

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

Won't this double escape subjectName (here and repeated below)?

Copy link
Member

Choose a reason for hiding this comment

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

(You won't see this problem in the UI unless subjectName has special characters.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, true, removing the _.escape( on these as redundant.
Though, even just with the template escape sequence <<<bar still appears as:

screen shot 2016-10-25 at 12 09 53 pm

Copy link
Member

Choose a reason for hiding this comment

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

Right, we shouldn't HTML escape anything going into the alerts. Just messages passed as detailsMarkup to the dialog.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to make sure I'm with you, alerts still get user input text, I'm just removing the _.escape() in favor of using <%- in the templates, separating out the one template that processes server response with <%= (I could see this one being inline but would rather be consistent at this point).

Copy link
Member

@spadgett spadgett Oct 26, 2016

Choose a reason for hiding this comment

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

Any template that will display a plain text message in an alert should use <%=.

Any template that will display HTML content in a dialog should use <%- to escape the HTML. The only time you need this is if you use ng-bind-html like in the dialog.

You shouldn't need to use _.escape anywhere if you use <%- for the HTML messages.

@benjaminapetersen benjaminapetersen force-pushed the bug-1388043-membership-escape-characters branch from ec69fdd to 7e09995 Compare October 25, 2016 16:13
resetForm();
refreshRoleBindingList();
showAlert('rolebindingCreate', 'success', messages.update.subject.success({
showAlert('rolebindingCreate', 'success', escaped.update.subject.success({
Copy link
Member

Choose a reason for hiding this comment

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

This still doesn't seem right. The alerts should not have any escaped messages. Only dialogs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The alerts can still have text from user input, not just the dialogs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Bob" was given the role "view". "Bob" needs to be escaped, correct?

Copy link
Member

Choose a reason for hiding this comment

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

"Bob" was given the role "view". "Bob" needs to be escaped, correct?

No, Angular will escape any special characters you have in the string since the alerts use angular expressions.

https://github.com/openshift/origin-web-console/blob/master/app/views/_alerts.html#L22

We only need to escape values that we pass to ng-bind-html in the dialog.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I can update this. Something about it still bothers me, looking at the docs:

ngBindHTML:

Evaluates the expression and inserts the resulting HTML into the element in a secure way. By default, the resulting HTML content will be sanitized using the $sanitize service.

$sanitize:

Sanitizes an html string by stripping all potentially dangerous tokens.

Copy link
Member

Choose a reason for hiding this comment

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

It sounds like they strip things like <script> tags from the content, which is good. But if you have a user name with special characters like < and &, I suspect it won't render correctly.

errorReason: _.template('Reason: "<%= httpErr %>"')
};

var escaped = {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe messages and messagesWithMarkup?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, since the real issue here seems to be security, the word 'escaped' seems to be more descriptive if the specific problem we are trying to solve. If I came back in a month I may wonder "why do I care which ones have markup?" and would have to dig. The word 'escaped' immediately tells me this is important for security.

@benjaminapetersen
Copy link
Contributor Author

You can see all the places we are using templates in this screenshot:
screen shot 2016-10-31 at 1 36 05 pm
I think the latest including @spadgett's change (not squashed) is where we want this, should be good to go.

@spadgett
Copy link
Member

[merge]

@openshift-bot
Copy link

Evaluated for origin web console merge up to c9ee3a5

@openshift-bot
Copy link

[Test]ing while waiting on the merge queue

@openshift-bot
Copy link

Evaluated for origin web console test up to c9ee3a5

@openshift-bot
Copy link

Origin Web Console Test Results: SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin_web_console/611/) (Base Commit: d4becd8)

@openshift-bot
Copy link

openshift-bot commented Oct 31, 2016

Origin Web Console Merge Results: SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin_web_console/613/) (Base Commit: 05de64a)

@openshift-bot openshift-bot merged commit d3402a5 into openshift:master Oct 31, 2016
@benjaminapetersen benjaminapetersen deleted the bug-1388043-membership-escape-characters branch October 31, 2016 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants