[java-idp-plugin-vci] 03/04: Malformed json input handled more defensively

Codeberg noreply at shibboleth.net
Wed Nov 11 10:42:19 UTC 2026


This is an automated email from the git hooks/post-receive script.

codeberg pushed a commit to branch dev/REVIEW_ASSIGN
in repository java-idp-plugin-vci.

View the commit online:
https://codeberg.org/Shibboleth/java-idp-plugin-vci/commit/322a3a552ee59d0fd93279ed3dc4776a7e8b4d89

commit 322a3a552ee59d0fd93279ed3dc4776a7e8b4d89
Author: Janne Lauros <janne.lauros at csc.fi>
AuthorDate: Wed Nov 11 12:37:22 2026 +0200

    Malformed json input handled more defensively
---
 .../messaging/impl/OpenIDVCICredentialsRequest.java   |  2 +-
 .../messaging/impl/OpenIDVCITokenRequest.java         |  2 +-
 .../messaging/impl/StatusListRevokeRequest.java       |  6 +++++-
 .../impl/OpenIDVCICredentialsRequestTest.java         | 19 ++++++++-----------
 .../messaging/impl/OpenIDVCITokenRequestTest.java     | 12 ++++++++++++
 .../messaging/impl/StatusListRevokeRequestTest.java   | 16 ++++++++++++++++
 6 files changed, 43 insertions(+), 14 deletions(-)

diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/OpenIDVCICredentialsRequest.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/OpenIDVCICredentialsRequest.java
index 0ad39f9..72be61d 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/OpenIDVCICredentialsRequest.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/OpenIDVCICredentialsRequest.java
@@ -195,7 +195,7 @@ public class OpenIDVCICredentialsRequest extends ProtectedResourceRequest {
             });
         } catch (final JsonProcessingException e1) {
             throw new ParseException(e1.getMessage(),
-                    OAuth2Error.INVALID_REQUEST.appendDescription(": " + e1.getMessage()));
+                    OAuth2Error.INVALID_REQUEST.appendDescription(": request body is not a JSON object"));
         }
         final URI uri;
         try {
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/OpenIDVCITokenRequest.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/OpenIDVCITokenRequest.java
index a5f32dc..155891e 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/OpenIDVCITokenRequest.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/OpenIDVCITokenRequest.java
@@ -413,7 +413,7 @@ public class OpenIDVCITokenRequest extends TokenRequest {
             authorizationDetails = OpenIDVCIAuthorizationDetail.parse(httpRequest);
         } catch (final JsonProcessingException e) {
             throw new ParseException(e.getMessage(),
-                    OAuth2Error.INVALID_REQUEST.appendDescription(": " + e.getMessage()));
+                    OAuth2Error.INVALID_REQUEST.appendDescription(": authorization_details could not be parsed"));
         }
         final String grantType = MultivaluedMapUtils.getFirstValue(params, "grant_type");
         if (!GRANT_TYPE_VALUE_PRE_AUTH.equals(grantType) && !GRANT_TYPE_VALUE_CODE.equals(grantType)) {
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/messaging/impl/StatusListRevokeRequest.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/messaging/impl/StatusListRevokeRequest.java
index 148d736..d9f7dbe 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/messaging/impl/StatusListRevokeRequest.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/messaging/impl/StatusListRevokeRequest.java
@@ -131,7 +131,11 @@ public class StatusListRevokeRequest extends AbstractOptionallyIdentifiedRequest
             });
         } catch (final JsonProcessingException e) {
             throw new ParseException(e.getMessage(),
-                    OAuth2Error.INVALID_REQUEST.appendDescription(": " + e.getMessage()));
+                    OAuth2Error.INVALID_REQUEST.appendDescription(": request body is not a JSON object"));
+        }
+        if (payload == null) {
+            throw new ParseException("Request body is not a JSON object",
+                    OAuth2Error.INVALID_REQUEST.appendDescription(": request body is not a JSON object"));
         }
 
         final URI uri;
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/OpenIDVCICredentialsRequestTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/OpenIDVCICredentialsRequestTest.java
index bf6b35f..9841284 100644
--- a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/OpenIDVCICredentialsRequestTest.java
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/OpenIDVCICredentialsRequestTest.java
@@ -20,6 +20,7 @@ import java.net.URI;
 
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
+import com.nimbusds.oauth2.sdk.OAuth2Error;
 import com.nimbusds.oauth2.sdk.ParseException;
 import com.nimbusds.oauth2.sdk.http.HTTPRequest;
 import com.nimbusds.oauth2.sdk.token.DPoPAccessToken;
@@ -89,16 +90,12 @@ public class OpenIDVCICredentialsRequestTest {
         OpenIDVCICredentialsRequest.parse(httpRequest);
     }
 
-    @Test(expectedExceptions = IllegalArgumentException.class)
-    public void failProofAndProofs() throws ParseException {
-        httpRequest.setBody("{\n" + "  \"credential_configuration_id\": \"org.iso.18013.5.1.mDL\",\n"
-                + "  \"proof\": {\n" + "    \"proof_type\": \"jwt\",\n"
-                + "    \"jwt\": \"eyJraWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEva2V5cy8xIiwiYWxnIjoiRVMyNTYiLCJ0eXAiOiJKV1QifQ\"\n"
-                + "  }\n" + "  \"proofs\": {\n" + "    \"jwt\": [\n"
-                + "      \"eyJ0eXAiOiJvcGVuaWQ0dmNpLXByb29mK2p3dCIsImFsZyI6IkVTMjU2IiwiandrIjp7Imt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiblVXQW9BdjNYWml0aDhFN2kxOU9kYXhPTFlGT3dNLVoyRXVNMDJUaXJUNCIsInkiOiJIc2tIVThCalVpMVU5WHFpN1N3bWo4Z3dBS18weGtjRGpFV183MVNvc0VZIn19\",\n"
-                + "      \"eyJraWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEva2V5cy8xIiwiYWxnIjoiRVMyNTYiLCJ0eXAiOiJKV1QifQ\"\n"
-                + "    ]\n" + "  }\n" + "}");
-        OpenIDVCICredentialsRequest.parse(httpRequest);
+    @Test
+    public void failBodyNotJson() throws ParseException {
+        httpRequest.setBody("not json");
+        final ParseException e =
+                Assert.expectThrows(ParseException.class, () -> OpenIDVCICredentialsRequest.parse(httpRequest));
+        Assert.assertEquals(e.getErrorObject().getCode(), OAuth2Error.INVALID_REQUEST.getCode());
     }
 
-}
\ No newline at end of file
+}
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/OpenIDVCITokenRequestTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/OpenIDVCITokenRequestTest.java
index 5e6bc57..eb9d817 100644
--- a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/OpenIDVCITokenRequestTest.java
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/OpenIDVCITokenRequestTest.java
@@ -29,6 +29,7 @@ import com.nimbusds.common.contenttype.ContentType;
 import com.nimbusds.oauth2.sdk.AuthorizationCodeGrant;
 import com.nimbusds.oauth2.sdk.ClientCredentialsGrant;
 import com.nimbusds.oauth2.sdk.GrantType;
+import com.nimbusds.oauth2.sdk.OAuth2Error;
 import com.nimbusds.oauth2.sdk.ParseException;
 import com.nimbusds.oauth2.sdk.RefreshTokenGrant;
 import com.nimbusds.oauth2.sdk.auth.ClientAuthentication;
@@ -184,4 +185,15 @@ public class OpenIDVCITokenRequestTest {
         Assert.assertEquals(message.getScope().toString(), "read");
     }
 
+    @Test
+    public void parseMalformedAuthorizationDetails() throws ParseException, URISyntaxException {
+        httpRequest = new HTTPRequest(HTTPRequest.Method.POST, new URI("http://example.com"));
+        httpRequest.setContentType(ContentType.APPLICATION_URLENCODED.toString());
+        httpRequest.setBody("client_id=clientID&client_secret=12234&grant_type=authorization_code&code=123456"
+                + "&authorization_details=not json");
+        final ParseException e =
+                Assert.expectThrows(ParseException.class, () -> OpenIDVCITokenRequest.parse(httpRequest));
+        Assert.assertEquals(e.getErrorObject().getCode(), OAuth2Error.INVALID_REQUEST.getCode());
+    }
+
 }
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/messaging/impl/StatusListRevokeRequestTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/messaging/impl/StatusListRevokeRequestTest.java
index 2a4778d..5ab65b5 100644
--- a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/messaging/impl/StatusListRevokeRequestTest.java
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/messaging/impl/StatusListRevokeRequestTest.java
@@ -74,6 +74,22 @@ public class StatusListRevokeRequestTest {
         Assert.assertEquals(e.getErrorObject().getCode(), OAuth2Error.INVALID_CLIENT.getCode());
     }
 
+    @Test
+    public void testBodyNotJson() throws Exception {
+        final ParseException e = Assert.expectThrows(ParseException.class,
+                () -> StatusListRevokeRequest.parse(request("Basic dGVzdDp0ZXN0", "not json")));
+
+        Assert.assertEquals(e.getErrorObject().getCode(), OAuth2Error.INVALID_REQUEST.getCode());
+    }
+
+    @Test
+    public void testBodyNull() throws Exception {
+        final ParseException e = Assert.expectThrows(ParseException.class,
+                () -> StatusListRevokeRequest.parse(request("Basic dGVzdDp0ZXN0", "null")));
+
+        Assert.assertEquals(e.getErrorObject().getCode(), OAuth2Error.INVALID_REQUEST.getCode());
+    }
+
     @Test
     public void testMissingId() throws Exception {
         final ParseException e = Assert.expectThrows(ParseException.class,

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list