-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:AikidoSec/node-RASP into patch-ssrf…
…-enable * 'main' of github.com:AikidoSec/node-RASP: (113 commits) Add performance test Shorten function Shorten methods Fix tests for attackPath Add failing tests Add breaking test Add test Add more tests Improve test coverage Extend and fix tests Link to Aikido Blog for Command Injection attacks Use more efficient ip matcher Fix tests Fix again fix: Wrong payload path after merge Fix tests Delete jwt.iss Add test Use new Zen internals JS parser Update Zen Internals ...
- Loading branch information
Showing
135 changed files
with
34,514 additions
and
5,748 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Installing Zen in a Node.js Application Bundled with esbuild | ||
|
||
Note: Zen runs only on the server side, it does not run in the browser. | ||
|
||
Note: If `bundle` is set to `false` in the esbuild configuration, Zen will work without any additional configuration. | ||
|
||
Modify your esbuild configuration to include the external option using this utility: | ||
|
||
```js | ||
const { build } = require("esbuild"); | ||
const { externals } = require("@aikidosec/firewall/bundler"); // <-- Add this line | ||
|
||
build({ | ||
entryPoints: ["./app.js"], | ||
bundle: true, | ||
platform: "node", | ||
target: "node18", | ||
outfile: "./dist/app.js", | ||
external: externals(), // <-- Add this line | ||
}); | ||
``` | ||
|
||
This tells esbuild to exclude @aikidosec/firewall and any packages that Zen hooks into from the bundle. | ||
|
||
⚠️ Don't forget to copy the node_modules directory to the output directory. | ||
|
||
## Why do I need to do this? | ||
|
||
Zen works by intercepting `require()` calls that a Node.js application makes when loading modules. This includes modules that are built-in to Node.js, like the `fs` module for accessing the filesystem, as well as modules installed from the NPM registry, like the `pg` database module. | ||
|
||
Bundlers like esbuild crawl all of the `require()` calls that an application makes to files on disk. It replaces the `require()` calls with custom code and combines all the resulting JavaScript into one "bundled" file. When a built-in module is loaded, such as `require('fs')`, that call can then remain the same in the resulting bundle. | ||
|
||
Zen can continue to intercept the calls for built-in modules but cannot intercept calls to third party libraries under those conditions. This means that when you bundle a Zen app with a bundler Zen is likely to capture information about disk access (through `fs`) and outbound HTTP requests (through `http`), but omit calls to third party libraries. | ||
|
||
The solution is to treat all third party modules that Zen needs to instrument as being "external" to the bundler. With this setting the instrumented modules remain on disk and continue to be loaded with `require()` while the non-instrumented modules are bundled. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { getBlockedIPAddresses } = require("../zen/config"); | ||
|
||
module.exports = function ipLists(req, res) { | ||
if (!req.app) { | ||
throw new Error("App is missing"); | ||
} | ||
|
||
const blockedIps = getBlockedIPAddresses(req.app); | ||
|
||
res.json({ | ||
success: true, | ||
serviceId: req.app.id, | ||
blockedIPAddresses: | ||
blockedIps.length > 0 | ||
? [ | ||
{ | ||
source: "geoip", | ||
description: "geo restrictions", | ||
ips: blockedIps, | ||
}, | ||
] | ||
: [], | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const { updateBlockedIPAddresses } = require("../zen/config"); | ||
|
||
module.exports = function updateIPLists(req, res) { | ||
if (!req.app) { | ||
throw new Error("App is missing"); | ||
} | ||
|
||
// Insecure input validation - but this is only a mock server | ||
if ( | ||
!req.body || | ||
typeof req.body !== "object" || | ||
Array.isArray(req.body) || | ||
!Object.keys(req.body).length | ||
) { | ||
return res.status(400).json({ | ||
message: "Request body is missing or invalid", | ||
}); | ||
} | ||
|
||
if ( | ||
!req.body.blockedIPAddresses || | ||
!Array.isArray(req.body.blockedIPAddresses) | ||
) { | ||
return res.status(400).json({ | ||
message: "blockedIPAddresses is missing or invalid", | ||
}); | ||
} | ||
|
||
updateBlockedIPAddresses(req.app, req.body.blockedIPAddresses); | ||
|
||
res.json({ success: true }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.