{"record":{"id":"7abe701b700797fb","repo":"spring-projects/spring-security","slug":"failed-to-deserialize-payload-7abe70","errorCode":null,"errorMessage":"Failed to deserialize payload","messagePattern":"Failed to deserialize payload","errorType":"exception","errorClass":"Saml2Exception","httpStatus":null,"severity":"error","filePath":"saml2/saml2-service-provider/src/opensaml5Main/java/org/springframework/security/saml2/provider/service/web/authentication/logout/OpenSaml5Template.java","lineNumber":160,"sourceCode":"\t@Override\n\tpublic <T extends XMLObject> T deserialize(InputStream serialized) {\n\t\ttry {\n\t\t\tParserPool pool = XMLObjectProviderRegistrySupport.getParserPool();\n\t\t\tAssert.notNull(pool, \"ParserPool must be configured\");\n\t\t\tDocument document = pool.parse(serialized);\n\t\t\tElement element = document.getDocumentElement();\n\t\t\tUnmarshallerFactory factory = XMLObjectProviderRegistrySupport.getUnmarshallerFactory();\n\t\t\tUnmarshaller unmarshaller = factory.getUnmarshaller(element);\n\t\t\tif (unmarshaller == null) {\n\t\t\t\tthrow new Saml2Exception(\"Unsupported element of type \" + element.getTagName());\n\t\t\t}\n\t\t\treturn (T) unmarshaller.unmarshall(element);\n\t\t}\n\t\tcatch (Saml2Exception ex) {\n\t\t\tthrow ex;\n\t\t}\n\t\tcatch (Exception ex) {\n\t\t\tthrow new Saml2Exception(\"Failed to deserialize payload\", ex);\n\t\t}\n\t}\n\n\t@Override\n\tpublic OpenSaml5SerializationConfigurer serialize(XMLObject object) {\n\t\tMarshaller marshaller = XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(object);\n\t\tAssert.notNull(marshaller, \"Marshaller for \" + object.getElementQName() + \" must be configured\");\n\t\ttry {\n\t\t\treturn serialize(marshaller.marshall(object));\n\t\t}\n\t\tcatch (MarshallingException ex) {\n\t\t\tthrow new Saml2Exception(ex);\n\t\t}\n\t}\n\n\t@Override\n\tpublic OpenSaml5SerializationConfigurer serialize(Element element) {\n\t\treturn new OpenSaml5SerializationConfigurer(element);","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/spring-projects/spring-security/blob/96852e8860138a482cb13d1479573f24ff6443c6/saml2/saml2-service-provider/src/opensaml5Main/java/org/springframework/security/saml2/provider/service/web/authentication/logout/OpenSaml5Template.java#L142-L178","documentation":"The catch-all wrapper in the logout OpenSaml5Template.deserialize(): any non-Saml2Exception exception during parsing or unmarshalling of the SLO payload is rethrown as a Saml2Exception with message \"Failed to deserialize payload\" and the original exception as cause.","triggerScenarios":"Calling logout OpenSaml5Template.deserialize(String) where pool.parse() or unmarshaller.unmarshall() throws (malformed XML, bad encoding, IO/SAX errors) other than Saml2Exception.","commonSituations":"Base64/URL-encoded SLO parameters not decoded before deserialization; truncated logout messages from POST-binding mishandling; invalid XML characters; charset mismatches between IdP and SP.","solutions":["Read ex.getCause() to identify the concrete parser error.","Decode Base64/URL encoding of SAMLRequest/SAMLResponse parameters before calling deserialize().","Validate the XML is well-formed with a standalone parser to locate the defect.","Confirm the payload was not truncated or modified in transit (binding/relay handling)."],"exampleFix":"// before\nString param = request.getParameter(\"SAMLRequest\");\nLogoutRequest lr = template.deserialize(param); // URL/base64 encoded\n\n// after\nString xml = new String(Base64.getMimeDecoder().decode(\n    URLDecoder.decode(param, StandardCharsets.UTF_8)), StandardCharsets.UTF_8);\nLogoutRequest lr = template.deserialize(xml);","handlingStrategy":"try-catch","validationCode":"try { new SAXReader().read(new StringReader(serialized)); } catch (Exception e) { throw new IllegalArgumentException(\"Malformed SLO XML\", e); }","typeGuard":null,"tryCatchPattern":"try { return template.deserialize(serialized); } catch (Saml2Exception ex) { log.error(\"SLO payload deserialization failed; cause={}\", ex.getCause(), ex); throw ex; }","preventionTips":["Decode SAMLRequest/SAMLResponse parameters (Base64 + URL) before deserializing","Check payload completeness when relaying through proxies","Log ex.getCause() to identify parse-stage failures"],"tags":["saml","opensaml","logout","xml-parsing","spring-security"],"backgroundTag":"invalid-argument-format","analyzedSha":"96852e8860138a482cb13d1479573f24ff6443c6","analyzedAt":"2026-09-10T23:25:23.477Z","contentChangedAt":"2026-09-10T23:25:23.477Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}