@@ -33,11 +33,18 @@ If you find a potential security vulnerability, please refer to our
33
33
34
34
Node.js contains experimental support for creating policies on loading code.
35
35
36
- Policies are a security feature intended to allow guarantees
37
- about what code Node.js is able to load. The use of policies assumes
38
- safe practices for the policy files such as ensuring that policy
39
- files cannot be overwritten by the Node.js application by using
40
- file permissions.
36
+ Policies are a security feature intended to ensure the integrity
37
+ of the loaded code.
38
+
39
+ While it does not function as a provenance mechanism to trace the origin of
40
+ code, it serves as a robust defense against the execution of malicious code.
41
+ Unlike runtime-based models that may restrict capabilities once the code is
42
+ loaded, Node.js policies focus on preventing malicious code from ever being
43
+ fully loaded into the application in the first place.
44
+
45
+ The use of policies assumes safe practices for the policy
46
+ files such as ensuring that policy files cannot be overwritten by the Node.js
47
+ application by using file permissions.
41
48
42
49
A best practice would be to ensure that the policy manifest is read-only for
43
50
the running Node.js application and that the file cannot be changed
@@ -202,12 +209,6 @@ the manifest and then immediately used without searching.
202
209
Any specifier string for which resolution is attempted and that is not listed in
203
210
the dependencies results in an error according to the policy.
204
211
205
- Redirection does not prevent access to APIs through means such as direct access
206
- to ` require.cache ` or through ` module.constructor ` which allow access to
207
- loading modules. Policy redirection only affects specifiers to ` require() ` and
208
- ` import ` . Other means, such as to prevent undesired access to APIs through
209
- variables, are necessary to lock down that path of loading modules.
210
-
211
212
A boolean value of ` true ` for the dependencies map can be specified to allow a
212
213
module to load any specifier without redirection. This can be useful for local
213
214
development and may have some valid usage in production, but should be used
@@ -224,6 +225,9 @@ can be used to ensure some kinds of dynamic access are explicitly prevented.
224
225
Unknown values for the resolved module location cause failures but are
225
226
not guaranteed to be forward compatible.
226
227
228
+ All the guarantees for policy redirection are specified in the
229
+ [ Guarantees] ( #guarantees ) section.
230
+
227
231
##### Example: Patched dependency
228
232
229
233
Redirected dependencies can provide attenuated or modified functionality as fits
@@ -446,6 +450,18 @@ not adopt the origin of the `blob:` URL.
446
450
Additionally, import maps only work on ` import ` so it may be desirable to add a
447
451
` "import" ` condition to all dependency mappings.
448
452
453
+ #### Guarantees
454
+
455
+ * The policies guarantee the file integrity when a module is loaded using
456
+ ` require() ` , ` import() ` or ` new Module() ` .
457
+ * Redirection does not prevent access to APIs through means such as direct
458
+ access to ` require.cache ` which allow access to loaded modules.
459
+ Policy redirection only affects specifiers to ` require() ` and
460
+ ` import ` .
461
+ * The approval of the module integrity in policies threat model implies
462
+ they are allowed to muck with and even circumvent security features once
463
+ loaded so environmental/runtime hardening is expected.
464
+
449
465
## Process-based permissions
450
466
451
467
### Permission Model
0 commit comments