Repository navigation
Commit 066fcbd
committed
src,lib: add --allow-env permission
Necessarily semver-major.
When `--permission` is on, every env var not matched by
`--allow-env` is removed at startup. It takes names,
patterns (`PREFI_*`), or `*`, repeatable or comma-sep'd.
There are a range of env vars that Node.js itself uses,
and a default range that are generally known to be safe
in common usage. These are never scrubbed. These include
things like `NODE_OPTIONS`, `NODE_EXTRA_CA_CERTS`, `PATH`,
`HOME`, etc.
Env vars can be dropped at runtime after reading using
`permission.drop()`. This is a stronger protection than
using `process.env.FOO = undefined` because it will
scrub the env var also from the environment block.
On Linux, the removed entries are overwritten in the
initial environment block and fs reads of /proc/*/environ
are denied.
On Windows, removal also clears the C runtime's copy
of the environ using _wputenv_s
Reading a removed name returns undefined, warns once per
name, and publishes to a diagnostics channel.
Env file keys are allowed. If the user had reason to pass
in an env file the assumption is they meant to allow them.
File-source config (node.config.json and NODE_OPTIONS
from a .env file can only narrow the allow list.
Embedders must call ScrubProcessEnvironment() themselves
on startup. This is left up to the embedder to determine
the exact timing but needs to be called before startup
actually happens.
Child processes are started with `--allow-env=*`. Those
either receive the explicit env they were started with
or only the env they inherit from the parent. Since the
parent process is scrubbed, it should never be more than
what the parent can see.
Main part of the impl was done by hand. Docs, tests,
verification pass, and cleanup nits were automated.
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode1 parent 3cd2d6e commit 066fcbd
45 files changed
Lines changed: 2107 additions & 23 deletions
File tree
- doc
- api
- lib
- internal/process
- src
- permission
- test
- cctest
- embedding
- parallel
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
194 | 238 | | |
195 | 239 | | |
196 | 240 | | |
| |||
2538 | 2582 | | |
2539 | 2583 | | |
2540 | 2584 | | |
| 2585 | + | |
2541 | 2586 | | |
2542 | 2587 | | |
2543 | 2588 | | |
| |||
4128 | 4173 | | |
4129 | 4174 | | |
4130 | 4175 | | |
| 4176 | + | |
4131 | 4177 | | |
4132 | 4178 | | |
4133 | 4179 | | |
| |||
4776 | 4822 | | |
4777 | 4823 | | |
4778 | 4824 | | |
| 4825 | + | |
4779 | 4826 | | |
4780 | 4827 | | |
4781 | 4828 | | |
| |||
4799 | 4846 | | |
4800 | 4847 | | |
4801 | 4848 | | |
| 4849 | + | |
4802 | 4850 | | |
4803 | 4851 | | |
4804 | 4852 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
75 | 120 | | |
76 | 121 | | |
77 | 122 | | |
| |||
178 | 223 | | |
179 | 224 | | |
180 | 225 | | |
| 226 | + | |
| 227 | + | |
181 | 228 | | |
182 | 229 | | |
183 | 230 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
65 | | - | |
66 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
| |||
157 | 159 | | |
158 | 160 | | |
159 | 161 | | |
160 | | - | |
161 | | - | |
162 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
163 | 165 | | |
164 | 166 | | |
165 | 167 | | |
| |||
172 | 174 | | |
173 | 175 | | |
174 | 176 | | |
| 177 | + | |
175 | 178 | | |
176 | 179 | | |
177 | 180 | | |
| |||
266 | 269 | | |
267 | 270 | | |
268 | 271 | | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
269 | 344 | | |
270 | 345 | | |
271 | 346 | | |
| |||
297 | 372 | | |
298 | 373 | | |
299 | 374 | | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
300 | 389 | | |
301 | 390 | | |
302 | 391 | | |
| |||
342 | 431 | | |
343 | 432 | | |
344 | 433 | | |
| 434 | + | |
345 | 435 | | |
346 | 436 | | |
347 | 437 | | |
| |||
404 | 494 | | |
405 | 495 | | |
406 | 496 | | |
| 497 | + | |
407 | 498 | | |
408 | 499 | | |
409 | 500 | | |
410 | 501 | | |
411 | 502 | | |
412 | 503 | | |
413 | 504 | | |
| 505 | + | |
| 506 | + | |
414 | 507 | | |
415 | 508 | | |
| 509 | + | |
416 | 510 | | |
417 | 511 | | |
| 512 | + | |
418 | 513 | | |
| 514 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3163 | 3163 | | |
3164 | 3164 | | |
3165 | 3165 | | |
| 3166 | + | |
3166 | 3167 | | |
3167 | 3168 | | |
3168 | 3169 | | |
| |||
3220 | 3221 | | |
3221 | 3222 | | |
3222 | 3223 | | |
| 3224 | + | |
| 3225 | + | |
3223 | 3226 | | |
3224 | 3227 | | |
3225 | 3228 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
121 | 156 | | |
122 | 157 | | |
123 | 158 | | |
| |||
1274 | 1309 | | |
1275 | 1310 | | |
1276 | 1311 | | |
| 1312 | + | |
| 1313 | + | |
1277 | 1314 | | |
1278 | 1315 | | |
1279 | 1316 | | |
| |||
2088 | 2125 | | |
2089 | 2126 | | |
2090 | 2127 | | |
| 2128 | + | |
| 2129 | + | |
2091 | 2130 | | |
2092 | 2131 | | |
2093 | 2132 | | |
| |||
0 commit comments