Skip to content

Commit 058e7b5

Browse files
committed
doc: clarify policy expectations
1 parent 48345d0 commit 058e7b5

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

doc/api/permissions.md

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,18 @@ If you find a potential security vulnerability, please refer to our
3333

3434
Node.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+
The use of policies assumes safe practices for the policy
40+
files such as ensuring that policy files cannot be overwritten by the Node.js
41+
application by using file permissions.
42+
43+
While it does not function as a provenance mechanism to trace the origin of
44+
code, it serves as a robust defense against the execution of malicious code.
45+
Unlike runtime-based models that may restrict capabilities once the code is
46+
loaded, Node.js policies focus on preventing malicious code from ever being
47+
fully loaded into the application in the first place.
4148

4249
A best practice would be to ensure that the policy manifest is read-only for
4350
the running Node.js application and that the file cannot be changed
@@ -202,12 +209,6 @@ the manifest and then immediately used without searching.
202209
Any specifier string for which resolution is attempted and that is not listed in
203210
the 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-
211212
A boolean value of `true` for the dependencies map can be specified to allow a
212213
module to load any specifier without redirection. This can be useful for local
213214
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.
224225
Unknown values for the resolved module location cause failures but are
225226
not 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

229233
Redirected dependencies can provide attenuated or modified functionality as fits
@@ -446,6 +450,16 @@ not adopt the origin of the `blob:` URL.
446450
Additionally, 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()` or `import()`.
457+
* Redirection does not prevent access to APIs through means such as direct
458+
access to `require.cache` or through `module.constructor` which allow access to
459+
loading modules. Policy redirection only affects specifiers to `require()` and
460+
`import`. Other means, such as to prevent undesired access to APIs through
461+
variables, are necessary to lock down that path of loading modules.
462+
449463
## Process-based permissions
450464

451465
### Permission Model

0 commit comments

Comments
 (0)