Skip to content

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

Merged
ashishvijaywargiya merged 1 commit into
apache:trunkfrom
Krishnauprit18:improvement/view-rendering-optimization
Aug 14, 2026
Merged

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

Conversation

@Krishnauprit18

@Krishnauprit18 Krishnauprit18 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

This PR builds on PR #1586 and keeps the WidgetSecureLocation approach, adding two related changes in RequestHandler:

  1. View state persistence check (LAST_VIEW_NAME): Validates candidate last view names against ControllerConfig before they are stored in the session, so view navigation falls back cleanly.

  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());
}
@Krishnauprit18
Krishnauprit18 force-pushed the improvement/view-rendering-optimization branch from b2d3970 to e51fe34 Compare August 14, 2026 05:03
@Krishnauprit18
Krishnauprit18 force-pushed the improvement/view-rendering-optimization branch from e51fe34 to 5c68185 Compare August 14, 2026 05:56
@ashishvijaywargiya
ashishvijaywargiya merged commit 9ca27f4 into apache:trunk Aug 14, 2026
7 checks passed
ashishvijaywargiya pushed a commit to ashishvijaywargiya/ofbiz-framework that referenced this pull request Aug 14, 2026
…cation resolution (apache#1624)

This PR builds on [PR
apache#1586](Krishnauprit18:secure-widget-resource-loading) and keeps the
WidgetSecureLocation approach, adding two related changes in
RequestHandler:

1. View state persistence check (_LAST_VIEW_NAME_): Validates candidate
last view names against ControllerConfig before they are stored in the
session, so view navigation falls back cleanly.

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.

Thank you Krishna for the contribution.

(cherry picked from commit 9ca27f4)
ashishvijaywargiya pushed a commit to ashishvijaywargiya/ofbiz-framework that referenced this pull request Aug 14, 2026
…cation resolution (apache#1624)

This PR builds on [PR
apache#1586](Krishnauprit18:secure-widget-resource-loading) and keeps the
WidgetSecureLocation approach, adding two related changes in
RequestHandler:

1. View state persistence check (_LAST_VIEW_NAME_): Validates candidate
last view names against ControllerConfig before they are stored in the
session, so view navigation falls back cleanly.

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.

Thank you Krishna for the contribution.

(cherry picked from commit 9ca27f4)
ashishvijaywargiya added a commit that referenced this pull request Aug 14, 2026
…cation resolution (#1624) (#1653)

This PR builds on [PR
#1586](Krishnauprit18:secure-widget-resource-loading) and keeps the
WidgetSecureLocation approach, adding two related changes in
RequestHandler:

1. View state persistence check (_LAST_VIEW_NAME_): Validates candidate
last view names against ControllerConfig before they are stored in the
session, so view navigation falls back cleanly.

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.

Thank you Krishna for the contribution.

(cherry picked from commit 9ca27f4)

Co-authored-by: Krishna Uprit <125099508+Krishnauprit18@users.noreply.github.com>
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