Skip to content

Commit 6f31441

Browse files
committed
Merge commit 'da829fc0216ed961ea7cb8a6234df65a60f51114' into multiple-authn-context
* commit 'da829fc0216ed961ea7cb8a6234df65a60f51114': Use crypto.randomBytes for ID generation (node-saml#235) BugFix: Fail gracefully when SAML Response is invalid. Fixes node-saml#238 docs: Improve docs for privateKey format. Ref node-saml#230 Drop support for Node versions < 4. v0.20.2
2 parents acf80ba + da829fc commit 6f31441

File tree

5 files changed

+38
-18
lines changed

5 files changed

+38
-18
lines changed

.travis.yml

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
language: node_js
22
node_js:
3-
- "0.10"
4-
- "0.12"
5-
- "iojs"
63
- "4.0"
74
- "stable"
85

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ The `decryptionCert` argument should be a public certificate matching the `decry
117117

118118
Passport-SAML uses the HTTP Redirect Binding for its `AuthnRequest`s (unless overridden with the `authnRequestBinding` parameter), and expects to receive the messages back via the HTTP POST binding.
119119

120-
Authentication requests sent by Passport-SAML can be signed using RSA-SHA1. To sign them you need to provide a private key in the PEM format via the `privateCert` configuration key. For example:
120+
Authentication requests sent by Passport-SAML can be signed using RSA-SHA1. To sign them you need to provide a private key in the PEM format via the `privateCert` configuration key. The certificate
121+
should start with `-----BEGIN PRIVATE KEY-----` on its own line and end with `-----END PRIVATE KEY-----` on its own line.
122+
123+
For example:
121124

122125
```javascript
123126
privateCert: fs.readFileSync('./cert.pem', 'utf-8')

lib/passport-saml/saml.js

+15-12
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,7 @@ SAML.prototype.getCallbackUrl = function (req) {
9494
};
9595

9696
SAML.prototype.generateUniqueID = function () {
97-
var chars = "abcdef0123456789";
98-
var uniqueID = "";
99-
for (var i = 0; i < 20; i++) {
100-
uniqueID += chars.substr(Math.floor((Math.random()*15)), 1);
101-
}
102-
return uniqueID;
97+
return crypto.randomBytes(10).toString('hex');
10398
};
10499

105100
SAML.prototype.generateInstant = function () {
@@ -517,15 +512,23 @@ SAML.prototype.validateSignature = function (fullXml, currentNode, cert) {
517512

518513
SAML.prototype.validatePostResponse = function (container, callback) {
519514
var self = this;
520-
var xml = new Buffer(container.SAMLResponse, 'base64').toString('utf8');
521-
var doc = new xmldom.DOMParser().parseFromString(xml);
522515

523-
var inResponseTo = xpath(doc, "/*[local-name()='Response']/@InResponseTo");
524-
if(inResponseTo){
525-
inResponseTo = inResponseTo.length ? inResponseTo[0].nodeValue : null;
526-
}
516+
var xml, doc, inResponseTo;
527517

528518
Q.fcall(function(){
519+
xml = new Buffer(container.SAMLResponse, 'base64').toString('utf8');
520+
doc = new xmldom.DOMParser({
521+
}).parseFromString(xml);
522+
523+
if (!doc.hasOwnProperty('documentElement'))
524+
throw new Error('SAMLResponse is not valid base64-encoded XML');
525+
526+
inResponseTo = xpath(doc, "/*[local-name()='Response']/@InResponseTo");
527+
528+
if(inResponseTo){
529+
inResponseTo = inResponseTo.length ? inResponseTo[0].nodeValue : null;
530+
}
531+
529532
if(self.options.validateInResponseTo){
530533
if (inResponseTo) {
531534
return Q.ninvoke(self.cacheProvider, 'get', inResponseTo)

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "passport-saml",
3-
"version": "0.20.1",
3+
"version": "0.20.2",
44
"license" : "MIT",
55
"keywords": [
66
"saml",
@@ -45,7 +45,7 @@
4545
"sinon": "^2.1.0"
4646
},
4747
"engines": {
48-
"node": ">= 0.10.0"
48+
"node": ">= 4"
4949
},
5050
"scripts": {
5151
"test": "mocha",

test/tests.js

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)