Lock the Nexo crypto choices with ten node-security rules - #1759
Lock the Nexo crypto choices with ten node-security rules#1759ofri-peretz wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request integrates the eslint-plugin-node-security ESLint plugin to enforce cryptographic and security rules, while adding an override to disable the no-math-random-crypto rule for test files. The feedback suggests restoring the trailing newline at the end of .eslintrc.js to adhere to best practices and prevent git diff warnings.
| }, | ||
| ], | ||
| }; | ||
| }; No newline at end of file |
There was a problem hiding this comment.
Fixed in 8b0812f — thanks. The file ends with a newline again.
|
Thank you @ofri-peretz for your contribution 🎉 We need to wait a little longer before we can merge this PR, we have a minimum 21 days age policy that doesn't allow us to merge newly released versions. I have marked the PR so we can assess again and merge later. Thank you! |
|
Thanks @gcatanese — a 21-day age policy is the right instinct for a payments SDK, and I would not want you to make an exception for this PR. I have worked out the exact dates so the wait is a scheduling question rather than an open one. The PR currently pins There is a shorter path if you would rather not hold the PR that long.
For the Nexo path specifically, Two housekeeping notes in the meantime:
No rush from my side, and no need to reply twice — I will keep the branch current either way. |
src/security already does the right thing: HMAC-SHA256, AES-256-CBC with a randomBytes IV, and timingSafeEqual behind a length guard. None of that is enforced by anything, so a future edit can weaken it silently. Ten rules from eslint-plugin-node-security, all currently passing on src/. No source change; one test override, since Math.random() generating a throwaway account code in a spec file is not what no-math-random-crypto is aimed at.
Caught in review. POSIX tools expect a final newline and git flags its absence on every subsequent diff of the file. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
b571555 to
a750356
Compare
src/securityalready does the right thing. This proposes making thatenforceable rather than conventional.
What is already correct here
nexoCrypto.ts:121—timingSafeEqualbehind an explicit length guard, with acomment explaining why the guard is there. That is the careful version; most
code I read gets this wrong.
nexoCrypto.ts:107—createHmac("sha256", …)nexoCrypto.ts:98—createCipheriv("aes-256-cbc", …)with an IV fromrandomBytes(NexoEnum.IV_LENGTH)(:112), not a constantnexoCryptoPrimitives.ts:57— the same timing-safe comparisonNone of it is enforced by anything. A future edit can turn
timingSafeEqualinto
===, orsha256intosha1, and nothing in CI notices. That is the gapthis closes — it is a lock on decisions you have already made, not a change to
them.
The rules
Ten from
eslint-plugin-node-security, chosen because each one maps tosomething
src/securityactually does:no-timing-unsafe-comparetimingSafeEqualinvalidateHmaccannot become===no-weak-hash-algorithmno-weak-cipher-algorithmno-deprecated-cipher-methodcreateCipher(keyless, IV-less)no-ecb-modeno-static-ivrandomBytesno-math-random-cryptoMath.random()no-insecure-rsa-paddingrequire-aead-tag-verificationno-dynamic-algorithm-selectionVerification
npm run lintpasses. No source file changes — the entire diff is.eslintrc.js,package.jsonand the lockfile.security plugins) over
src/— 229.5 KLOC, zero findings. This library isthe cleanest scan in a 1,400-repository sweep I ran this week, which is why
the ask here is "keep it that way" rather than "you have a bug".
The one override
src/__tests__/platforms.spec.ts:27usesMath.floor(Math.random() * Date.now())to generate a throwaway account code.That is fine, and it is not what
no-math-random-cryptois aimed at — so therule is switched off for
src/__tests__/**. Being straight about it: the ruleshould default to allowing test files and does not yet, and I am fixing that
upstream. The override is here so this PR does not depend on that release.
Happy to trim the list to just the four that map to existing code
(
no-timing-unsafe-compare,no-weak-hash-algorithm,no-ecb-mode,no-static-iv) if the forward-looking six feel speculative.