-
Notifications
You must be signed in to change notification settings - Fork 230
Fix bug 1388043 #718
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 bug 1388043 #718
Conversation
| // NOTE: these could all be moved out into a strings service. | ||
| var messages = { | ||
| errorReason: _.template('Reason: "<%- httpErr %>"'), | ||
| errorReason: _.template('Reason: "<%= httpErr %>"'), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
fd20f61 to
ec69fdd
Compare
|
@spadgett updated, split into |
| showAlert('rolebindingCreate', 'success', messages.update.subject.success({ | ||
| showAlert('rolebindingCreate', 'success', escaped.update.subject.success({ | ||
| roleName: role.metadata.name, | ||
| subjectName: _.escape(newSubject.name) |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
ec69fdd to
7e09995
Compare
| resetForm(); | ||
| refreshRoleBindingList(); | ||
| showAlert('rolebindingCreate', 'success', messages.update.subject.success({ | ||
| showAlert('rolebindingCreate', 'success', escaped.update.subject.success({ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe messages and messagesWithMarkup?
There was a problem hiding this comment.
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.
Fixup HTML escaping in membership.js
|
You can see all the places we are using templates in this screenshot: |
|
[merge] |
|
Evaluated for origin web console merge up to c9ee3a5 |
|
[Test]ing while waiting on the merge queue |
|
Evaluated for origin web console test up to c9ee3a5 |
|
Origin Web Console Test Results: SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin_web_console/611/) (Base Commit: d4becd8) |
|
Origin Web Console Merge Results: SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin_web_console/613/) (Base Commit: 05de64a) |




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