Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set explicitChar: true to make XML parsing consistent. Fixes issue #283 and #187 #361

Merged
merged 2 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
.tern-port
.idea
25 changes: 14 additions & 11 deletions lib/passport-saml/saml.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ SAML.prototype.validateRedirect = function(container, callback) {
var dom = new xmldom.DOMParser().parseFromString(inflated.toString());
var parserConfig = {
explicitRoot: true,
explicitCharKey: true,
tagNameProcessors: [xml2js.processors.stripPrefix]
};
var parser = new xml2js.Parser(parserConfig);
Expand Down Expand Up @@ -855,8 +856,8 @@ SAML.prototype.verifyIssuer = function (samlMessage) {
if(this.options.idpIssuer) {
var issuer = samlMessage.Issuer;
if (issuer) {
if (issuer[0] !== this.options.idpIssuer && issuer[0]._ !== this.options.idpIssuer)
throw 'Unknown SAML issuer. Expected: ' + this.options.idpIssuer + ' Received: ' + issuer[0];
if (issuer[0]._ !== this.options.idpIssuer)
throw 'Unknown SAML issuer. Expected: ' + this.options.idpIssuer + ' Received: ' + issuer[0]._;
} else {
throw 'Missing SAML issuer';
}
Expand All @@ -868,6 +869,7 @@ SAML.prototype.processValidlySignedAssertion = function(xml, samlResponseXml, in
var msg;
var parserConfig = {
explicitRoot: true,
explicitCharkey: true,
tagNameProcessors: [xml2js.processors.stripPrefix]
};
var nowMs = new Date().getTime();
Expand All @@ -881,8 +883,8 @@ SAML.prototype.processValidlySignedAssertion = function(xml, samlResponseXml, in
assertion = doc.Assertion;

var issuer = assertion.Issuer;
if (issuer) {
profile.issuer = issuer[0];
if (issuer && issuer[0]._) {
profile.issuer = issuer[0]._;
}

var authnStatement = assertion.AuthnStatement;
Expand All @@ -896,8 +898,8 @@ SAML.prototype.processValidlySignedAssertion = function(xml, samlResponseXml, in
var subjectConfirmation, confirmData;
if (subject) {
var nameID = subject[0].NameID;
if (nameID) {
profile.nameID = nameID[0]._ || nameID[0];
if (nameID && nameID[0]._) {
profile.nameID = nameID[0]._;

if (nameID[0].$ && nameID[0].$.Format) {
profile.nameIDFormat = nameID[0].$.Format;
Expand Down Expand Up @@ -1061,10 +1063,10 @@ SAML.prototype.checkAudienceValidityError = function(expectedAudience, audienceR
return new Error('SAML assertion has no AudienceRestriction');
}
var errors = audienceRestrictions.map(function(restriction) {
if (!restriction.Audience || !restriction.Audience[0]) {
if (!restriction.Audience || !restriction.Audience[0] || !restriction.Audience[0]._) {
return new Error('SAML assertion AudienceRestriction has no Audience value');
}
if (restriction.Audience[0] !== expectedAudience) {
if (restriction.Audience[0]._ !== expectedAudience) {
return new Error('SAML assertion audience mismatch');
}
return null;
Expand All @@ -1083,6 +1085,7 @@ SAML.prototype.validatePostRequest = function (container, callback) {
var dom = new xmldom.DOMParser().parseFromString(xml);
var parserConfig = {
explicitRoot: true,
explicitCharkey: true,
tagNameProcessors: [xml2js.processors.stripPrefix]
};
var parser = new xml2js.Parser(parserConfig);
Expand Down Expand Up @@ -1116,15 +1119,15 @@ function processValidlySignedPostRequest(self, doc, callback) {
return callback(new Error('Missing SAML LogoutRequest ID'));
}
var issuer = request.Issuer;
if (issuer) {
profile.issuer = issuer[0];
if (issuer && issuer[0]._) {
profile.issuer = issuer[0]._;
} else {
return callback(new Error('Missing SAML issuer'));
}

var nameID = request.NameID;
if (nameID) {
profile.nameID = nameID[0]._ || nameID[0];
profile.nameID = nameID[0]._;

if (nameID[0].$ && nameID[0].$.Format) {
profile.nameIDFormat = nameID[0].$.Format;
Expand Down