File tree Expand file tree Collapse file tree 6 files changed +29
-0
lines changed Open diff view settings
Expand file tree Collapse file tree 6 files changed +29
-0
lines changed Open diff view settings
Original file line number Diff line number Diff line change @@ -439,6 +439,13 @@ added: v6.0.0
439439
440440Silence all process warnings (including deprecations).
441441
442+ ### ` --force-context-aware `
443+ <!-- YAML
444+ added: REPLACEME
445+ -->
446+
447+ Disable loading non-context-aware native addons.
448+
442449### ` --openssl-config=file `
443450<!-- YAML
444451added: v6.9.0
@@ -1009,6 +1016,7 @@ Node.js options that are allowed are:
10091016* ` --experimental-report `
10101017* ` --experimental-vm-modules `
10111018* ` --experimental-wasm-modules `
1019+ * ` --force-context-aware `
10121020* ` --force-fips `
10131021* ` --frozen-intrinsics `
10141022* ` --heapsnapshot-signal `
Original file line number Diff line number Diff line change @@ -1609,6 +1609,11 @@ OpenSSL crypto support.
16091609An attempt was made to use features that require [ ICU] [ ] , but Node.js was not
16101610compiled with ICU support.
16111611
1612+ <a id =" ERR_NON_CONTEXT_AWARE_DISABLED " ></a >
1613+ ### ERR_NON_CONTEXT_AWARE_DISABLED
1614+
1615+ A non-context-aware native addon was loaded in a process that disallows them.
1616+
16121617<a id =" ERR_OUT_OF_RANGE " ></a >
16131618### ERR_OUT_OF_RANGE
16141619
Original file line number Diff line number Diff line change 11#include " node_binding.h"
2+ #include " node_errors.h"
23#include < atomic>
34#include " env-inl.h"
45#include " node_native_module_env.h"
@@ -463,6 +464,13 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
463464 }
464465
465466 if (mp != nullptr ) {
467+ if (mp->nm_context_register_func == nullptr ) {
468+ if (env->options ()->force_context_aware ) {
469+ dlib->Close ();
470+ THROW_ERR_NON_CONTEXT_AWARE_DISABLED (env);
471+ return false ;
472+ }
473+ }
466474 mp->nm_dso_handle = dlib->handle_ ;
467475 dlib->SaveInGlobalHandleMap (mp);
468476 } else {
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ void PrintErrorString(const char* format, ...);
5252 V (ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST, TypeError) \
5353 V (ERR_MISSING_PASSPHRASE, TypeError) \
5454 V (ERR_MISSING_PLATFORM_FOR_WORKER, Error) \
55+ V (ERR_NON_CONTEXT_AWARE_DISABLED, Error) \
5556 V (ERR_MODULE_NOT_FOUND, Error) \
5657 V (ERR_OUT_OF_RANGE, RangeError) \
5758 V (ERR_SCRIPT_EXECUTION_INTERRUPTED, Error) \
@@ -96,6 +97,8 @@ void PrintErrorString(const char* format, ...);
9697 V (ERR_MISSING_PLATFORM_FOR_WORKER, \
9798 " The V8 platform used by this instance of Node does not support " \
9899 " creating Workers" ) \
100+ V (ERR_NON_CONTEXT_AWARE_DISABLED, \
101+ " Loading non context-aware native modules has been disabled" ) \
99102 V (ERR_SCRIPT_EXECUTION_INTERRUPTED, \
100103 " Script execution was interrupted by `SIGINT`" ) \
101104 V (ERR_TRANSFERRING_EXTERNALIZED_SHAREDARRAYBUFFER, \
Original file line number Diff line number Diff line change @@ -400,6 +400,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
400400 " silence all process warnings" ,
401401 &EnvironmentOptions::no_warnings,
402402 kAllowedInEnvironment );
403+ AddOption (" --force-context-aware" ,
404+ " disable loading non-context-aware addons" ,
405+ &EnvironmentOptions::force_context_aware,
406+ kAllowedInEnvironment );
403407 AddOption (" --pending-deprecation" ,
404408 " emit pending deprecation warnings" ,
405409 &EnvironmentOptions::pending_deprecation,
Original file line number Diff line number Diff line change @@ -118,6 +118,7 @@ class EnvironmentOptions : public Options {
118118 bool no_deprecation = false ;
119119 bool no_force_async_hooks_checks = false ;
120120 bool no_warnings = false ;
121+ bool force_context_aware = false ;
121122 bool pending_deprecation = false ;
122123 bool preserve_symlinks = false ;
123124 bool preserve_symlinks_main = false ;
You can’t perform that action at this time.
0 commit comments