{"record":{"id":"5d6baf61d480ba28","repo":"twentyhq/twenty","slug":"file-is-not-valid-xml","errorCode":null,"errorMessage":"File is not valid XML","messagePattern":"File is not valid XML","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/twenty-front/src/modules/settings/security/utils/parseSAMLMetadataFromXMLFile.ts","lineNumber":70,"sourceCode":"        const path = issue.path.join('.');\n        return path.length > 0 ? `${path}: ${issue.message}` : issue.message;\n      })\n      .join('; ');\n  }\n  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');","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-front/src/modules/settings/security/utils/parseSAMLMetadataFromXMLFile.ts#L52-L88","documentation":"Thrown by parseSAMLMetadataFromXMLFile (parseSAMLMetadataFromXMLFile.ts:69-71) when the DOMParser inserts a <parsererror> element, meaning the supplied string is not well-formed XML. The throw is caught at line 127 and returned as `{ success: false, reason: 'File is not valid XML' }` — callers never see it propagate.","triggerScenarios":"User uploads a SAML metadata file whose content fails XML parsing: not XML at all (JSON, plain text), malformed tags, unclosed elements, encoding issues. DOMParser.parseFromString with 'application/xml' embeds a parsererror element on failure, which the code detects.","commonSituations":"Uploading the wrong file (e.g. a certificate instead of metadata); copy-paste truncation; BOM or encoding mismatch; HTML content uploaded by mistake; partial file download.","solutions":["Provide a well-formed SAML 2.0 metadata XML file (validate with xmllint first).","Download the metadata XML directly from the IdP rather than copy-pasting.","Confirm the file is UTF-8 without BOM.","Surface the returned `reason` to the user as a form validation error."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate XML well-formedness before calling the parser\nconst doc = new DOMParser().parseFromString(xmlString, 'application/xml');\nif (doc.getElementsByTagName('parsererror').length > 0) {\n  setError(t`Please upload a well-formed XML file`);\n  return;\n}","typeGuard":"const isWellFormedXml = (s: string): boolean =>\n  new DOMParser().parseFromString(s, 'application/xml')\n    .getElementsByTagName('parsererror').length === 0;","tryCatchPattern":"// The parser returns { success: false, reason } rather than throwing to callers:\nconst result = parseSAMLMetadataFromXMLFile(xmlString);\nif (!result.success) {\n  setFormError(result.reason);\n  return;\n}","preventionTips":["Validate the file is XML before uploading.","Prefer downloading metadata from the IdP over copy-paste.","Use UTF-8 without BOM.","Surface the returned reason to users as a form error."],"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"}