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

RA-1875: EMPT110 Fixed XSS Vulnerability in AppId field on User App Page #89

Merged
merged 2 commits into from
Apr 22, 2021

Conversation

The-Lady
Copy link
Contributor

Description of What I Changed

I encoded the AppId (entered by the user via AppId field) before it is referenced for further processing to prevent any XSS attacks.

Issue I Worked On

A script or an iframe could be injected in the AppId field while adding app definition. I encoded the AppId in the controller file before it was referenced for usage to prevent any XSS.

Steps to reproduce the vulnerability:

  1. Launch the OpenMRS application.
  2. Login with username "Admin" and password "Admin123" with location as Inpatient Ward.
  3. Click on the “System Administration” option.
  4. Click ‘Manage Apps’.
  5. Click ‘Add App Definition’.
  6. ln the App lD (required) field enter:</script><script>alert('XSS');</script>.
  7. Right click on the page and select ‘lnspect Element’.
  8. ln the ‘Search HTML’ panel of the lnspector tab, search for the HTML for the 'Save' button. Double-click on the ‘disabled=”disabled”’ text and delete hit, then press Enter to save the changes.
  9. Click on the Save button (which should now be clickable).

Output: A dialog box pops up with 'XSS' written on it.

Link to ticket

RA-1875

@isears

@@ -52,27 +53,28 @@ public void get(PageModel model, @RequestParam(value = "appId", required = false
public String post(PageModel model, @ModelAttribute(value = "appId") @BindParams UserApp userApp,
@RequestParam("action") String action,
@SpringBean("appFrameworkService") AppFrameworkService service, HttpSession session, UiUtils ui) {


String htmlSafeAppId = StringEscapeUtils.escapeHtml(userApp.getAppId());
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM! cc @isears

try {
AppDescriptor descriptor = mapper.readValue(userApp.getJson(), AppDescriptor.class);
if (!userApp.getAppId().equals(descriptor.getId())) {
if (!htmlSafeAppId.equals(descriptor.getId())) {
Copy link
Member

Choose a reason for hiding this comment

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

Is using the htmlSafeAppId here instead of the real appId strictly necessary to prevent XSS? (also on line 63)

If not, let's just use the real unescaped appId and only use the html-escaped app-id when it gets displayed in UI 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.

@isears I have restricted encoding of appId to just when error messages are displayed

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.

Great thanks for the update @The-Lady !

@isears isears merged commit 0410c09 into openmrs:master Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants