Skip to content

Commit f0e4c4c

Browse files
committed
Prettier
1 parent df92588 commit f0e4c4c

12 files changed

+5190
-529
lines changed

.github/dependabot.yml

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
version: 2
22
updates:
3-
- package-ecosystem: npm
4-
directory: "/"
5-
schedule:
6-
interval: daily
7-
open-pull-requests-limit: 10
8-
ignore:
9-
- dependency-name: eslint
10-
versions:
11-
- 7.18.0
12-
- 7.19.0
13-
- 7.20.0
14-
- 7.21.0
15-
- 7.23.0
16-
- dependency-name: mocha
17-
versions:
18-
- 8.3.0
19-
- 8.3.1
20-
- dependency-name: chai
21-
versions:
22-
- 4.3.0
23-
- 4.3.1
24-
- 4.3.3
3+
- package-ecosystem: npm
4+
directory: '/'
5+
schedule:
6+
interval: daily
7+
open-pull-requests-limit: 10
8+
ignore:
9+
- dependency-name: eslint
10+
versions:
11+
- 7.18.0
12+
- 7.19.0
13+
- 7.20.0
14+
- 7.21.0
15+
- 7.23.0
16+
- dependency-name: mocha
17+
versions:
18+
- 8.3.0
19+
- 8.3.1
20+
- dependency-name: chai
21+
versions:
22+
- 4.3.0
23+
- 4.3.1
24+
- 4.3.3

.github/workflows/nodejs.yml

+11-12
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,25 @@ name: Node.js CI
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [master]
66
pull_request:
7-
branches: [ master ]
7+
branches: [master]
88

99
jobs:
1010
build:
11-
1211
runs-on: ubuntu-latest
1312

1413
strategy:
1514
matrix:
1615
node-version: [10.x, 12.x, 14.x, 16.x]
1716

1817
steps:
19-
- uses: actions/checkout@v2
20-
- name: Use Node.js ${{ matrix.node-version }}
21-
uses: actions/setup-node@v1
22-
with:
23-
node-version: ${{ matrix.node-version }}
24-
- run: npm ci
25-
- run: npm test
26-
env:
27-
CI: true
18+
- uses: actions/checkout@v2
19+
- name: Use Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v1
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
- run: npm ci
24+
- run: npm test
25+
env:
26+
CI: true

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"bracketSpacing": true,
3+
"singleQuote": true,
4+
"trailingComma": "all"
5+
}

CHANGELOG.md

+20
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,70 @@
11
# Change Log
2+
23
All notable changes to this project will be documented in this file.
34
This project adheres to [Semantic Versioning](http://semver.org/).
45

56
## [2.0.2] - 2021-01-07
7+
68
### Fixed
9+
710
- Fixed a prototype pollution security vulnerability. #34
811

912
### Updated
13+
1014
- Update dependencies.
1115

1216
## [2.0.1] - 2020-12-02
17+
1318
### Updated
19+
1420
- Update dependencies and test against node 14.
1521

1622
### Changed
23+
1724
- Use ESLint instead of JSHint for code linting.
1825
- Use GitHub Actions for CI instead of Travis.
1926

2027
## [2.0.0] - 2020-03-25
28+
2129
### Added / Breaking
30+
2231
- Support sanitization of headers. #5
2332

2433
Note that if you weren't previously expecting headers to be sanitized, this is considered a breaking change.
2534

2635
### Breaking
36+
2737
- Drop support for node versions < 10.
2838

2939
## [1.3.2] - 2017-01-12
40+
3041
### Fixed
42+
3143
- Fixed an issue when using the sanitizer in the node REPL. #3
3244

3345
## [1.3.1] - 2017-01-12
46+
3447
### Fixed
48+
3549
- Fixed an issue with objects containing prohibited keys nested inside other objects with prohibited keys. #2
3650
- Added a more robust check for plain objects.
3751

3852
## [1.3.0] - 2016-01-15
53+
3954
### Added
55+
4056
- A new function `has`, which checks whether a passed object/array contains any keys with prohibited characters.
4157

4258
## [1.2.0] - 2016-01-13
59+
4360
### Added
61+
4462
- A new option `replaceWith` which can be used to replace offending characters in a key. This is an alternative to removing the data from the payload.
4563

4664
## [1.1.0] - 2016-01-13
65+
4766
### Added
67+
4868
- The middleware also now sanitizes keys with a `.`. This is in line with Mongo's reserved operators.
4969

5070
## 1.0.0 - 2015-11-11

README.md

+25-21
Original file line numberDiff line numberDiff line change
@@ -8,67 +8,71 @@ Express 4.x middleware which sanitizes user-supplied data to prevent MongoDB Ope
88
[![Dependency Status](https://david-dm.org/fiznool/express-mongo-sanitize.svg)](https://david-dm.org/fiznool/express-mongo-sanitize)
99
[![devDependency Status](https://david-dm.org/fiznool/express-mongo-sanitize/dev-status.svg)](https://david-dm.org/fiznool/express-mongo-sanitize#info=devDependencies)
1010

11-
1211
## Installation
1312

14-
``` bash
13+
```bash
1514
npm install express-mongo-sanitize
1615
```
1716

1817
## Usage
1918

2019
Add as a piece of express middleware, before defining your routes.
2120

22-
``` js
21+
```js
2322
const express = require('express');
2423
const bodyParser = require('body-parser');
2524
const mongoSanitize = require('express-mongo-sanitize');
2625

2726
const app = express();
2827

29-
app.use(bodyParser.urlencoded({extended: true}));
28+
app.use(bodyParser.urlencoded({ extended: true }));
3029
app.use(bodyParser.json());
3130

3231
// To remove data, use:
3332
app.use(mongoSanitize());
3433

3534
// Or, to replace prohibited characters with _, use:
36-
app.use(mongoSanitize({
37-
replaceWith: '_'
38-
}));
39-
35+
app.use(
36+
mongoSanitize({
37+
replaceWith: '_',
38+
}),
39+
);
4040
```
4141

4242
### `onSanitize`
4343

4444
`onSanitize` callback is called after the request's value was sanitized.
4545

4646
```js
47-
app.use(mongoSanitize({
48-
onSanitize: ({ req, key }) => {
49-
console.warn(`This request[${key}] is sanitized`, req);
50-
}
51-
}));
47+
app.use(
48+
mongoSanitize({
49+
onSanitize: ({ req, key }) => {
50+
console.warn(`This request[${key}] is sanitized`, req);
51+
},
52+
}),
53+
);
5254
```
5355

5456
### `dryRun`
5557

5658
You can run this middleware as dry run mode.
5759

5860
```js
59-
app.use(mongoSanitize({
60-
dryRun: true,
61-
onSanitize: ({ req, key }) => {
62-
console.warn(`[DryRun] This request[${key}] will be sanitized`, req);
63-
}
64-
}));
61+
app.use(
62+
mongoSanitize({
63+
dryRun: true,
64+
onSanitize: ({ req, key }) => {
65+
console.warn(`[DryRun] This request[${key}] will be sanitized`, req);
66+
},
67+
}),
68+
);
6569
```
6670

6771
### Node Modules API
6872

6973
You can also bypass the middleware and use the module directly:
7074

71-
``` js
75+
```js
7276
const mongoSanitize = require('express-mongo-sanitize');
7377

7478
const payload = {...};
@@ -98,7 +102,7 @@ See the spec file for more examples.
98102

99103
## Why?
100104

101-
Object keys starting with a `$` or containing a `.` are _reserved_ for use by MongoDB as operators. Without this sanitization, malicious users could send an object containing a `$` operator, or including a `.`, which could change the context of a database operation. Most notorious is the `$where` operator, which can execute arbitrary JavaScript on the database.
105+
Object keys starting with a `$` or containing a `.` are _reserved_ for use by MongoDB as operators. Without this sanitization, malicious users could send an object containing a `$` operator, or including a `.`, which could change the context of a database operation. Most notorious is the `$where` operator, which can execute arbitrary JavaScript on the database.
102106

103107
The best way to prevent this is to sanitize the received data, and remove any offending keys, or replace the characters with a 'safe' one.
104108

SECURITY.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ The following table describes the versions of this project that are currently su
66

77
| Version | Supported |
88
| ------- | ------------------ |
9-
| 2.x | :white_check_mark: |
10-
| 1.x | :x: |
9+
| 2.x | :white_check_mark: |
10+
| 1.x | :x: |
1111

1212
## Responsible disclosure security policy
1313

index.d.ts

+26-24
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
1-
import {Request, Response, Handler} from "express"
1+
import { Request, Response, Handler } from 'express';
22

33
declare namespace ExpressMongoSanitize {
4-
interface Options {
5-
replaceWith?: string;
6-
onSanitize?: (req: Request, res: Response) => unknown;
7-
dryRun?: boolean;
8-
}
4+
interface Options {
5+
replaceWith?: string;
6+
onSanitize?: (req: Request, res: Response) => unknown;
7+
dryRun?: boolean;
8+
}
99
}
1010

11-
1211
type Middleware = {
13-
/**
14-
* Create middleware instance
15-
* @param options
16-
*/
17-
(options?: ExpressMongoSanitize.Options): Handler;
18-
/**
19-
* Remove any keys containing prohibited characters
20-
* @param target
21-
* @param options
22-
*/
23-
sanitize<T extends Record<string, unknown> | unknown[]>(target: T, options?: ExpressMongoSanitize.Options): T;
24-
/**
25-
* Check if the payload has keys with prohibited characters‘
26-
* @param target
27-
*/
28-
has(target: Record<string, unknown> | unknown[]): boolean;
12+
/**
13+
* Create middleware instance
14+
* @param options
15+
*/
16+
(options?: ExpressMongoSanitize.Options): Handler;
17+
/**
18+
* Remove any keys containing prohibited characters
19+
* @param target
20+
* @param options
21+
*/
22+
sanitize<T extends Record<string, unknown> | unknown[]>(
23+
target: T,
24+
options?: ExpressMongoSanitize.Options,
25+
): T;
26+
/**
27+
* Check if the payload has keys with prohibited characters‘
28+
* @param target
29+
*/
30+
has(target: Record<string, unknown> | unknown[]): boolean;
2931
};
3032

3133
declare const ExpressMongoSanitize: Middleware & {
32-
default: typeof ExpressMongoSanitize;
34+
default: typeof ExpressMongoSanitize;
3335
};
3436

3537
export = ExpressMongoSanitize;

0 commit comments

Comments
 (0)