Repository navigation
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
Open
sohankanna wants to merge 1 commit into
sohankanna wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes WW-5884 (first step; the public interfaces are unchanged)
StrutsParameterAuthorizerandOgnlParameterAllowlisterderived 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
ParameterPath. It parses the name throughOgnlUtil.compile, so it uses the shared expression cache and the same tree OGNL evaluates.ASTProperty, or the name of anASTMethod.ASTChainchildren after the first, plus one when the first node is a method call. That keepsusers(1)at depth 1, as in the ticket's table and as the text derivation gave.[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,ParameterAllowlisterand the accepted-names pattern are unchanged. NewParameterPath-taking methods, deprecating theStringones, and shrinking the accepted-names pattern can follow, as the ticket suggests.OgnlUtilhas been injected (hand-built components),ParameterPathfalls back to the previous text-based derivation.Behavior
ParameterPathTest.agreesWithTheTextForNamesWithoutQuotedNestingCharacterscovers this.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, andmap['a.b'].cis still rejected at depth 1.StrutsParameterAnnotationTest.publicNestedPojoDepthTwo_bracket(publicPojoDepthTwo('key')('key')).ASTEval, which evaluates the result ofpublicPojoDepthTwo('key')as a further expression.StrutsParameterNodeGuardalready refusesASTEvalwhen 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".ParameterPathcould map anASTEvalto its first child's path plus one level. I left it out because it would authorize a node the binding path refuses.Testing
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.ParameterAuthorizerTestcases (4): quoted key at depth 1 and 2, no named root, unparsable name.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