-
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 pull request #14 from AikidoSec/dev
Dev
- Loading branch information
Showing
4 changed files
with
117 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Express | ||
|
||
At the very beginning of your app.js file, add the following line: | ||
|
||
```js | ||
const { protect, preventPrototypePollution } = require('@aikidosec/guard'); | ||
|
||
protect(); // <-- Call this before any other code or imports | ||
|
||
const express = require('express'); | ||
|
||
preventPrototypePollution(); // <-- Call this after your main imports | ||
|
||
// ... | ||
``` | ||
|
||
You can read more about `preventPrototypePollution` [here](./prototype-pollution.md). | ||
|
||
or ESM import style: | ||
|
||
```js | ||
import { protect, preventPrototypePollution } from '@aikidosec/guard'; | ||
|
||
// ... | ||
``` | ||
|
||
That's it! Your Express app is now protected by Aikido guard. | ||
|
||
## Debug mode | ||
|
||
If you need to debug the guard, you can set the `debug` option to `true`: | ||
|
||
```js | ||
protect({ debug: true }); | ||
``` | ||
|
||
This will output debug information to the console (e.g. if the agent failed to start, no token was found, unsupported packages, ...). |
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,43 @@ | ||
# AWS Lambda | ||
|
||
At the very beginning of your handler.js file, add the following line: | ||
|
||
```js | ||
const { lambda, preventPrototypePollution } = require("@aikidosec/guard"); | ||
|
||
const protect = lambda(); // <-- Call this before any other code or imports | ||
|
||
const dependency = require("dependency"); | ||
|
||
preventPrototypePollution(); // <-- Call this after your main imports | ||
|
||
exports.handler = protect(async (event, context) => { | ||
// ... | ||
}); | ||
``` | ||
|
||
You can read more about `preventPrototypePollution` [here](./prototype-pollution.md). | ||
|
||
or ESM import style: | ||
|
||
```js | ||
import { lambda, preventPrototypePollution } from '@aikidosec/guard'; | ||
``` | ||
|
||
In order for the RASP to work properly, we need the following event properties to be present: | ||
|
||
* `event.body` | ||
* `event.httpMethod` (optional) | ||
* `event.headers` (optional) | ||
|
||
That's it! Your AWS Lambda function is now protected by Aikido guard. | ||
|
||
## Debug mode | ||
|
||
If you need to debug the guard, you can set the `debug` option to `true`: | ||
|
||
```js | ||
protect({ debug: true }); | ||
``` | ||
|
||
This will output debug information to the console (e.g. if the agent failed to start, no token was found, unsupported packages, ...). |
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,27 @@ | ||
# Protect against prototype pollution | ||
|
||
Aikido guard can also protect your application against [prototype pollution attacks](https://www.aikido.dev/blog/prevent-prototype-pollution). | ||
|
||
It works by calling [Object.freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze) for some built-in JavaScript objects. | ||
|
||
> The `Object.freeze()` method freezes an object. A frozen object can no longer be changed; freezing an object prevents new properties from being added to it, existing properties from being removed, prevents changing the enumerability, configurability, or writability of existing properties, and prevents the values of existing properties from being changed. | ||
We believe that there are legitimate cases of prototype changes, but they should happen only during the initialization step. Hence, we recommend calling `preventPrototypePollution` when your application is initialised. | ||
|
||
```js | ||
import { preventPrototypePollution } from '@aikidosec/guard'; | ||
|
||
import express from 'express'; | ||
|
||
preventPrototypePollution(); // <-- Call this after your main imports | ||
|
||
const app = express(); | ||
|
||
app.get("/", (req, res) => { | ||
res.send("Hello, world!"); | ||
}); | ||
|
||
app.listen(3000, () => { | ||
console.log("Server is running on port 3000"); | ||
}); | ||
``` |