Skip to content

fix: add JS-side validation for pbkdf2 iterations/keylen#939

Merged
boorad merged 1 commit intomainfrom
fix/pbkdf2-validation
Feb 16, 2026
Merged

fix: add JS-side validation for pbkdf2 iterations/keylen#939
boorad merged 1 commit intomainfrom
fix/pbkdf2-validation

Conversation

@boorad
Copy link
Copy Markdown
Collaborator

@boorad boorad commented Feb 16, 2026

Summary

Adds JavaScript-side parameter validation for pbkdf2 and pbkdf2Sync to prevent invalid values from reaching the native C++ layer where they trigger assert()/abort() instead of throwing catchable JS errors.

Changes

  • Add validateParameters() function in packages/react-native-quick-crypto/src/pbkdf2.ts that validates iterations and keylen before calling native code:
    • Must be a number (not a string)
    • Must be a finite integer (rejects NaN, Infinity, floats)
    • iterations must be >= 1 and <= INT32_MAX
    • keylen must be >= 0 and <= INT32_MAX
  • Enable previously-disabled invalid fixture tests in example/src/tests/pbkdf2/pbkdf2_tests.ts

Testing

Invalid fixture tests cover: string iterations, negative iterations, string dkLen, negative dkLen, huge dkLen (4073741824), NaN dkLen, and Infinity dkLen.

Fixes #931

Add validateParameters() to pbkdf2() and pbkdf2Sync() that checks
iterations and keylen before they reach the native C layer. Previously,
invalid values (negative, NaN, Infinity) would trigger assert()/abort()
in native code instead of throwing a JS TypeError.

Validation matches Node.js behavior:
- iterations must be an integer >= 1 and <= INT32_MAX
- keylen must be an integer >= 0 and <= INT32_MAX

Enable the previously commented-out invalid fixture tests.
@boorad boorad self-assigned this Feb 16, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🤖 End-to-End Test Results - Android

Status: ✅ Passed
Platform: Android
Run: 22048139720

📸 Final Test Screenshot

Maestro Test Results - android

Screenshot automatically captured from End-to-End tests and will expire in 30 days


This comment is automatically updated on each test run.

@github-actions
Copy link
Copy Markdown
Contributor

🤖 End-to-End Test Results - iOS

Status: ✅ Passed
Platform: iOS
Run: 22048139733

📸 Final Test Screenshot

Maestro Test Results - ios

Screenshot automatically captured from End-to-End tests and will expire in 30 days


This comment is automatically updated on each test run.

@boorad boorad merged commit c959f30 into main Feb 16, 2026
6 checks passed
@boorad boorad deleted the fix/pbkdf2-validation branch February 16, 2026 02:52
boorad added a commit that referenced this pull request Feb 24, 2026
New pages: PQC (ML-DSA/ML-KEM), Argon2, KMAC, Certificate (SPKAC),
and Utilities (one-shot hash, timingSafeEqual, primes, introspection).

Updated 8 existing pages with missing API sections: SubtleCrypto
(deriveBits, deriveKey, wrapKey/unwrapKey, encapsulation), Keys
(KeyObject.from, equals, toCryptoKey), Signing (standalone sign/verify),
DiffieHellman (diffieHellman function), Ed25519 (Ed448/X448), Hash
(crypto.hash one-shot, SHA3), ECDH (convertKey), and reorganized the
API index into Core/Key Exchange/Key Derivation/Advanced sections.

Annotated 7 pages with behavioral notes from recent fix PRs (#929,
#930, #932, #933, #939, #948, #949, #951, #954, #955): cipher
single-use warning, generateKeys preservation, PBKDF2 validation,
OAEP hash default, randomFill view correctness, RSA-* aliases, and
flexible curve names.

Added llms.txt index route and fixed llms-full.txt JSX stripping in
source.ts to produce clean LLM-friendly output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pbkdf2: add JS-side validation for iterations/keylen to prevent native abort()

1 participant