Skip to content

Commit

Permalink
Merge pull request #43 from rubenstolk/hotfix/detect-protocol
Browse files Browse the repository at this point in the history
Detect protocol if not provided, fixes #42
  • Loading branch information
ploer committed Jun 20, 2014
2 parents f199e8c + a3a9c3a commit c928fdc
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/passport-saml/saml.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ SAML.prototype.initialize = function (options) {
options = {};
}

if (!options.protocol) {
options.protocol = 'https://';
}

if (!options.path) {
options.path = '/saml/consume';
}
Expand Down Expand Up @@ -80,6 +76,7 @@ SAML.prototype.signRequest = function (xml) {
SAML.prototype.generateAuthorizeRequest = function (req, isPassive) {
var id = "_" + this.generateUniqueID();
var instant = this.generateInstant();
var protocol = this.options.protocol || (req.protocol || 'http').concat('://');
var callbackUrl;

if(this.options.validateInResponseTo) {
Expand All @@ -90,7 +87,7 @@ SAML.prototype.generateAuthorizeRequest = function (req, isPassive) {
if (this.options.callbackUrl) {
callbackUrl = this.options.callbackUrl;
} else {
callbackUrl = this.options.protocol + req.headers.host + this.options.path;
callbackUrl = protocol + req.headers.host + this.options.path;
}

var request = {
Expand Down Expand Up @@ -252,7 +249,7 @@ SAML.prototype.certToPEM = function (cert) {
// vectors against SAML signature verification.
SAML.prototype.validateSignature = function (fullXml, currentNode, cert) {
var self = this;
var xpathSigQuery = ".//*[local-name(.)='Signature' and " +
var xpathSigQuery = ".//*[local-name(.)='Signature' and " +
"namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']";
var signatures = xpath(currentNode, xpathSigQuery);
// This function is expecting to validate exactly one signature, so if we find more or fewer
Expand All @@ -279,7 +276,7 @@ SAML.prototype.validateSignature = function (fullXml, currentNode, cert) {
// If we can't find the reference at the top level, reject
if (currentNode.getAttribute('ID') != refId)
return false;
// If we find any extra referenced nodes, reject. (xml-crypto only verifies one digest, so
// If we find any extra referenced nodes, reject. (xml-crypto only verifies one digest, so
// multiple candidate references is bad news)
var totalReferencedNodes = xpath(currentNode.ownerDocument, "//*[@ID='" + refId + "']");
if (totalReferencedNodes.length > 1)
Expand Down Expand Up @@ -320,8 +317,8 @@ SAML.prototype.validatePostResponse = function (container, callback) {
}

if (assertions.length == 1) {
if (self.options.cert &&
!validSignature &&
if (self.options.cert &&
!validSignature &&
!self.validateSignature(xml, assertions[0], self.options.cert)) {
return callback(new Error('Invalid signature'), null, false);
}
Expand Down Expand Up @@ -426,7 +423,7 @@ SAML.prototype.processValidlySignedAssertion = function(xml, inResponseTo, callb
profile.nameIDFormat = nameID[0].$.Format;
}
}
}
}

var nowMs = new Date().getTime();
var subjectConfirmation = subject[0].SubjectConfirmation ?
Expand Down

0 comments on commit c928fdc

Please sign in to comment.