strip prefix when parsing the request saml (#158)

This commit is contained in:
Deepak Prabhakara 2023-03-24 05:12:47 +00:00 committed by GitHub
parent 019a511eea
commit 77f4034531
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,13 +7,20 @@ const inflateRawAsync = promisify(inflateRaw);
// Parse XML // Parse XML
const parseXML = (xml: string): Promise<Record<string, any>> => { const parseXML = (xml: string): Promise<Record<string, any>> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
xml2js.parseString(xml, (err: Error | null, result: any) => { xml2js.parseString(
if (err) { xml,
reject(err); {
} tagNameProcessors: [xml2js.processors.stripPrefix],
strict: true,
},
(err: Error | null, result: any) => {
if (err) {
reject(err);
}
resolve(result); resolve(result);
}); }
);
}); });
}; };
@ -28,11 +35,11 @@ const decodeBase64 = async (string: string, isDeflated: boolean) => {
const extractSAMLRequestAttributes = async (rawRequest: string) => { const extractSAMLRequestAttributes = async (rawRequest: string) => {
const result = await parseXML(rawRequest); const result = await parseXML(rawRequest);
const attributes = result['samlp:AuthnRequest']['$']; const attributes = result['AuthnRequest']['$'];
const issuer = result['samlp:AuthnRequest']['saml:Issuer']; const issuer = result['AuthnRequest']['Issuer'];
const publicKey = result['samlp:AuthnRequest']['Signature'] const publicKey = result['AuthnRequest']['Signature']
? result['samlp:AuthnRequest']['Signature'][0]['KeyInfo'][0]['X509Data'][0]['X509Certificate'][0] ? result['AuthnRequest']['Signature'][0]['KeyInfo'][0]['X509Data'][0]['X509Certificate'][0]
: null; : null;
if (!publicKey) { if (!publicKey) {