@@ -33,11 +33,18 @@ If you find a potential security vulnerability, please refer to our
3333
3434Node.js contains experimental support for creating policies on loading code.
3535
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.
4148
4249A best practice would be to ensure that the policy manifest is read-only for
4350the running Node.js application and that the file cannot be changed
@@ -202,12 +209,6 @@ the manifest and then immediately used without searching.
202209Any specifier string for which resolution is attempted and that is not listed in
203210the dependencies results in an error according to the policy.
204211
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-
211212A boolean value of ` true ` for the dependencies map can be specified to allow a
212213module to load any specifier without redirection. This can be useful for local
213214development 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.
224225Unknown values for the resolved module location cause failures but are
225226not guaranteed to be forward compatible.
226227
228+ All the guarantees for policy redirection are specified in the
229+ [ Guarantees] ( #guarantees ) section.
230+
227231##### Example: Patched dependency
228232
229233Redirected dependencies can provide attenuated or modified functionality as fits
@@ -446,6 +450,18 @@ not adopt the origin of the `blob:` URL.
446450Additionally, import maps only work on ` import ` so it may be desirable to add a
447451` "import" ` condition to all dependency mappings.
448452
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+
449465## Process-based permissions
450466
451467### Permission Model
0 commit comments