Skip to content

Improved: Enhance RequestHandler view state persistence and screen location resolution - #1624

Open
Krishnauprit18 wants to merge 1 commit into
apache:trunkfrom
Krishnauprit18:improvement/view-rendering-optimization
Open

Improved: Enhance RequestHandler view state persistence and screen location resolution#1624
Krishnauprit18 wants to merge 1 commit into
apache:trunkfrom
Krishnauprit18:improvement/view-rendering-optimization

Conversation

@Krishnauprit18

Copy link
Copy Markdown
Contributor

This PR builds upon PR #1586 by preserving WidgetSecureLocation architecture and introducing two Defense-in-Depth security add-ons in RequestHandler:

  1. View State Persistence Validation (_LAST_VIEW_NAME_): Validates candidate last view names against ControllerConfig policies before persisting them to the session, ensuring clean view navigation fallback.

  2. Parameter-Level Attribute Filtering (_LAST_VIEW_PARAMS_): Filters dynamic resource and location parameters (*Location, *Screen, *Template, *Uri) during session persistence and view-last attribute restoration.

Copilot AI lite review requested due to automatic review settings August 10, 2026 14:34
@Krishnauprit18 Krishnauprit18 changed the title Improved: Enhance RequestHandler view state persistence and screen lo… Improved: Enhance RequestHandler view state persistence and screen location resolution Aug 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR strengthens OFBiz widget and request handling security by hardening how screen locations are resolved and how “last view” state is persisted/restored from the session, aiming to reduce injection and unsafe resource/location override vectors.

Changes:

  • Introduces WidgetSecureLocation and uses it from ScreenFactory to sanitize component:// screen locations before resolution.
  • Enhances RequestHandler to validate _LAST_VIEW_NAME_ against controller policy (including auth requirements) and to filter out sensitive *Location/*Screen/*Template/*Uri parameters from session-persisted view state.
  • Tightens authentication requirements on specific view-maps in controller XMLs.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
framework/widget/src/main/java/org/apache/ofbiz/widget/model/WidgetSecureLocation.java Adds a centralized sanitizer for widget resource locations.
framework/widget/src/main/java/org/apache/ofbiz/widget/model/ScreenFactory.java Applies location sanitization before loading referenced screens.
framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java Validates/persists _LAST_VIEW_NAME_ and filters persisted/restored view parameters.
framework/common/webcommon/WEB-INF/portal-controller.xml Changes showPortalPage view-map to require auth.
applications/product/webapp/facility/WEB-INF/controller.xml Changes EditShipmentRouteSegments view-map to require auth.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +37 to +43
if (location.startsWith(COMPO_TYPE) && location.length() > 12) {
if (location.indexOf("..") > 0) {
Debug.logWarning(String.format("For security reason traversal sequence '..' is not allowed: [%s]", location), MODULE);
return null;
}
return COMPO_TYPE + Paths.get(location.substring(12)).normalize();
}
Comment on lines +202 to 205
if (sanitizedLocation == null) {
Debug.logWarning("The location of screen [%s] isn't an allowed Path. Abort rendering. Raw location [%s]", MODULE, name, location);
throw new IllegalArgumentException("Abort screen rendering due to unallowed screen location");
}
Comment on lines +1209 to +1215
Map<String, Object> sanitizedParamMap = new HashMap<>(paramMap);
sanitizedParamMap.keySet().removeIf(key -> key != null && (
key.endsWith("Location")
|| key.endsWith("Screen")
|| key.endsWith("Template")
|| key.endsWith("Uri")
));
Comment on lines +972 to 980
if (key != null && !key.startsWith("_")
&& !key.endsWith("Location")
&& !key.endsWith("Screen")
&& !key.endsWith("Template")
&& !key.endsWith("Uri")
&& !("_EVENT_MESSAGE_".equals(key) || "_ERROR_MESSAGE_".equals(key)
|| "_EVENT_MESSAGE_LIST_".equals(key) || "_ERROR_MESSAGE_LIST_".equals(key))) {
request.setAttribute(key, urlParamEntry.getValue());
}
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.

2 participants