Skip to content

Commit b574c95

Browse files
committed
feat: US-006 - Fix Cipher/Decipher streaming and crypto error codes
1 parent 8f3f9db commit b574c95

12 files changed

Lines changed: 721 additions & 173 deletions

File tree

.agent/contracts/node-bridge.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ Bridge-provided `crypto` Diffie-Hellman and ECDH APIs SHALL delegate to host `no
120120
- **THEN** the bridge MUST delegate to host `node:crypto.diffieHellman`
121121
- **AND** the returned shared secret and thrown validation errors MUST preserve Node-compatible behavior
122122

123+
### Requirement: Crypto Stream Wrappers Preserve Transform Semantics And Validation Errors
124+
Bridge-backed `crypto` hash and cipher wrappers SHALL remain compatible with Node stream semantics and MUST preserve Node-style validation error codes for callback-driven APIs.
125+
126+
#### Scenario: Sandbox hashes or encrypts data through stream piping
127+
- **WHEN** sandboxed code uses `crypto.Hash`, `crypto.Cipheriv`, or `crypto.Decipheriv` as stream destinations or sources
128+
- **THEN** those objects MUST be `stream.Transform` instances
129+
- **AND** piping data through them MUST emit the same digest or ciphertext/plaintext bytes that the corresponding direct `update()`/`final()` calls would produce
130+
131+
#### Scenario: Sandbox calls pbkdf2 with invalid arguments
132+
- **WHEN** sandboxed code calls `crypto.pbkdf2()` or `crypto.pbkdf2Sync()` with invalid callback, digest, password, salt, iteration, or key length arguments
133+
- **THEN** the bridge MUST throw or surface Node-compatible `ERR_INVALID_ARG_TYPE` / `ERR_OUT_OF_RANGE` errors instead of plain untyped exceptions
134+
123135
### Requirement: Bridge FS Open Flag Translation Uses Named Constants
124136
The bridge `fs` implementation MUST express string-flag translation using named open-flag constants (for example `O_WRONLY | O_CREAT | O_TRUNC`) aligned with Node `fs.constants` semantics, and MUST NOT rely on undocumented numeric literals.
125137

docs/nodejs-conformance-report.mdx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@ description: Node.js v22 test/parallel/ conformance results for the secure-exec
1212
| Node.js version | 22.14.0 |
1313
| Source | v22.14.0 (test/parallel/) |
1414
| Total tests | 3532 |
15-
| Passing (genuine) | 740 (21.0%) |
15+
| Passing (genuine) | 748 (21.2%) |
1616
| Passing (vacuous self-skip) | 33 |
17-
| Passing (total) | 773 (21.9%) |
18-
| Expected fail | 2688 |
17+
| Passing (total) | 781 (22.1%) |
18+
| Expected fail | 2680 |
1919
| Skip | 71 |
2020
| Last updated | 2026-03-26 |
2121

2222
## Failure Categories
2323

2424
| Category | Tests |
2525
| --- | --- |
26-
| implementation-gap | 1386 |
26+
| implementation-gap | 1377 |
2727
| unsupported-module | 738 |
2828
| requires-v8-flags | 239 |
2929
| requires-exec-path | 200 |
3030
| unsupported-api | 124 |
3131
| test-infra | 68 |
3232
| vacuous-skip | 33 |
3333
| native-addon | 3 |
34-
| security-constraint | 1 |
34+
| security-constraint | 2 |
3535

3636
## Per-Module Results
3737

@@ -70,7 +70,7 @@ description: Node.js v22 test/parallel/ conformance results for the secure-exec
7070
| constants | 1 | 0 | 1 | 0 | 0.0% |
7171
| corepack | 1 | 0 | 1 | 0 | 0.0% |
7272
| coverage | 1 | 0 | 1 | 0 | 0.0% |
73-
| crypto | 99 | 48 (12 vacuous) | 51 | 0 | 48.5% |
73+
| crypto | 99 | 56 (12 vacuous) | 43 | 0 | 56.6% |
7474
| cwd | 3 | 0 | 3 | 0 | 0.0% |
7575
| data | 1 | 0 | 1 | 0 | 0.0% |
7676
| datetime | 1 | 0 | 1 | 0 | 0.0% |
@@ -245,11 +245,11 @@ description: Node.js v22 test/parallel/ conformance results for the secure-exec
245245
| wrap | 4 | 0 | 4 | 0 | 0.0% |
246246
| x509 | 1 | 0 | 1 | 0 | 0.0% |
247247
| zlib | 53 | 17 | 33 | 3 | 34.0% |
248-
| **Total** | **3532** | **773** | **2688** | **71** | **22.3%** |
248+
| **Total** | **3532** | **781** | **2680** | **71** | **22.6%** |
249249

250250
## Expectations Detail
251251

252-
### implementation-gap (705 entries)
252+
### implementation-gap (696 entries)
253253

254254
**Glob patterns:**
255255

@@ -260,7 +260,7 @@ description: Node.js v22 test/parallel/ conformance results for the secure-exec
260260
- `test-https-*.js` — https depends on tls — most tests fail on missing TLS fixture files or crypto API gaps
261261
- `test-http2-*.js` — http2 module bridged via kernel — most tests fail on API gaps, missing fixtures, or protocol handling
262262

263-
*699 individual tests — see expectations.json for full list.*
263+
*690 individual tests — see expectations.json for full list.*
264264

265265
### unsupported-module (191 entries)
266266

@@ -745,12 +745,13 @@ description: Node.js v22 test/parallel/ conformance results for the secure-exec
745745

746746
</Accordion>
747747

748-
### security-constraint (1 entries)
748+
### security-constraint (2 entries)
749749

750-
<Accordion title="1 individual test">
750+
<Accordion title="2 individual tests">
751751

752752
| Test | Reason |
753753
| --- | --- |
754+
| `test-crypto-pbkdf2.js` | SharedArrayBuffer is intentionally removed by sandbox hardening, so the vendored TypedArray coverage loop aborts before the remaining pbkdf2 assertions run |
754755
| `test-process-binding-internalbinding-allowlist.js` | process.binding is not supported in sandbox (security constraint) |
755756

756757
</Accordion>

0 commit comments

Comments
 (0)