Skip to content

WW-5884 Derive the root property and depth of a parameter name from its parsed OGNL expression - #2202

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

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

Conversation

@sohankanna

Copy link
Copy Markdown

Fixes WW-5884 (first step; the public interfaces are unchanged)

StrutsParameterAuthorizer and OgnlParameterAllowlister derived two security-relevant facts from the text of a parameter name: the root property (the text before the first ., [ or () and the nesting depth (the count of those characters). That only matches what OGNL evaluates because the accepted-names pattern forbids the cases where they differ. Since WW-5881 every bound name is parsed anyway, so this reads both facts from that tree instead.

Change

  • New package-private ParameterPath. It parses the name through OgnlUtil.compile, so it uses the shared expression cache and the same tree OGNL evaluates.
    • The root is the constant of the first non-indexed ASTProperty, or the name of an ASTMethod.
    • The depth is the number of ASTChain children after the first, plus one when the first node is a method call. That keeps users(1) at depth 1, as in the ticket's table and as the text derivation gave.
    • A name that does not parse, or does not start with a named property ([0].name, ['key'], a literal), yields no path.
  • StrutsParameterAuthorizer.isAuthorized: uses the path, and rejects a name without one (before, it rejected only a leading nesting character).
  • StrutsParameterAuthorizer.memberGuard: uses the path's depth, or the most restrictive depth when there is no path.
  • OgnlParameterAllowlister.primeAllowlistForPath: uses the path, and primes nothing without one.
  • ParameterAuthorizer, ParameterAllowlister and the accepted-names pattern are unchanged. New ParameterPath-taking methods, deprecating the String ones, and shrinking the accepted-names pattern can follow, as the ticket suggests.
  • When no OgnlUtil has been injected (hand-built components), ParameterPath falls back to the previous text-based derivation.

Behavior

  • For every name the default accepted pattern allows, the root and depth are the same as before. ParameterPathTest.agreesWithTheTextForNamesWithoutQuotedNestingCharacters covers this.
  • They differ only where nesting characters sit inside a quoted key. map['a.b'] is depth 1, as OGNL walks it, where the text derivation said 2. So a @StrutsParameter(depth = 1) map can now take such a key, and map['a.b'].c is still rejected at depth 1.
  • One existing test changes expectation: StrutsParameterAnnotationTest.publicNestedPojoDepthTwo_bracket (publicPojoDepthTwo('key')('key')).
    • OGNL does not parse that as two subscripts. It parses it as an ASTEval, which evaluates the result of publicPojoDepthTwo('key') as a further expression.
    • StrutsParameterNodeGuard already refuses ASTEval when the name is bound (WW-5881), so the name could not actually be set. Only the authorizer, counting parentheses in the text, called it "depth 2".
    • It is now rejected by the authorizer as well, and the test asserts that. If you'd rather keep accepting that syntax in the authorizer, ParameterPath could map an ASTEval to its first child's path plus one level. I left it out because it would authorize a node the binding path refuses.

Testing

  • New ParameterPathTest (7 tests): the ticket's examples, agreement with the text derivation, quoted keys, names without a named root, ASTEval, unparsable names, and the text fallback.
  • New ParameterAuthorizerTest cases (4): quoted key at depth 1 and 2, no named root, unparsable name.
  • Targeted run (ParameterPathTest, ParameterAuthorizerTest, OgnlParameterAllowlisterTest, ParametersInterceptorTest, ParameterMemberGuardTest, CookieInterceptor*Test): 165 run, 0 failures.
  • mvn -pl core test: 3,961 run, 0 failures, 0 errors.

🤖 Generated with Claude Code

…ts parsed OGNL expression

StrutsParameterAuthorizer and OgnlParameterAllowlister now take the root
property and nesting depth of a parameter name from the OGNL tree that
OgnlUtil.compile caches, instead of splitting the text at the first
'.', '[' or '(' and counting those characters. Names that do not parse,
or do not start with a named property, are rejected by the authorizer
and prime nothing. Public interfaces are unchanged.

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