Repository navigation
Validate JavaScript native wrapper identity before Rust access - #175
Merged
Merged
Conversation
Pin the matched upstream type-tag implementation, brand native classes by deterministic build inputs, and cover collection, descriptor, callback, lifetime, and ownership boundaries. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Mixed-language test coverageWorkflow status: ✅ Passed
|
Shawn Yuan (shuaiyuanxx)
approved these changes
Sep 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix native-class identity validation at the shared JavaScript binding boundary, rather than validating collection values after interpreting another class's Rust storage.
napi3.12.0,napi-derive3.6.1, and backend 6.1.0; enable N-API 8 explicitly. The lockfile resolvesnapi-sys3.3.2.type_tagattribute to native class declarations with a thinnative_class!declaration macro. A deterministic SHA-256 salt covers sorted native binding/core/contract sources, manifests/lockfile, target/features/build configuration and compiler version. Upstream still incorporates the actual Rust module and class identity.Root cause and dependency choice
The previous generated
FromNapiRef/FromNapiMutRefconversions callednapi_unwrapand cast the returned pointer without verifying its Rust class. This also affected nested collection parameters, metadata/signature arguments and handwritten conversion bridges. Ordinary JavaScript receiver checks are not an adequate replacement for creation-time native identity.The selected published pairing includes the complete class-identity implementation from napi-rs/napi-rs#3405, verified against published source and its release commit
58bd87fa524a837a7c962ab4103e5588557ccd81:new_instance/ToNapiValueTClassInstance,Reference, method and accessor receiversSome upstream paths first retrieve an opaque pointer via
napi_unwrap; the tag is checked before its typed Rust cast/reference/dereference.The backend is pinned separately so its compatible version range cannot select mismatched later conversion glue. Subsequent upstream borrow/unload policy changes reject existing reentrant delegate release/
oncebehavior and require separate compatibility work. This PR adopts the complete class-identity fix, not that separate migration, and does not claim general Rust aliasing or addon-unload safety.Before / after
The coordinator's retained pre-fix production ARM64 evidence at
34eb6246627c671113a501c00edc8e3317fc8b3drecords a genuine owned process resource passed as a vector element terminating with0xC0000005; valid/null/plain-object and resource-close controls completed normally. The known crash was not rerun.The production regression obtains an owned resource through the existing Win32 runtime's
OpenProcesscall for the current process. The same wrong input now raises a JS exception;GetProcessIdstill succeeds afterward, the resource closes once, and the process exits naturally.Validation
Executed on Node 24.15.0 native ARM64 unless noted:
once, both nested/reentrant delegate-release paths, IOCP/worker teardown, and genuine Win32 COM inputs.Limits: Node 18 was not installed/executed here; its N-API 8 capability was checked, not represented as runtime execution. The Node >=18 requirement is unchanged; source builds now require Rust >=1.88. Existing full ARM64 raw-union tests remain blocked by their pre-existing by-value union support gate; this PR does not expand that support. Build branding is a conservative compatibility boundary, not a formal cross-library Rust ABI guarantee.