Skip to content

Commit a9c6324

Browse files
authored
Merge pull request #847 from AikidoSec/dotenv
Add note about loading env variables in ESM mode
2 parents 9d85c50 + 1f045b7 commit a9c6324

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

docs/esm.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,22 @@ Alternatively, you can set the `NODE_OPTIONS` environment variable to include th
1515
export NODE_OPTIONS='-r @aikidosec/firewall/instrument'
1616
```
1717

18-
> [!IMPORTANT]
18+
> [!IMPORTANT]
1919
> Please also check the documentation on how to integrate Zen with your used web framework.
2020
21+
## Loading environment variables
22+
23+
When using `--require`/`-r` to preload the Zen firewall, the instrumentation hook runs before your application code. This means environment variables loaded by packages like `dotenv` will not be available when Zen starts.
24+
25+
To ensure `AIKIDO_TOKEN` and other environment variables are available during instrumentation, use Node.js's native `--env-file` flag:
26+
27+
```sh
28+
node --env-file=.env -r @aikidosec/firewall/instrument your-app.js
29+
```
30+
31+
> [!NOTE]
32+
> The `--env-file` flag cannot be used in `NODE_OPTIONS`.
33+
2134
## Known issues
2235

2336
- Zen can not protect ESM sub-dependencies of an ESM package. For example if an ESM package `foo` imports a sub-dependency `bar` that is also an ESM package, Zen will not be able to protect the code in `bar`. This is because the V8 engine does not allow Node.js to observe the evaluation of inner ESM packages (yet). Open issue: [Adding an evaluation hook for v8::Module](https://issues.chromium.org/u/1/issues/384413088). See a full example below.

0 commit comments

Comments
 (0)