Skip to content

WW-5879 Convention plugin: resolve dot segments and keep view lookups inside the result location - #2193

Open
sohankanna wants to merge 1 commit into
apache:mainfrom
sohankanna:WW-5879
Open

sohankanna wants to merge 1 commit into
apache:mainfrom
sohankanna:WW-5879

Conversation

@sohankanna

Copy link
Copy Markdown

Fixes WW-5879

When no result is configured, ConventionUnknownHandler builds a view path from the result location, the namespace, the action name and the result code. Until now it only collapsed repeated slashes, so . and .. in a namespace or action name went straight to ServletContext.getResource and the class loader, with nothing checking that the path stayed under /WEB-INF/content/.

Change

  • resolveDotSegments(path) collapses // and resolves . and ... It returns null for a path containing a backslash or one that would climb above its root.
  • resolveInsideResultLocation(path, resultLocation) returns the resolved path only if it is still inside the result location. It compares against location + "/", so /WEB-INF/content-private/ does not count as inside /WEB-INF/content.
  • Unknown action: handleUnknownAction now calls a new findResource(resultLocation, resultsByExtension, parts...), which skips any candidate that leaves the result location. The existing protected findResource(Map, String...) keeps its old behavior for subclasses.
  • Unknown result: every findResult call in handleUnknownResult goes through findResultInside(...), which resolves the path and checks it the same way. The resolved path is also what ends up in the generated result config.
  • determinePath is split into determineResultLocation plus the namespace append, so each lookup asks ConventionsService once and checks against the same location. That location honors per-package struts.convention.result.path (WW-5770).

Namespaces and action names without such segments resolve to exactly the same views as before (all existing tests are unchanged).

Testing

mvn -pl plugins/convention test: 99 run, 0 failures, 0 errors (ConventionUnknownHandlerTest: 16, of which 5 are new).

New tests in ConventionUnknownHandlerTest:

  • testResolveDotSegments
  • testResolveInsideResultLocation (including the sibling-prefix case)
  • testUnknownActionWithDotSegmentsInActionNameStaysInsideResultLocation
  • testUnknownActionWithDotSegmentsInNamespaceStaysInsideResultLocation (/ns/../other still finds /WEB-INF/content/other/page.jsp)
  • testUnknownResultWithDotSegmentsStaysInsideResultLocation

…the result location

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.

1 participant