René's URL Explorer Experiment


Title: node-api: do not crash on module version mismatch by krassx · Pull Request #66019 · nodejs/node · GitHub

Open Graph Title: node-api: do not crash on module version mismatch by krassx · Pull Request #66019 · nodejs/node

X Title: node-api: do not crash on module version mismatch by krassx · Pull Request #66019 · nodejs/node

Description: Problem node_napi_env__::New() validates the Node-API version an add-on declares. When the add-on requires a version this binary does not support, it throws a descriptive error and returns nullptr: } else if (module_api_version > NODE_API_SUPPORTED_VERSION_MAX && module_api_version != NAPI_VERSION_EXPERIMENTAL) { node::Environment* node_env = node::Environment::GetCurrent(context); CHECK_NOT_NULL(node_env); v8impl::ThrowNodeApiVersionError( node_env, module_filename.c_str(), module_api_version); return nullptr; } napi_module_register_by_symbol() then dereferences that nullptr without checking it: napi_env env = node_napi_env__::New(context, module_filename, module_api_version); napi_value _exports = nullptr; env->CallIntoModule([&](napi_env env) { // <-- nullptr So loading such an add-on segfaults, and the error Node already built — "… requires Node-API version N, but this version of Node.js only supports version M add-ons." — is never delivered. require() cannot catch it, because the process is gone. Reproduction A ten-line add-on, no third-party tooling, plain node-gyp: #define NAPI_VERSION 99 #include static napi_value Init(napi_env env, napi_value exports) { return exports; } NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) $ node -e "try { require('./build/Release/hello.node') } catch (e) { console.log('caught:', e.message) }" Segmentation fault Confirmed on v20.x, v22.x, v24.x and v26.8.2, and main, v22.x-staging and v24.x-staging all still lack the check. Fix Return when New() returns nullptr; the error it threw then propagates normally. Verified against a local build of this branch: $ ./out/Release/node -e "try { require('.../test_module_version_mismatch.node') } catch (e) { console.log('caught:', e.message) }" caught: file:///.../test_module_version_mismatch.node requires Node-API version 2147483646, but this version of Node.js only supports version 10 add-ons. Removing the four added lines and relinking the same tree turns that back into exit=139 with the catch never reached, so the new test fails without the fix and passes with it. node-api and js-native-api both run clean on the patched build: 102 tests, 0 failures. Test The error path had no coverage at all — "requires Node-API version" appears in exactly one file in the repository, src/node_api.cc, which is how it could be unreachable without anyone noticing. The new test is modelled on test/node-api/test_null_init, which covers the sibling early return in the same function. Notes for reviewers This is not a reprise of the Node-API versioning discussion in #57233. That issue was closed on the grounds that the add-on had been miscompiled by a third-party tool, which is fair — but it leaves the crash in place. The version policy is not in question here; only that a check which already detects the problem and writes an error should be able to deliver it. The reproduction above involves no external tooling. #63740 reports a superficially similar segfault in napi_register_module_v1 from a libnode.so ABI mismatch. That is a different root cause and this change does not address it. Closest precedent: #58459 added CHECK_NOT_NULL(node_env) to this same function for the node::Environment pointer. This change covers the napi_env returned by New() twelve lines below, which is the one that is nullable by design. Refs: #57233 AI use disclosure Per doc/contributing/ai-guidelines.md: this change was prepared with assistance from Claude Code. The commit message refers to it only as "a closed-source coding agent", following the guidance in Naming AI tools in disclosures to keep commercial brand names out of the commit log and name them here instead. The design, review and validation are my own. Specifically, what I verified personally rather than taking on trust: The mechanism, read directly in src/node_api.cc — node_napi_env__::New() returns nullptr on the version-mismatch branch, and napi_module_register_by_symbol() dereferences it with no check. Confirmed under a debugger: the faulting register holds 0. That the fix works, against a local build of this branch, by observing the intended error reach a try/catch around require(). That the new test can fail. I removed the four added lines, relinked the same tree, and confirmed the test fails there (exit=139, the catch never reached) and passes with them. A test that cannot fail would not be worth adding. That the test asserts the intended behaviour rather than the implementation's incidental shape: it matches the error text the version check produces, with the supported-version number left as \d+ so it does not need updating each time NODE_API_SUPPORTED_VERSION_MAX moves. No regressions: node-api and js-native-api run clean on the patched build, 102 tests, 0 failures. I can explain and defend the change during review, and will respond to feedback myself.

Open Graph Description: Problem node_napi_env__::New() validates the Node-API version an add-on declares. When the add-on requires a version this binary does not support, it throws a descriptive error and returns nullptr:...

X Description: Problem node_napi_env__::New() validates the Node-API version an add-on declares. When the add-on requires a version this binary does not support, it throws a descriptive error and returns nullptr:...

Opengraph URL: https://github.com/nodejs/node/pull/66019

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:b2150ff5-616f-b054-11d9-cacc1659d766
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idD194:2684EB:737D8B:9D502C:6AED2B4A
html-safe-noncedbaa60977bec9b95e9fdb963a628e939997127805e279261c486594639205647
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTk0OjI2ODRFQjo3MzdEOEI6OUQ1MDJDOjZBRUQyQjRBIiwidmlzaXRvcl9pZCI6IjEwNTAzNDU1OTI3NDQzODk0NTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac59bb33a74cb1f7a1d846a6348cb68076d44270120ed61f83feadf873ef52ff79
hovercard-subject-tagpull_request:4525038634
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/nodejs/node/pull/66019/files
twitter:imagehttps://avatars.githubusercontent.com/u/8613766?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/8613766?s=400&v=4
og:image:altProblem node_napi_env__::New() validates the Node-API version an add-on declares. When the add-on requires a version this binary does not support, it throws a descriptive error and returns nullptr:...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None9d95365dda0576efe9b71f45807595e396bd0ca9286fba5367a05048e6ddf8f2
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/nodejs/node git https://github.com/nodejs/node.git
octolytics-dimension-user_id9950313
octolytics-dimension-user_loginnodejs
octolytics-dimension-repository_id27193779
octolytics-dimension-repository_nwonodejs/node
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id27193779
octolytics-dimension-repository_network_root_nwonodejs/node
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release98b41fa4b5635ceb45a4c54320fced73817ff290
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/nodejs/node/pull/66019/changes#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fpull%2F66019%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fpull%2F66019%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=nodejs%2Fnode
Reloadhttps://github.com/nodejs/node/pull/66019/changes
Reloadhttps://github.com/nodejs/node/pull/66019/changes
Reloadhttps://github.com/nodejs/node/pull/66019/changes
nodejshttps://github.com/nodejs
nodehttps://github.com/nodejs/node
Codehttps://github.com/nodejs/node
Issues656 (656)https://github.com/nodejs/node/issues
Pull requests666 (666)https://github.com/nodejs/node/pulls
Actionshttps://github.com/nodejs/node/actions
Projectshttps://github.com/nodejs/node/projects
Security and qualityhttps://github.com/nodejs/node/security
Insightshttps://github.com/nodejs/node/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fnodejs%2Fnode%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fnodejs%2Fnode%2Fissues%2Fnew%2Fchoose
nodejs-github-bothttps://github.com/nodejs-github-bot
nodejs:mainhttps://github.com/nodejs/node/tree/main
krassx:node-api-throw-instead-of-crash-on-version-mismatchhttps://github.com/krassx/node/tree/node-api-throw-instead-of-crash-on-version-mismatch
Conversation 13 https://github.com/nodejs/node/pull/66019
Commits 4 https://github.com/nodejs/node/pull/66019/commits
Checks 46 https://github.com/nodejs/node/pull/66019/checks
Files changed https://github.com/nodejs/node/pull/66019/files
Please reload this pagehttps://github.com/nodejs/node/pull/66019/changes
node-api: do not crash on module version mismatch https://github.com/nodejs/node/pull/66019/changes#top
Show all changes 4 commits https://github.com/nodejs/node/pull/66019/files
089103e node-api: do not crash on module version mismatch krassx Sep 14, 2026 https://github.com/nodejs/node/pull/66019/commits/089103ea66b357a9e8ce3ed25cff89b20bbe02f7
a105f14 Update test/node-api/test_module_version_mismatch/test_module_version… krassx Sep 15, 2026 https://github.com/nodejs/node/pull/66019/commits/a105f1486720e762de952a40532bfd9c1c8c353c
bab3202 Update src/node_api.cc krassx Sep 15, 2026 https://github.com/nodejs/node/pull/66019/commits/bab32029e36825eff7aa5c020f0f30f283d60c9a
3a43920 Update test/node-api/test_module_version_mismatch/test.js krassx Sep 16, 2026 https://github.com/nodejs/node/pull/66019/commits/3a439201da6658774291fec82e42f4a166125402
Clear filters https://github.com/nodejs/node/pull/66019/files
Please reload this pagehttps://github.com/nodejs/node/pull/66019/changes
Please reload this pagehttps://github.com/nodejs/node/pull/66019/changes
node_api.cc https://github.com/nodejs/node/pull/66019/changes#diff-2057dbe503dbb37a65a74cf86e056d50c27ba828070577e0f7f07e734365c9bc
binding.gyp https://github.com/nodejs/node/pull/66019/changes#diff-9122cc90694bafa1b2d5c8244da0700a82897430b9435df086d308efe6e90b13
test.js https://github.com/nodejs/node/pull/66019/changes#diff-bc24d5acc68a0c6aee80d94f5659aaf7c59cc466d21f06f0ecdf31db8b307cd4
test_module_version_mismatch.c https://github.com/nodejs/node/pull/66019/changes#diff-4bb85f8301e4abb78c71ff80c829b5176055798c372115da746e9d539ce64af0
src/node_api.cchttps://github.com/nodejs/node/pull/66019/changes#diff-2057dbe503dbb37a65a74cf86e056d50c27ba828070577e0f7f07e734365c9bc
View file https://github.com/krassx/node/blob/3a439201da6658774291fec82e42f4a166125402/src/node_api.cc
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/nodejs/node/pull/66019/{{ revealButtonHref }}
https://github.com/nodejs/node/pull/66019/changes#diff-2057dbe503dbb37a65a74cf86e056d50c27ba828070577e0f7f07e734365c9bc
https://github.com/nodejs/node/pull/66019/changes#diff-2057dbe503dbb37a65a74cf86e056d50c27ba828070577e0f7f07e734365c9bc
test/node-api/test_module_version_mismatch/binding.gyphttps://github.com/nodejs/node/pull/66019/changes#diff-9122cc90694bafa1b2d5c8244da0700a82897430b9435df086d308efe6e90b13
View file https://github.com/krassx/node/blob/3a439201da6658774291fec82e42f4a166125402/test/node-api/test_module_version_mismatch/binding.gyp
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/nodejs/node/pull/66019/{{ revealButtonHref }}
test/node-api/test_module_version_mismatch/test.jshttps://github.com/nodejs/node/pull/66019/changes#diff-bc24d5acc68a0c6aee80d94f5659aaf7c59cc466d21f06f0ecdf31db8b307cd4
View file https://github.com/krassx/node/blob/3a439201da6658774291fec82e42f4a166125402/test/node-api/test_module_version_mismatch/test.js
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/nodejs/node/pull/66019/{{ revealButtonHref }}
test/node-api/test_module_version_mismatch/test_module_version_mismatch.chttps://github.com/nodejs/node/pull/66019/changes#diff-4bb85f8301e4abb78c71ff80c829b5176055798c372115da746e9d539ce64af0
View file https://github.com/krassx/node/blob/3a439201da6658774291fec82e42f4a166125402/test/node-api/test_module_version_mismatch/test_module_version_mismatch.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/nodejs/node/pull/66019/{{ revealButtonHref }}
Please reload this pagehttps://github.com/nodejs/node/pull/66019/changes
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.