[java-opensaml] 02/02: Some message decoder improvements.
Codeberg
noreply at shibboleth.net
Fri Nov 27 23:08:19 UTC 2026
This is an automated email from the git hooks/post-receive script.
codeberg pushed a commit to branch main
in repository java-opensaml.
View the commit online:
https://codeberg.org/Shibboleth/java-opensaml/commit/7bd75992701b8285266ac2ef6050f7b58c553ccb
commit 7bd75992701b8285266ac2ef6050f7b58c553ccb
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Wed Nov 18 01:12:53 2026 -0500
Some message decoder improvements.
---
.../decoding/impl/HTTPRedirectDeflateDecoder.java | 12 +++++++++--
.../impl/HTTPRedirectDeflateDecoderTest.java | 25 ++++++++++++++++++++++
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPRedirectDeflateDecoder.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPRedirectDeflateDecoder.java
index 851e76197..9cfbe011b 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPRedirectDeflateDecoder.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPRedirectDeflateDecoder.java
@@ -63,6 +63,9 @@ public class HTTPRedirectDeflateDecoder extends BaseSAMLHttpServletRequestDecode
/** Optional {@link BindingDescriptor} to inject into {@link SAMLBindingContext} created. */
@Nullable private BindingDescriptor bindingDescriptor;
+ /** Tracking whether we saw a RelayState value via HttpServletRequest.getParameter. */
+ @Nullable private String relayStateParam;
+
/** {@inheritDoc} */
@Nonnull @NotEmpty public String getBindingURI() {
return SAMLConstants.SAML2_REDIRECT_BINDING_URI;
@@ -105,9 +108,11 @@ public class HTTPRedirectDeflateDecoder extends BaseSAMLHttpServletRequestDecode
throw new MessageDecodingException("Request indicated an unsupported SAMLEncoding: " + samlEncoding);
}
- final String relayState = request.getParameter("RelayState");
+ final String relayState = StringSupport.trimOrNull(request.getParameter("RelayState"));
log.debug("Decoded RelayState: {}", relayState);
SAMLBindingSupport.setRelayState(messageContext, relayState);
+ // Use the support method just so we are consistent with what will later be used by callers
+ relayStateParam = SAMLBindingSupport.getRelayState(messageContext);
String samlMessageEncoded = null;
String samlMessageParamName = null;
@@ -219,7 +224,10 @@ public class HTTPRedirectDeflateDecoder extends BaseSAMLHttpServletRequestDecode
}
// This is optional
- appendParameter(builder, queryString, "RelayState");
+ final boolean sawSignedRelayState = appendParameter(builder, queryString, "RelayState");
+ if (!sawSignedRelayState && relayStateParam != null) {
+ throw new MessageDecodingException("No signed RelayState was present but HttpServletRequest reported one");
+ }
// This is mandatory
if (!appendParameter(builder, queryString, "SigAlg")) {
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPRedirectDeflateDecoderTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPRedirectDeflateDecoderTest.java
index d0f965415..78343d6d9 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPRedirectDeflateDecoderTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPRedirectDeflateDecoderTest.java
@@ -179,6 +179,31 @@ public class HTTPRedirectDeflateDecoderTest extends XMLObjectBaseTestCase {
Assert.assertEquals(messageContext.ensureSubcontext(SimpleSignatureContext.class).getSignedContent(), expectedSignedContent);
}
+ @Test(expectedExceptions = MessageDecodingException.class)
+ public void testRequestDecodingWithSignatureNoValidRelayStateInQuery() throws MessageDecodingException, MessageEncodingException,
+ MarshallingException, EncodingException, UnsupportedEncodingException {
+ final AuthnRequest samlRequest =
+ (AuthnRequest) unmarshallElement("/org/opensaml/saml/saml2/binding/AuthnRequest.xml");
+ assert samlRequest != null;
+ samlRequest.setDestination(null);
+
+ httpRequest.setParameter("SAMLRequest", encodeMessage(samlRequest));
+ httpRequest.setParameter("SigAlg", "TheAlgorithm");
+ httpRequest.setParameter("Signature", "TheSignature");
+ // Note RelayState is already set to 'relay'
+
+ String query = URISupport.buildQuery(CollectionSupport.listOf(
+ new Pair<>("SAMLRequest", httpRequest.getParameter("SAMLRequest")),
+ new Pair<>("SigAlg", httpRequest.getParameter("SigAlg")),
+ new Pair<>("Signature", httpRequest.getParameter("Signature")),
+ new Pair<>("Relay%53tate", "foobar")
+ ));
+ assert query != null;
+ httpRequest.setQueryString(query);
+
+ decoder.decode();
+ }
+
/**
* Test decoding a Base64 invalid SAML Request.
*
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list