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

Remove cryptiles dependency #102

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions lib/passport-wsfed-saml2/saml.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// credits to: https://github.com/bergie/passport-saml

var crypto = require('crypto');
var cryptiles = require('cryptiles');
var xpath = require('xpath');
var xmlCrypto = require('xml-crypto');
var EventEmitter = require('events');
Expand Down Expand Up @@ -161,7 +160,13 @@ SAML.prototype.validateAudience = function (samlAssertion, realm, version) {
}

if (!audience || audience.length === 0) return false;
return cryptiles.fixedTimeComparison(audience[0].textContent, realm);

try {
return crypto.timingSafeEqual(Buffer.from(audience[0].textContent), Buffer.from(realm));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this change is benign (cryptiles code is inlined here), the calling code should check if compared buffers have the same length. Lack of this validation by the caller results in an exception being thrown.

While use of timingSafeEqual is admirable, I don't see how this might be used as an oracle, and I think a simple string comparison would be just as good.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so first you want a length check on ´audience[0].textContent´ and ´realm´ and then you want to replace the ´timingSafeEqual´ with a simple ´===´ comparison. Is this correct?

}
catch (err) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good idea to propagate this error?

};

SAML.prototype.validateNameQualifier = function (samlAssertion, issuer) {
Expand Down
50 changes: 21 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
},
"main": "./lib/passport-wsfed-saml2",
"dependencies": {
"cryptiles": "~0.2.2",
"ejs": "2.5.5",
"jsonwebtoken": "~5.0.4",
"passport-strategy": "^1.0.0",
Expand Down