Skip to content

Commit 7e9f93e

Browse files
committed
Fixed: Validate last view name input in RequestHandler to enhance security and prevent user manipulation
(cherry picked from commit d387aea)
1 parent 1a59fb1 commit 7e9f93e

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,10 @@ private void renderView(String view, boolean allowExtView, HttpServletRequest re
11711171
// add in the attributes as well so everything needed for the rendering context will be in place if/when we get back to this view
11721172
paramMap.putAll(UtilHttp.getAttributeMap(req));
11731173
UtilMisc.makeMapSerializable(paramMap);
1174-
// Used by lookups to keep the real view (request)
1175-
req.getSession().setAttribute("_LAST_VIEW_NAME_", paramMap.getOrDefault("_LAST_VIEW_NAME_", view));
1174+
// Used by lookups to keep the real view (request); accept the request parameter only if it is a safe view name (alphanumeric/dash/underscore)
1175+
String lastViewNameParam = (String) paramMap.get("_LAST_VIEW_NAME_");
1176+
String lastViewName = (lastViewNameParam != null && lastViewNameParam.matches("[\\w\\-]+")) ? lastViewNameParam : view;
1177+
req.getSession().setAttribute("_LAST_VIEW_NAME_", lastViewName);
11761178
req.getSession().setAttribute("_LAST_VIEW_PARAMS_", paramMap);
11771179

11781180
if ("SAVED".equals(saveName)) {

framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,11 +1483,8 @@ public void renderLookupField(Appendable writer, Map<String, Object> context, Lo
14831483
if (showDescription == null) {
14841484
showDescription = "Y".equals(visualTheme.getModelTheme().getLookupShowDescription());
14851485
}
1486-
// lastViewName, used by lookup to remember the real last view name
1487-
String lastViewName = request.getParameter("_LAST_VIEW_NAME_"); // Try to get it from parameters firstly
1488-
if (UtilValidate.isEmpty(lastViewName)) { // get from session
1489-
lastViewName = (String) request.getSession().getAttribute("_LAST_VIEW_NAME_");
1490-
}
1486+
// lastViewName, used by lookup to remember the real last view name; read only from session (set by RequestHandler) to prevent user input
1487+
String lastViewName = (String) request.getSession().getAttribute("_LAST_VIEW_NAME_");
14911488
if (UtilValidate.isEmpty(lastViewName)) {
14921489
lastViewName = "";
14931490
}

0 commit comments

Comments
 (0)