-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: deprecate aliases for randomBytes #22519
Conversation
cc @nodejs/crypto @nodejs/security-wg Deprecation was suggested back in #557 by the way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
doc/api/deprecations.md
Outdated
Type: Runtime | ||
|
||
In recent versions of Node.js, there is no difference between | ||
[`crypto.randomBytes()`][] and `crypto.pseudoRandomBytes()`. The latter has been |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: has been
-> is
for consistency with the rest of the deprecation messages (with one exception that should also be changed but not in this PR).
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@dougwilson which module is that? why is it doing that check? |
This comment has been minimized.
This comment has been minimized.
@dougwilson I would release a new major version of that module, and drop support for Node < 4 (even Node < 6). However, you could still detect this without version checking via Note that when this land any user of |
This comment has been minimized.
This comment has been minimized.
My bad. |
I would say go for it. |
@@ -234,5 +231,20 @@ Object.defineProperties(exports, { | |||
configurable: false, | |||
enumerable: true, | |||
value: constants | |||
}, | |||
|
|||
// Aliases for randomBytes are deprecated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a comment:
// The ecosystem needs those to exists for backwards compatibility with
// ancient Node.js runtimes (0.10, 0.12).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added it. IMO this kind of makes it sound as if we couldn't remove these functions in the future though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, this is the sound of #22519 (comment) comment.
@dougwilson Thanks for weighing in! Are you sure that people are still using that package for backcompatibility? The only Node.js releases which require this kind of check are from 2015 or even older and have long been EOL. Maybe people just want to use promises? |
This comment has been minimized.
This comment has been minimized.
@dougwilson I don't know. Your previous comment suggested that backcompatibility was the primary intention of people using the package, but I'd be surprised if that was true. There are barely any packages depending on random-bytes, so maybe the majority of downloads is caused by people using uid-safe? It is cool that packages such as yours try to support "ancient" versions as @mcollina called them, but that shouldn't stand in the way of improving Node.js. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@dougwilson I am sorry for the misunderstanding, this was in no way directed at you! This was entirely based on #22519 (comment), which suggests that we cannot remove these functions. |
lib/crypto.js
Outdated
}, | ||
|
||
// Aliases for randomBytes are deprecated. | ||
// The ecosystem needs those to exists for backwards compatibility with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: exists -> exist?
8a304fe
to
86b7efd
Compare
Rebased, old HEAD was 8a304fe59a87cf8be7e0a804c860d017b91375ab. |
Landed in 221df22. |
PR-URL: #22519 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: James M Snell <[email protected]>
This affects a module used by |
@targos I opened npm/unique-slug#6. |
Make `pseudoRandomBytes` and it's aliases `prng` and `rng` configurable to allow monkey patching. PR-URL: nodejs#24108 Refs: nodejs#22519 Refs: nodejs#23017 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Vladimir de Turckheim <[email protected]> Reviewed-By: James M Snell <[email protected]>
Make `pseudoRandomBytes` and it's aliases `prng` and `rng` configurable to allow monkey patching. PR-URL: #24108 Refs: #22519 Refs: #23017 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Vladimir de Turckheim <[email protected]> Reviewed-By: James M Snell <[email protected]>
Make `pseudoRandomBytes` and it's aliases `prng` and `rng` configurable to allow monkey patching. PR-URL: #24108 Refs: #22519 Refs: #23017 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Vladimir de Turckheim <[email protected]> Reviewed-By: James M Snell <[email protected]>
The deprecation warning causes an npm test to fail, at least when run via our # Subtest: tarball paths should update port if updating protocol
not ok 1 - no error output
---
found: >
(node:51947) [DEP0115] DeprecationWarning: crypto.pseudoRandomBytes
is
deprecated.
wanted: ''
compare: ===
at:
line: 75
column: 9
file: test/tap/add-named-update-protocol-port.js
type: global Hopefully npm/unique-slug#6 can land soon, but if not, I wonder if we should document We could also consider the Buffer constructor route and only produce a runtime warning on use outside of node_modules. Updating the npm test somehow may also be an option, I suppose, although it's not obvious to me how in this case, as the whole point of this test is probably to check that there isn't stderr output on success. |
@Trott I think npm/unique-slug#6 should land even if we un-deprecate I am +0.5 on the deprecation itself. I suggested documentation as an alternative, but I still prefer the deprecation. |
Aliases are very cheap, and if this adds a deprecation warning to npm output in some cases, I’d prefer to undo the deprecation (or make it a |
@tniessen oh, ha 😄 Is there actually anything to do for us then? Does the npm test still fail without |
Oh, right, I have Heh, the test still fails on master but not because of this. It's instead because it gets this warning: npm WARN npm npm does not support Node.js v12.0.0-pre The test in question is making sure that there are no warnings emitted. So as-is, I suppose it will always fail on master. Wonder if we should make it an expected failure in our wrapper or if the test itself should be updated to be tolerant about EDIT: Will be solved by updating core's npm from 6.5.0-next to 6.5.0. So: There's no problem. |
Make `pseudoRandomBytes` and it's aliases `prng` and `rng` configurable to allow monkey patching. PR-URL: nodejs#24108 Refs: nodejs#22519 Refs: nodejs#23017 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Vladimir de Turckheim <[email protected]> Reviewed-By: James M Snell <[email protected]>
There are three aliases for
crypto.randomBytes
now, all of them are undocumented. I think we should strive to have as little undocumented API surface as possible, so the next logical step would be to either document or deprecate these aliases.crypto.pseudoRandomBytes
used to be a different function but became an alias forcrypto.randomBytes
in #557 (three years ago). It has been undocumented ever since and is rarely used within the ecosystem.The other two aliases,
crypto.rng
andcrypto.prng
have never been documented as far as I can tell and their names are unintuitive for people who are not familiar with crypto and the concept of CSRNGs / CSPRNGs.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes