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

crypto: upgrade pbkdf2 without digest to an error #11305

Closed

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Feb 10, 2017

Commit a116358 added a deprecation warning when pbkdf2 was called without an explicit digest argument. This was because the default digest is sha1, which is not-recommended from a security point of view. This upgrades it to a runtime error when digest is undefined per the plan discussed in the original issue.

Ref: a116358

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

crypto

@jasnell jasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Feb 10, 2017
@nodejs-github-bot nodejs-github-bot added the crypto Issues and PRs related to the crypto subsystem. label Feb 10, 2017
@jasnell
Copy link
Member Author

jasnell commented Feb 10, 2017

cc @nodejs/crypto @bnoordhuis

Copy link
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

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

LGTM with style nits and a suggestion.

lib/crypto.js Outdated
pbkdf2DeprecationWarning();
// Formerly Deprecation code DEP0009
throw new TypeError(
'The "digest" argument is required and must not be undefined');
Copy link
Member

Choose a reason for hiding this comment

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

Can you indent by two additional spaces here?

Copy link
Contributor

Choose a reason for hiding this comment

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

It checks if digest is a function and throws error saying must not be undefined. I think this could do stricter validations.

lib/crypto.js Outdated
if (digest === undefined) {
// Formerly Deprecation code DEP0009
throw new TypeError(
'The "digest" argument is required and must not be undefined');
Copy link
Member

Choose a reason for hiding this comment

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

Ditto. Out of curiosity, is there a reason you can't move the check to the pbkdf2 function below? That would avoid the duplication.

Copy link
Contributor

Choose a reason for hiding this comment

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

and null is allowed? Or will another layer throw for that case? basically, looks like the check should be against == undefined to me, but there is clearly another layer doing a check for digests like 'the-happy-digest', and other invalid input (numbers, etc.), so maybe its covered there.

Use of the [`crypto.pbkdf2()`][] API without specifying a digest was deprecated
in Node.js 6.0 because the method defaulted to using the non-recommendend
`'SHA1'` digest. Previously, a deprecation warning was printed. Starting in
Node.js 8.0.0, calling the `crypto.pbkdf2()` or `crypto.pbkdf2Sync()` with an
Copy link
Contributor

Choose a reason for hiding this comment

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

drop the "the"

in Node.js 6.0 because the method defaulted to using the non-recommendend
`'SHA1'` digest. Previously, a deprecation warning was printed. Starting in
Node.js 8.0.0, calling the `crypto.pbkdf2()` or `crypto.pbkdf2Sync()` with an
undefined `digest` will throw a `TypeError`.
Copy link
Contributor

Choose a reason for hiding this comment

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

what if its null? Maybe, "with an unspecified digest" or "with a non-string digest"?

lib/crypto.js Outdated
if (digest === undefined) {
// Formerly Deprecation code DEP0009
throw new TypeError(
'The "digest" argument is required and must not be undefined');
Copy link
Contributor

Choose a reason for hiding this comment

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

and null is allowed? Or will another layer throw for that case? basically, looks like the check should be against == undefined to me, but there is clearly another layer doing a check for digests like 'the-happy-digest', and other invalid input (numbers, etc.), so maybe its covered there.

@jasnell
Copy link
Member Author

jasnell commented Feb 11, 2017

to be honest, not sure what we should do with null. the current code only prints the deprecation notice if it's undefined so this only throws if it's undefined. The assumption, I believe, is that passing null is more explicit and is therefore ok.

Copy link
Member

@indutny indutny left a comment

Choose a reason for hiding this comment

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

LGTM

@jasnell
Copy link
Member Author

jasnell commented Feb 12, 2017

Updated to address feedback. New CI: https://ci.nodejs.org/job/node-test-pull-request/6365/

Commit a116358 added a deprecation warning when pbkdf2 was called without an
explicit `digest` argument. This was because the default digest is `sha1`,
which is not-recommended from a security point of view. This upgrades it
to a runtime error when `digest` is undefined per the plan discussed in
the original issue.

Ref: nodejs@a116358
@jasnell jasnell force-pushed the crypto-error-pbkdf2-without-digest branch from 62568ab to 6c58166 Compare February 12, 2017 20:48
@jasnell
Copy link
Member Author

jasnell commented Feb 13, 2017

@nodejs/ctc ... any further thoughts?

@@ -562,15 +556,17 @@ exports.pbkdf2 = function(password,


exports.pbkdf2Sync = function(password, salt, iterations, keylen, digest) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's simply do exports.pbkdf2Sync = pbkdf2

Copy link
Member Author

Choose a reason for hiding this comment

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

That would change the signature of pbkdf2Sync (it would accept the callback argument and change the value of pbkdf2Sync.length).

Copy link
Contributor

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

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

Concept and API (error) change LGTM, no comment on the code

jasnell added a commit that referenced this pull request Feb 13, 2017
Commit a116358 added a deprecation warning when pbkdf2 was called without an
explicit `digest` argument. This was because the default digest is `sha1`,
which is not-recommended from a security point of view. This upgrades it
to a runtime error when `digest` is undefined per the plan discussed in
the original issue.

Ref: a116358

PR-URL: #11305
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
@jasnell
Copy link
Member Author

jasnell commented Feb 13, 2017

Landed in 9f74184

@jasnell jasnell closed this Feb 13, 2017
addaleax added a commit to addaleax/express that referenced this pull request Feb 15, 2017
Calling `crypto.pbkdf2()` without a digest has been deprecated in Node
and is scheduled to be broken in Node 8.

Fix this by actually passing a digest.

ref: nodejs/node#11305
@addaleax
Copy link
Member

@jasnell This breaks CITGM because it was used in the express tests in the deprecated way… it’s “just” in an example script, but we really should have run that on this :/

I opened expressjs/express#3207 but there might be another problem with express + Node master… I’m looking into it

@jasnell
Copy link
Member Author

jasnell commented Feb 15, 2017

Argh... Ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crypto Issues and PRs related to the crypto subsystem. deprecations Issues and PRs related to deprecations. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants