[ 
https://issues.apache.org/jira/browse/WW-5761?focusedWorklogId=1056532&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1056532
 ]

ASF GitHub Bot logged work on WW-5761:
--------------------------------------

                Author: ASF GitHub Bot
            Created on: 22/Nov/26 16:49
            Start Date: 22/Nov/26 16:49
    Worklog Time Spent: 10m 
      Work Description: emilhuseyn commented on PR #2109:
URL: https://github.com/apache/struts/pull/2109#issuecomment-7082373312

   Thanks for the careful review. All seven points are addressed in 3c91f5087; 
with the flag off nothing changes.
   
   1. **Nested object also in the root** (`StrutsParameterMemberGuard` line 
65): the guard now judges only the root
      segment, the first member OGNL resolves on a root object. Once that 
member is authorized for the parameter's
      depth, the objects OGNL reaches through it are covered by that depth even 
when they also stand in the root. On the
      object the root segment was resolved on, a later member is still judged 
unless it is the same member again or the
      null handler's store (point 6). Tests: 
`testNestedObjectAlsoInTheRootBindsThroughItsAnnotatedGetter` and the
      unannotated-getter counterpart.
   2. **A `Map` lower in the root** (line 81): the first refused member now 
refuses the whole parameter. The guard stays
      refused for the rest of that parameter, and `CompoundRootAccessor` stops 
walking the root, in both `setProperty`
      and `getProperty`, once `SecurityMemberAccess.isParameterRefused()` is 
true. A `Map` further down therefore neither
      takes the value through `put()` nor hands out the root object through 
`get()`. I chose this over throwing from
      `isAccessible`, because `OgnlValueStack.handleRuntimeException` would 
then log every refused parameter at WARN with
      a stack trace. Tests: 
`testRefusedParameterIsNotBoundByAMapLowerInTheRoot`,
      `testRefusedRootIsNotTakenFromAMapLowerInTheRoot`.
   3. **Decapitalize** (line 120): the public-field lookup now decapitalizes 
`propertyName` the way `isAuthorized` does.
      Test: `testCapitalizedNameOfAnAnnotatedFieldBindsThroughItsSetter`.
   4. **Silent skip** (`ParametersInterceptor` line 341): 
`MemberAccessValueStack.useParameterMemberGuard` now returns
      whether the stack applies the guard (the default returns `false`, 
`OgnlValueStack` returns `true`). When the flag
      is on and the stack is not a `MemberAccessValueStack` or cannot apply the 
guard, the interceptor logs a one-time
      warning through `logWarningForFirstOccurrence`. I kept it a default 
method so existing custom stacks still compile.
   5. **Duplicate devMode notices** (line 77): because the guard refuses the 
whole parameter after the first refusal, the
      notice is emitted once per parameter. Test: 
`testRefusalIsReportedOnceInDevMode`.
   6. **Null handler** (line 93): the store now has to be a `set*` method with 
one parameter whose type is assignable
      from the root getter's return type, on the owner and property the root 
getter was resolved by. Test:
      `testNullHandlerStoreMustBeTheBeanSetterOfWhatTheGetterReturns`.
   7. **Package cycle**: `ParameterMemberGuard` moved to 
`org.apache.struts2.ognl`, next to `SecurityMemberAccess`, so
      `ognl` and `util` no longer import `interceptor.parameter`.
   
   One behaviour to flag: a root getter that returns the owner itself (say 
`getSelf()`) is still judged at the full
   depth on the next segment, since that is the object the root segment was 
resolved on. That is stricter than
   `isAuthorized`; happy to relax it if you prefer.
   
   `ParameterMemberGuardTest` now has 31 tests, 10 of them new; for points 1, 
2, 3, 5 and 6 I checked that undoing the
   fix makes its new test fail. The full `core` suite passes on JDK 21 (3,664 
tests, 0 failures, 2 skipped as before).
   




Issue Time Tracking
-------------------

    Worklog Id:     (was: 1056532)
    Time Spent: 50m  (was: 40m)

> Enforce @StrutsParameter on the member OGNL resolves during parameter binding
> -----------------------------------------------------------------------------
>
>                 Key: WW-5761
>                 URL: https://issues.apache.org/jira/browse/WW-5761
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Core
>            Reporter: Lukasz Lenart
>            Priority: Major
>             Fix For: 7.6.0
>
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> {{@StrutsParameter}} is enforced once, before OGNL runs: 
> {{StrutsParameterAuthorizer}} takes the parameter name and predicts which 
> accessor or field OGNL will go through, then checks that member for the 
> annotation. {{SecurityMemberAccess}}, which OGNL consults for every member it 
> actually touches, does not know about the annotation at all.
> Every time OGNL's resolution rules and the prediction drift apart, the 
> authorizer has to be taught again:
> * WW-5709: fluent (non-void) setters, which {{java.beans}} does not treat as 
> write methods but OGNL binds through
> * WW-5759: OGNL 3.4.14's JavaBeans-style accessor names ({{setuRange}} before 
> {{setURange}}), and getters whose {{java.beans}} property name differs from 
> the name OGNL reaches them by ({{getURL()}})
> The prediction is a hand-written copy of OGNL internals 
> ({{accessorBaseNames}}, set/is/get order, overload choice), so the next OGNL 
> change to name resolution needs the same follow-up.
> h3. Proposal
> Enforce the annotation where OGNL resolves the member, during parameter 
> binding only.
> Binding already runs on its own value stack 
> ({{ParametersInterceptor.toNewStack}}). Its {{SecurityMemberAccess}} already 
> receives binding-only settings ({{useAcceptProperties}} / 
> {{useExcludeProperties}} via {{MemberAccessValueStack}}). A binding mode on 
> that instance could require {{@StrutsParameter}} on the actual 
> {{Method}}/{{Field}} OGNL is about to use on the action, whatever name it was 
> reached by. The authorizer's prediction would remain a fast pre-check and 
> would no longer be the only gate.
> h3. Open design questions
> * *Depth*: {{isAccessible}} sees one member at a time, not its position in 
> the expression. The required {{depth}} of the root getter is known only to 
> the caller, so it has to be tracked per binding (e.g. the authorizer records 
> the authorized root and depth in the binding context).
> * *ModelDriven*: model members are exempt, so {{SecurityMemberAccess}} needs 
> to know which object is the model, by identity, as 
> {{StrutsParameterAuthorizer.resolveTarget}} already does.
> * *Paths that never call {{isAccessible}}*: Map-backed models and custom 
> {{PropertyAccessor}}s keep relying on the authorizer.
> * *Transition mode, {{ParameterNameAware}}, the JSON/REST deserialization 
> paths* (WW-5624) and {{CookieInterceptor}} (WW-5627) share 
> {{ParameterAuthorizer}} and need a consistent story.
> * *Cost*: an annotation lookup per member access during binding; cacheable 
> per {{Member}}.
> Fits 8.0.0 together with the other {{SecurityMemberAccess}} changes (WW-5678) 
> and the OGNL 3.5 upgrade (WW-5326).



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to