ffang commented on PR #3792:
URL: https://github.com/apache/cxf/pull/3792#issuecomment-7288428476

   > The DOM-side fix looks right. A few points:
   > 
   > **StAX path (`STSStaxTokenValidator`)**
   > 
   > 1. `checkOneTimeUse` still runs before `validateTokenToSTS`. That's true 
on the `alwaysValidateToSts` path and in the `verify()` fallback, so an 
assertion the STS rejects can still poison the replay cache. It should run only 
after STS validation succeeds, as in the DOM fix.
   > 2. The new `verifySubjectConfirmationMethod` / `checkAuthnStatements` / 
audience checks now run even when `alwaysValidateToSts=true`. With the 
defaults, unsigned bearer assertions the STS would accept are now rejected 
locally. DOM `STSTokenValidator(true)` does no local checks. Is this behaviour 
change intended?
   > 
   > **DOM path** 3. With `alwaysValidateToSts=true`, OneTimeUse is still never 
enforced, because the post-STS check is skipped by the `!alwaysValidateToSts` 
guard. This bug predates the PR, but it would be easy to fix here. 4. The 
`checkOneTimeUse` override only works because WSS4J calls it after 
`verifySignedAssertion`. That's true in 4.0.3, but it's worth a comment, or 
caching explicitly in `STSTokenValidator` instead, so a backport to an older 
WSS4J doesn't silently lose replay protection.
   > 
   > **Tests** 5. `testOneTimeUseNotCachedForUntrustedAssertion` only exercises 
`isValidatedLocally`. Nothing covers `validate()` → 
`checkOneTimeUseAfterSTSValidation` in either the STS-accept or STS-reject 
case. 6. `assertWrongAudienceRejected` passes on any `SOAPFaultException`. 
Please assert the cause, or add a positive control with a matching audience.
   
   Thanks @coheigea, all six points are addressed in c7a0c82314:
   
   **StAX path**
   1. With `alwaysValidateToSts`, `checkOneTimeUse` now runs only after 
`validateTokenToSTS` succeeds. Without it, the ID is still cached in 
`validate()`. By the time `STSStaxTokenValidator` is called, WSS4J 
(`SAMLTokenInputHandler`) has already verified the assertion's signature and 
the trust of its issuer. `verify()` only checks the trust of the subject's key, 
and it is only called when the token is used for a signature. Moving the check 
there would drop OneTimeUse for every other assertion. I added a comment 
explaining this.
   2. With `alwaysValidateToSts=true`, the StAX validator now matches DOM 
`STSTokenValidator(true)`: it only checks the validity period (no audience) and 
the schema/profile locally, and leaves the rest to the STS. The audience, 
AuthnStatement and subject confirmation checks now only run when the token is 
validated locally.
   
   **DOM path**
   3. Fixed. `STSTokenValidator.validate` now checks OneTimeUse once the 
assertion has been validated, either locally or by the STS. This covers 
`alwaysValidateToSts=true` too.
   4. I went with explicit caching. `STSSamlAssertionValidator.checkOneTimeUse` 
is now a no-op, and `STSTokenValidator` calls `checkOneTimeUseCondition` after 
validation. It no longer depends on the order in which WSS4J calls 
`checkOneTimeUse` and `verifySignedAssertion`.
   
   **Tests**
   5. `STSTokenValidatorTest` now goes through `validate()` with a stub STS. It 
covers the STS accepting the assertion (ID cached, replay rejected) and 
rejecting it (ID not cached, genuine assertion still accepted), with 
`alwaysValidateToSts` both on and off.
   6. `DOMToStaxSamlTest` now asserts the audience failure itself rather than 
any `SOAPFaultException`. It also has a positive control with a matching 
audience, which needs `ws-security.audience-restrictions` set explicitly 
because the local transport's default audiences don't include `local://Echo`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to