Skip to content

Commit

Permalink
resolve 3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
slubwama committed Oct 1, 2024
1 parent f29296d commit 66eb999
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions omod/src/main/java/org/openmrs/web/servlet/QuickReportServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "error.null");
return;
}

if (!Context.hasPrivilege(PrivilegeConstants.GET_PATIENTS)) {
session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Privilege required: " + PrivilegeConstants.GET_PATIENTS);
session.setAttribute(WebConstants.OPENMRS_LOGIN_REDIRECT_HTTPSESSION_ATTR, request.getRequestURI() + "?"
Expand All @@ -70,6 +71,13 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
return;
}

reportType = sanitizeInput(reportType);

if (!isValidReportType(reportType)) {
session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "error.invalidReportType");
return;
}

try {
Velocity.init();
}
Expand Down Expand Up @@ -359,4 +367,16 @@ private String getTemplate(String reportType) {

return template;
}

private String sanitizeInput(String input) {
if (input == null) {
return null;
}
return input.replaceAll("[<>\"'%;()&+]", "");
}

private boolean isValidReportType(String reportType) {
return "RETURN VISIT DATE THIS WEEK".equals(reportType) || "ATTENDED CLINIC THIS WEEK".equals(reportType)
|| "VOIDED OBS".equals(reportType);
}
}

0 comments on commit 66eb999

Please sign in to comment.