This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-wss4j.git
The following commit(s) were added to refs/heads/master by this push:
new 25b31d099 Cache a OneTimeUse SAML Assertion ID only once the Assertion
is trusted (#772)
25b31d099 is described below
commit 25b31d099db6e25198118b178588b9b24e2bca78
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Fri Nov 6 07:17:37 2026 +0000
Cache a OneTimeUse SAML Assertion ID only once the Assertion is trusted
(#772)
---
THREAT-MODEL.md | 11 ++++
.../wss4j/dom/validate/SamlAssertionValidator.java | 10 ++-
.../apache/wss4j/dom/saml/SamlNegativeTest.java | 76 ++++++++++++++++++++++
.../stax/validate/SamlTokenValidatorImpl.java | 12 ++--
4 files changed, 102 insertions(+), 7 deletions(-)
diff --git a/THREAT-MODEL.md b/THREAT-MODEL.md
index 1d649457a..a2dbd3533 100644
--- a/THREAT-MODEL.md
+++ b/THREAT-MODEL.md
@@ -508,6 +508,17 @@ on each is captured in §14 Q10–Q11.
SAML2 `OneTimeUse` condition.
- **Violation symptom**: an inbound envelope identical to one already
accepted within the TTL window is accepted again.
+- **Ordering**: an identifier is cached only once the token it belongs to
+ has been validated — a UsernameToken once its password verifies, a
+ Timestamp/Signature pair once the signature verifies, and a OneTimeUse
+ assertion once its signature verifies and its signing key is trusted.
+ Caching earlier would let anyone who knows a genuine token's identifier
+ get it rejected as a replay by sending a forged token with the same one.
+- **Residual**: an *unsigned* OneTimeUse assertion (e.g. sender-vouches) has
+ no signature of its own to check, so its ID is cached before the message
+ signature that is meant to cover it has been checked. An attacker who knows
+ the ID of a genuine unsigned assertion can therefore get it rejected. That
+ is denial of service against a single assertion, not an accepted replay.
- **Severity**: **security-critical**, `VALID` per §13.
- *(documented: `src/site/asciidoc/config.adoc` §"Non-boolean configuration
tags" — `NONCE_CACHE_INSTANCE`, `TIMESTAMP_CACHE_INSTANCE`,
diff --git
a/ws-security-dom/src/main/java/org/apache/wss4j/dom/validate/SamlAssertionValidator.java
b/ws-security-dom/src/main/java/org/apache/wss4j/dom/validate/SamlAssertionValidator.java
index 0858039e9..a3c167936 100644
---
a/ws-security-dom/src/main/java/org/apache/wss4j/dom/validate/SamlAssertionValidator.java
+++
b/ws-security-dom/src/main/java/org/apache/wss4j/dom/validate/SamlAssertionValidator.java
@@ -118,9 +118,6 @@ public class SamlAssertionValidator extends
SignatureTrustValidator {
// Check the AuthnStatements of the assertion (if any)
checkAuthnStatements(samlAssertion);
- // Check OneTimeUse Condition
- checkOneTimeUse(samlAssertion, data);
-
// Validate the assertion against schemas/profiles
validateAssertion(samlAssertion);
@@ -128,6 +125,13 @@ public class SamlAssertionValidator extends
SignatureTrustValidator {
if (samlAssertion.isSigned()) {
verifySignedAssertion(samlAssertion, data);
}
+
+ // Check OneTimeUse Condition. This must come last, as it caches the
Assertion ID: caching it
+ // before the Assertion has been validated would let an attacker
poison the cache with an
+ // Assertion (e.g. one signed by an untrusted key) that carries the ID
of a genuine one, so
+ // that the genuine Assertion is subsequently rejected as a replay.
+ checkOneTimeUse(samlAssertion, data);
+
return credential;
}
diff --git
a/ws-security-dom/src/test/java/org/apache/wss4j/dom/saml/SamlNegativeTest.java
b/ws-security-dom/src/test/java/org/apache/wss4j/dom/saml/SamlNegativeTest.java
index c18c967d9..449a46d21 100644
---
a/ws-security-dom/src/test/java/org/apache/wss4j/dom/saml/SamlNegativeTest.java
+++
b/ws-security-dom/src/test/java/org/apache/wss4j/dom/saml/SamlNegativeTest.java
@@ -31,6 +31,8 @@ import org.apache.wss4j.dom.engine.WSSConfig;
import org.apache.wss4j.dom.engine.WSSecurityEngine;
import org.apache.wss4j.dom.handler.RequestData;
import org.apache.wss4j.dom.handler.WSHandlerResult;
+import org.apache.wss4j.common.cache.MemoryReplayCache;
+import org.apache.wss4j.common.cache.ReplayCache;
import org.apache.wss4j.common.crypto.Crypto;
import org.apache.wss4j.common.crypto.CryptoFactory;
import org.apache.wss4j.common.crypto.CryptoType;
@@ -38,6 +40,7 @@ import org.apache.wss4j.common.crypto.Merlin;
import org.apache.wss4j.common.ext.WSSecurityException;
import org.apache.wss4j.common.saml.SAMLCallback;
import org.apache.wss4j.common.saml.SAMLUtil;
+import org.apache.wss4j.common.saml.bean.ConditionsBean;
import org.apache.wss4j.common.saml.bean.SubjectBean;
import org.apache.wss4j.common.saml.bean.Version;
import org.apache.wss4j.common.saml.builder.SAML1Constants;
@@ -383,6 +386,79 @@ public class SamlNegativeTest {
}
}
+ /**
+ * An Assertion with a OneTimeUse Condition that is rejected because its
signature is not trusted
+ * must not have its ID cached. Otherwise an attacker could pre-empt a
genuine Assertion by sending
+ * one with the same ID, signed by any key, so that the genuine one is
rejected as a replay.
+ */
+ @Test
+ public void testSAML2OneTimeUseUntrustedDoesNotPoisonCache() throws
Exception {
+ ReplayCache replayCache = new MemoryReplayCache();
+ String assertionId = "_" + java.util.UUID.randomUUID().toString();
+
+ // An attacker's Assertion with the ID of the genuine one, signed by
an untrusted key
+ Document forgedDoc = createOneTimeUseSignedAssertionDoc(
+ assertionId, "16c73ab6-b892-458f-abf5-2f875f74882e", "security",
+ CryptoFactory.getInstance("crypto.properties")
+ );
+ try {
+ verifyOneTimeUse(forgedDoc, replayCache);
+ fail("Failure expected on an untrusted signed assertion");
+ } catch (WSSecurityException ex) {
+ assertTrue(ex.getErrorCode() ==
WSSecurityException.ErrorCode.FAILURE);
+ }
+
+ // The genuine Assertion, signed by the trusted issuer, must still be
accepted
+ Document genuineDoc =
+ createOneTimeUseSignedAssertionDoc(assertionId, "wss40_server",
"security", issuerCrypto);
+ verifyOneTimeUse(genuineDoc, replayCache);
+
+ // ...but only once
+ try {
+ verifyOneTimeUse(genuineDoc, replayCache);
+ fail("Expected failure on a replay attack");
+ } catch (WSSecurityException ex) {
+ assertTrue(ex.getErrorCode() ==
WSSecurityException.ErrorCode.INVALID_SECURITY);
+ }
+
+ replayCache.close();
+ }
+
+ private Document createOneTimeUseSignedAssertionDoc(
+ String assertionId, String alias, String password, Crypto signingCrypto
+ ) throws Exception {
+ SAML2CallbackHandler callbackHandler = new SAML2CallbackHandler();
+ callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
+ callbackHandler.setIssuer("www.example.com");
+ callbackHandler.setConfirmationMethod(SAML2Constants.CONF_BEARER);
+
+ ConditionsBean conditions = new ConditionsBean();
+ conditions.setTokenPeriodMinutes(5);
+ conditions.setOneTimeUse(true);
+ callbackHandler.setConditions(conditions);
+
+ SAMLCallback samlCallback = new SAMLCallback();
+ SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
+ SamlAssertionWrapper samlAssertion = new
SamlAssertionWrapper(samlCallback);
+ samlAssertion.getSaml2().setID(assertionId);
+ samlAssertion.signAssertion(alias, password, signingCrypto, false);
+
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecSAMLToken wsSign = new WSSecSAMLToken(secHeader);
+ return wsSign.build(samlAssertion);
+ }
+
+ private WSHandlerResult verifyOneTimeUse(Document doc, ReplayCache
replayCache) throws Exception {
+ RequestData requestData = new RequestData();
+ requestData.setCallbackHandler(callbackHandler);
+ requestData.setSigVerCrypto(trustCrypto);
+ requestData.setSamlOneTimeUseReplayCache(replayCache);
+ return secEngine.processSecurityHeader(doc, requestData);
+ }
+
/**
* Verifies the soap envelope
*
diff --git
a/ws-security-stax/src/main/java/org/apache/wss4j/stax/validate/SamlTokenValidatorImpl.java
b/ws-security-stax/src/main/java/org/apache/wss4j/stax/validate/SamlTokenValidatorImpl.java
index 7d96f2759..6ba9afcde 100644
---
a/ws-security-stax/src/main/java/org/apache/wss4j/stax/validate/SamlTokenValidatorImpl.java
+++
b/ws-security-stax/src/main/java/org/apache/wss4j/stax/validate/SamlTokenValidatorImpl.java
@@ -128,13 +128,17 @@ public class SamlTokenValidatorImpl extends
SignatureTokenValidatorImpl implemen
// Check the Subject Confirmation requirements
verifySubjectConfirmationMethod(samlAssertionWrapper);
- // Check OneTimeUse Condition
- checkOneTimeUse(samlAssertionWrapper,
-
tokenContext.getWssSecurityProperties().getSamlOneTimeUseReplayCache());
-
// Validate the assertion against schemas/profiles
validateAssertion(samlAssertionWrapper);
+ // Check OneTimeUse Condition. This must come after every other check,
as it caches the
+ // Assertion ID, and caching the ID of an Assertion that is then
rejected would let an
+ // attacker poison the cache against a genuine Assertion with the same
ID. The signature of
+ // a signed Assertion has already been verified, and its signing key
trusted, by
+ // SAMLTokenInputHandler before this method is called.
+ checkOneTimeUse(samlAssertionWrapper,
+
tokenContext.getWssSecurityProperties().getSamlOneTimeUseReplayCache());
+
Crypto sigVerCrypto = null;
if (samlAssertionWrapper.isSigned()) {
sigVerCrypto =
tokenContext.getWssSecurityProperties().getSignatureVerificationCrypto();