{"record":{"id":"a9190de4d405b38e","repo":"twentyhq/twenty","slug":"entitydescriptor-element-is-missing","errorCode":null,"errorMessage":"EntityDescriptor element is missing","messagePattern":"EntityDescriptor element is missing","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/twenty-front/src/modules/settings/security/utils/parseSAMLMetadataFromXMLFile.ts","lineNumber":75,"sourceCode":"  if (error instanceof Error) return error.message;\n  return 'Unknown parsing error';\n};\n\nexport const parseSAMLMetadataFromXMLFile = (\n  xmlString: string,\n):\n  | { success: true; data: z.infer<typeof validator> }\n  | { success: false; reason: string } => {\n  try {\n    const parser = new DOMParser();\n    const xmlDoc = parser.parseFromString(xmlString, 'application/xml');\n    if (xmlDoc.getElementsByTagName('parsererror').length > 0) {\n      throw new Error('File is not valid XML');\n    }\n\n    const entityDescriptor = getByPrefixAndKey(xmlDoc, 'EntityDescriptor');\n    if (!entityDescriptor)\n      throw new Error('EntityDescriptor element is missing');\n\n    const IDPSSODescriptor = getByPrefixAndKey(xmlDoc, 'IDPSSODescriptor');\n    if (!IDPSSODescriptor)\n      throw new Error('IDPSSODescriptor element is missing');\n\n    const keyDescriptors = getByPrefixAndKey(IDPSSODescriptor, 'KeyDescriptor');\n    if (!keyDescriptors) throw new Error('KeyDescriptor element is missing');\n\n    const keyInfo = getByPrefixAndKey(keyDescriptors, 'KeyInfo');\n    if (!keyInfo) throw new Error('KeyInfo element is missing');\n\n    const x509Data = getByPrefixAndKey(keyInfo, 'X509Data');\n    if (!x509Data) throw new Error('X509Data element is missing');\n\n    const x509Certificate = getByPrefixAndKey(\n      x509Data,\n      'X509Certificate',\n    )?.textContent?.trim();","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-front/src/modules/settings/security/utils/parseSAMLMetadataFromXMLFile.ts#L57-L93","documentation":"Thrown by parseSAMLMetadataFromXMLFile (parseSAMLMetadataFromXMLFile.ts:73-75) when the XML parses successfully but no EntityDescriptor element is found under any of the supported namespace prefixes (md, ns0, ns2, dsig, ds) or unprefixed. EntityDescriptor is the root element of a SAML 2.0 metadata document. Caught at line 127 and returned as `{ success: false, reason: 'EntityDescriptor element is missing' }`.","triggerScenarios":"Uploaded valid XML that is not a SAML metadata document — e.g. a SPARQL/eduserv/other XML payload, or a SAML metadata using an unsupported namespace prefix not in allPrefix.","commonSituations":"Uploading a service-provider metadata file instead of identity-provider metadata; IdP using a custom namespace prefix not in [md, ns0, ns2, dsig, ds]; uploading an AuthnRequest XML instead of metadata.","solutions":["Upload the IdP metadata XML (must contain <EntityDescriptor> as root).","If the IdP uses an unusual namespace prefix, preprocess the XML to normalize prefixes or extend allPrefix.","Verify with the IdP vendor that the file is the metadata export.","Inspect the XML root tag to confirm it is EntityDescriptor."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Pre-check for the EntityDescriptor root before parsing metadata\nconst doc = new DOMParser().parseFromString(xmlString, 'application/xml');\nconst hasEntityDescriptor =\n  doc.getElementsByTagName('EntityDescriptor').length > 0 ||\n  ['md', 'ns0', 'ns2', 'dsig', 'ds'].some((p) =>\n    doc.getElementsByTagName(`${p}:EntityDescriptor`).length > 0,\n  );\nif (!hasEntityDescriptor) {\n  setFormError(t`Metadata must contain an EntityDescriptor element`);\n}","typeGuard":"const hasEntityDescriptor = (s: string): boolean => {\n  const doc = new DOMParser().parseFromString(s, 'application/xml');\n  return ['md', 'ns0', 'ns2', 'dsig', 'ds', '']\n    .some((p) => doc.getElementsByTagName(p ? `${p}:EntityDescriptor` : 'EntityDescriptor').length > 0);\n};","tryCatchPattern":"// Parser returns { success: false, reason } — handle accordingly\nconst result = parseSAMLMetadataFromXMLFile(xmlString);\nif (!result.success && result.reason === 'EntityDescriptor element is missing') {\n  setFormError(t`Upload IdP metadata containing EntityDescriptor`);\n}","preventionTips":["Upload IdP metadata (not SP metadata).","Download metadata directly from the IdP's well-known URL.","Inspect the XML root tag before uploading.","Extend namespace prefix support if your IdP uses an uncommon prefix."],"tags":["frontend","saml","sso","xml","parsing","settings"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}