Skip to content

Commit 33f4ef5

Browse files
committed
v2.0.0
- Added header sanitization - Drop support for node <10 - Bump dev dependencies
1 parent ae45543 commit 33f4ef5

File tree

6 files changed

+1632
-43
lines changed

6 files changed

+1632
-43
lines changed

.travis.yml

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
language: node_js
22
node_js:
3-
- '0.10'
4-
- '0.12'
5-
- '4'
6-
- '5'
7-
- '6'
8-
- '7'
3+
- '10'
4+
- '12'

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [2.0.0] - 2020-03-25
6+
### Added / Breaking
7+
- Support sanitization of headers. #5
8+
9+
Note that if you weren't previously expecting headers to be sanitized, this is considered a breaking change.
10+
11+
### Breaking
12+
- Drop support for node versions < 10.
13+
514
## [1.3.2] - 2017-01-12
615
### Fixed
716
- Fixed an issue when using the sanitizer in the node REPL. #3
@@ -27,6 +36,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2736

2837
Initial Release.
2938

39+
[2.0.0]: https://github.com/fiznool/express-mongo-sanitize/compare/v1.3.2...v2.0.0
3040
[1.3.2]: https://github.com/fiznool/express-mongo-sanitize/compare/v1.3.1...v1.3.2
3141
[1.3.1]: https://github.com/fiznool/express-mongo-sanitize/compare/v1.3.0...v1.3.1
3242
[1.3.0]: https://github.com/fiznool/express-mongo-sanitize/compare/v1.2.0...v1.3.0

index.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
'use strict';
22

3-
var TEST_REGEX = /^\$|\./,
4-
REPLACE_REGEX = /^\$|\./g;
3+
const TEST_REGEX = /^\$|\./;
4+
const REPLACE_REGEX = /^\$|\./g;
55

66
function isPlainObject(obj) {
77
return typeof obj === 'object' && obj !== null;
88
}
99

1010
function withEach(target, cb) {
11-
var act = function(obj) {
11+
(function act(obj) {
1212
if(Array.isArray(obj)) {
1313
obj.forEach(act);
1414

1515
} else if(isPlainObject(obj)) {
1616
Object.keys(obj).forEach(function(key) {
17-
var val = obj[key];
18-
var resp = cb(obj, val, key);
17+
const val = obj[key];
18+
const resp = cb(obj, val, key);
1919
if(resp.shouldRecurse) {
2020
act(obj[resp.key || key]);
2121
}
2222
});
2323
}
24-
};
24+
})(target);
2525

26-
act(target);
2726
}
2827

2928
function has(target) {
30-
var hasProhibited = false;
29+
let hasProhibited = false;
3130
withEach(target, function(obj, val, key) {
3231
if(TEST_REGEX.test(key)) {
3332
hasProhibited = true;
@@ -43,13 +42,13 @@ function has(target) {
4342
function sanitize(target, options) {
4443
options = options || {};
4544

46-
var replaceWith = null;
45+
let replaceWith = null;
4746
if(!(TEST_REGEX.test(options.replaceWith))) {
4847
replaceWith = options.replaceWith;
4948
}
5049

5150
withEach(target, function(obj, val, key) {
52-
var shouldRecurse = true;
51+
let shouldRecurse = true;
5352

5453
if(TEST_REGEX.test(key)) {
5554
delete obj[key];
@@ -72,7 +71,7 @@ function sanitize(target, options) {
7271

7372
function middleware(options) {
7473
return function(req, res, next) {
75-
['body', 'params', 'query'].forEach(function(k) {
74+
['body', 'params', 'headers', 'query'].forEach(function(k) {
7675
if(req[k]) {
7776
req[k] = sanitize(req[k], options);
7877
}

0 commit comments

Comments
 (0)