这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@jmmacdo4
Copy link
Contributor

@jmmacdo4 jmmacdo4 commented Mar 2, 2021

By adding cout to the error spans as well as adding htmlEscaping to the error div, I was able to remove the possibility for a cross site scripting attack on the implementation ID, Name, Passphrase, and Description fields.

@isears

<spring:bind path="implId.implementationId">
<td style="white-space: nowrap"><openmrs:message code="ImplementationId.implementationId"/><span class="required">*</span></td>
<td style="white-space: nowrap">
<input type="text" value="${status.value}" name="${status.expression}" maxlength="20" size="8"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

do we expect cross site scripting in such cases,ie on the input tag

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the input field is loaded in with data from the server initially. So if a script is stored on the server, it could be executed when loaded. That was my thought process, but it could be incorrect. What do you think @isears?

Copy link
Member

Choose a reason for hiding this comment

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

Are the patches in implementationIdForm.jsp still related to EMPT54? So far I've only been able to trigger XSS in the error messages that come up in headerFull.jsp but maybe I'm missing something.

Copy link
Member

@isears isears left a comment

Choose a reason for hiding this comment

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

@jmmacdo4 this is looking pretty good, I just want to take a little more time to make sure that turning on html filtering in headerFull.jsp doesn't break the UI elsewhere.

</c:if>
<c:if test="${err != null}">
<div id="openmrs_error"><openmrs:message code="${err}" text="${err}" arguments="${errArgs}" htmlEscape="false"/></div>
<div id="openmrs_error"><openmrs:message code="${err}" text="${err}" arguments="${errArgs}" htmlEscape="true"/></div>
Copy link
Member

Choose a reason for hiding this comment

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

@dkayiwa do you know why the htmlEscaping here was set to "false" originally? Can you think of anything in the legacy UI that would break by turning it on?

Copy link
Member

Choose a reason for hiding this comment

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

@jmmacdo4 unfortunately, there's at least one page that uses HTML tags in error messages (example). So turning on htmlEscaping in this header will break the error-display UI there and probably a few other places.

I think the best approach for EMPT54 is to patch in the controller by using a java html-escaping function to sanitize the error message when it gets passed to the response here.

The alternative is to comb through every call to setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "some-error-msg");, check to see if it's legitimately using HTML to format the error message, and then refactor it to not use that HTML somehow.

Feel free to reach out if you would like to discuss further. This issue may also be a good topic for next Friday's sync.

<input type="text" name="${status.expression}" value="${status.value}" size="40" />
<c:if test="${status.errorMessage != ''}">
<span class="error">${status.errorMessage}</span>
<span class="error">$<c:out value="${status.errorMessage}"/></span>
Copy link
Member

Choose a reason for hiding this comment

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

Was the $ character before the <c:out tag on this line left in on purpose?

Copy link
Contributor Author

@jmmacdo4 jmmacdo4 Mar 3, 2021

Choose a reason for hiding this comment

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

No, thanks for pointing that out, I will fix that on my next push.

</c:if>
<c:if test="${err != null}">
<div id="openmrs_error"><openmrs:message code="${err}" text="${err}" arguments="${errArgs}" htmlEscape="false"/></div>
<div id="openmrs_error"><openmrs:message code="${err}" text="${err}" arguments="${errArgs}" htmlEscape="true"/></div>
Copy link
Member

Choose a reason for hiding this comment

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

@jmmacdo4 unfortunately, there's at least one page that uses HTML tags in error messages (example). So turning on htmlEscaping in this header will break the error-display UI there and probably a few other places.

I think the best approach for EMPT54 is to patch in the controller by using a java html-escaping function to sanitize the error message when it gets passed to the response here.

The alternative is to comb through every call to setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "some-error-msg");, check to see if it's legitimately using HTML to format the error message, and then refactor it to not use that HTML somehow.

Feel free to reach out if you would like to discuss further. This issue may also be a good topic for next Friday's sync.

<spring:bind path="implId.implementationId">
<td style="white-space: nowrap"><openmrs:message code="ImplementationId.implementationId"/><span class="required">*</span></td>
<td style="white-space: nowrap">
<input type="text" value="${status.value}" name="${status.expression}" maxlength="20" size="8"/>
Copy link
Member

Choose a reason for hiding this comment

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

Are the patches in implementationIdForm.jsp still related to EMPT54? So far I've only been able to trigger XSS in the error messages that come up in headerFull.jsp but maybe I'm missing something.

@jmmacdo4
Copy link
Contributor Author

@isears I have updated the sanitization to be present in the controller.

On this note, I think it would be really easy to CTRL-F WebConstants.OPENMRS_ERROR_ATTR and add these escape utils to knock out a bunch of XSS vulnerabilities. Is this something we want to look into or talk about more on Friday?

@isears
Copy link
Member

isears commented Mar 18, 2021

On this note, I think it would be really easy to CTRL-F WebConstants.OPENMRS_ERROR_ATTR and add these escape utils to knock out a bunch of XSS vulnerabilities. Is this something we want to look into or talk about more on Friday?

@jmmacdo4 I'm warming up to the idea. It's possible that the example I cited above is the only thing you have to refactor.

If that's the case, what's your workaround for formatting that specific exception without using HTML tags?

@isears isears mentioned this pull request Mar 18, 2021
@jmmacdo4
Copy link
Contributor Author

jmmacdo4 commented Mar 25, 2021

@isears I have went ahead with the error div "redesign" we talked about. I have replaced all of the <br /> error messages with commas to allow us to turn htmlEscape to true. I tested a few of them out and it seems to be working okay.

@jmmacdo4 jmmacdo4 changed the title Add cout to legacy ui error div - EMPT 54 Sanitize HTML in legacyui error div to avoid XSS- EMPT 54 Mar 25, 2021
@isears
Copy link
Member

isears commented Mar 27, 2021

Going to close this in favor of #149

@jmmacdo4
Copy link
Contributor Author

This PR has been restructured in #151

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