mongodb-redact 0.2.3 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ import mod from "./index.js";
2
+
3
+ export default mod["default"];
4
+ export const redact = mod.redact;
@@ -0,0 +1,3 @@
1
+ export declare function redact<T>(message: T): T;
2
+ export default redact;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,CAoBvC;AAED,eAAe,MAAM,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.redact = redact;
7
+ const lodash_1 = __importDefault(require("lodash"));
8
+ const regexes_1 = require("./regexes");
9
+ function redact(message) {
10
+ if (lodash_1.default.isPlainObject(message)) {
11
+ return lodash_1.default.mapValues(message, redact);
12
+ }
13
+ if (lodash_1.default.isArray(message)) {
14
+ return lodash_1.default.map(message, redact);
15
+ }
16
+ if (typeof message !== 'string') {
17
+ return message;
18
+ }
19
+ for (const [regex, replacement] of regexes_1.regexes) {
20
+ message = message.replace(regex, replacement);
21
+ }
22
+ return message;
23
+ }
24
+ exports.default = redact;
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAGA,wBAoBC;AAvBD,oDAAuB;AACvB,uCAAoC;AAEpC,SAAgB,MAAM,CAAI,OAAU;IAClC,IAAI,gBAAC,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;QAE7B,OAAO,gBAAC,CAAC,SAAS,CAAC,OAAc,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;IACD,IAAI,gBAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAEvB,OAAO,gBAAC,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAM,CAAC;IACrC,CAAC;IACD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAEhC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,KAAK,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,IAAI,iBAAO,EAAE,CAAC;QAG3C,OAAO,GAAI,OAAsB,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,CAAe,CAAC;IAC9E,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,kBAAe,MAAM,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const regexes: readonly [readonly [RegExp, "$1$2$4<base64>$5"], readonly [RegExp, "<certificate>"], readonly [RegExp, "<private key>"], readonly [RegExp, "$1$2/<user>/"], readonly [RegExp, "$1$2\\<user>\\"], readonly [RegExp, "$1<email>"], readonly [RegExp, "<ip address>"], readonly [RegExp, "<url>"], readonly [RegExp, "<mongodb uri>"], readonly [RegExp, "#schema/<namespace>"]];
2
+ //# sourceMappingURL=regexes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regexes.d.ts","sourceRoot":"","sources":["../src/regexes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,+WAiDV,CAAC"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.regexes = void 0;
4
+ exports.regexes = [
5
+ [
6
+ /(BinData\()((0|[1-9][0-9]{0,2}))(\s*,\s*['"]?)[A-Za-z0-9+/=\s]+(['"]?\))/gm,
7
+ '$1$2$4<base64>$5',
8
+ ],
9
+ [/-----BEGIN CERTIFICATE-----.*-----END CERTIFICATE-----/gm, '<certificate>'],
10
+ [
11
+ /-----BEGIN RSA PRIVATE KEY-----.*-----END RSA PRIVATE KEY-----/gm,
12
+ '<private key>',
13
+ ],
14
+ [
15
+ /(file:\/\/|\/)(Users|user|users|user|usr|u01|var\/users|home|export\/home|Documents and Settings|Profiles)\/[^/]*\//gm,
16
+ '$1$2/<user>/',
17
+ ],
18
+ [
19
+ /(file:\/\/|\\)(Users|user|users|user|usr|u01|var\\users|home|export\\home|Documents and Settings|Profiles)\\[^/]*\\/gm,
20
+ '$1$2\\<user>\\',
21
+ ],
22
+ [
23
+ /(^|[ \t\r\n\v\f])([a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]{1,64}@[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?){1,500})/gim,
24
+ '$1<email>',
25
+ ],
26
+ [
27
+ /((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])/gm,
28
+ '<ip address>',
29
+ ],
30
+ [
31
+ /(http(s)?:\/\/)(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}(\.[a-z]{2,6})?\b([-a-zA-Z0-9@:%_+.~#?&/=]*)/gim,
32
+ '<url>',
33
+ ],
34
+ [
35
+ /(mongodb:\/\/)(www\.)?[-a-zA-Z0-9@:%._+~#=,]{2,256}(\.[a-z]{2,6})?\b([-a-zA-Z0-9@:%_+.~#?&/=]*)/gim,
36
+ '<mongodb uri>',
37
+ ],
38
+ [/#schema\/\w+\.\w+/, '#schema/<namespace>'],
39
+ ];
40
+ //# sourceMappingURL=regexes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regexes.js","sourceRoot":"","sources":["../src/regexes.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG;IACrB;QACE,4EAA4E;QAC5E,kBAAkB;KACnB;IAGD,CAAC,0DAA0D,EAAE,eAAe,CAAC;IAC7E;QACE,kEAAkE;QAClE,eAAe;KAChB;IAGD;QACE,uHAAuH;QACvH,cAAc;KACf;IACD;QACE,uHAAuH;QACvH,gBAAgB;KACjB;IAGD;QACE,+JAA+J;QAC/J,WAAW;KACZ;IAGD;QACE,iFAAiF;QACjF,cAAc;KACf;IAGD;QACE,oGAAoG;QACpG,OAAO;KACR;IAGD;QACE,oGAAoG;QACpG,eAAe;KAChB;IAGD,CAAC,mBAAmB,EAAE,qBAAqB,CAAC;CACpC,CAAC"}
package/package.json CHANGED
@@ -1,28 +1,70 @@
1
1
  {
2
2
  "name": "mongodb-redact",
3
- "version": "0.2.3",
4
3
  "description": "Remove potentially sensitive information from objects without changing the shape.",
5
- "scripts": {
6
- "check": "mongodb-js-precommit",
7
- "test": "mocha"
4
+ "author": {
5
+ "name": "MongoDB Inc",
6
+ "email": "compass@mongodb.com"
8
7
  },
9
- "dependencies": {
10
- "lodash": "^4.17.15"
8
+ "publishConfig": {
9
+ "access": "public"
11
10
  },
12
- "devDependencies": {
13
- "eslint-config-mongodb-js": "^5.0.3",
14
- "mocha": "~7.0.0",
15
- "mongodb-js-precommit": "^2.0.0"
11
+ "bugs": {
12
+ "url": "https://jira.mongodb.org/projects/COMPASS/issues",
13
+ "email": "compass@mongodb.com"
16
14
  },
17
- "keywords": [
18
- "mongodb",
19
- "mongodb.js"
20
- ],
15
+ "homepage": "https://github.com/mongodb-js/devtools-shared",
16
+ "version": "1.1.1",
21
17
  "repository": {
22
18
  "type": "git",
23
- "url": "http://github.com/mongodb-js/mongodb-redact.git"
19
+ "url": "https://github.com/mongodb-js/devtools-shared.git"
24
20
  },
25
- "author": "Lucas Hrabovsky <hrabovsky.lucas@gmail.com> (http://imlucas.com)",
21
+ "files": [
22
+ "dist"
23
+ ],
26
24
  "license": "Apache-2.0",
27
- "homepage": "http://github.com/mongodb-js/mongodb-redact"
25
+ "main": "dist/index.js",
26
+ "exports": {
27
+ "require": "./dist/index.js",
28
+ "import": "./dist/.esm-wrapper.mjs"
29
+ },
30
+ "types": "./dist/index.d.ts",
31
+ "scripts": {
32
+ "bootstrap": "npm run compile",
33
+ "prepublishOnly": "npm run compile",
34
+ "compile": "tsc -p tsconfig.json && gen-esm-wrapper . ./dist/.esm-wrapper.mjs",
35
+ "typecheck": "tsc --noEmit",
36
+ "eslint": "eslint",
37
+ "prettier": "prettier",
38
+ "lint": "npm run eslint . && npm run prettier -- --check .",
39
+ "depcheck": "depcheck",
40
+ "check": "npm run typecheck && npm run lint && npm run depcheck",
41
+ "check-ci": "npm run check",
42
+ "test": "mocha",
43
+ "test-cov": "nyc -x \"**/*.spec.*\" --reporter=lcov --reporter=text --reporter=html npm run test",
44
+ "test-watch": "npm run test -- --watch",
45
+ "test-ci": "npm run test-cov",
46
+ "reformat": "npm run prettier -- --write ."
47
+ },
48
+ "dependencies": {
49
+ "lodash": "^4.17.21"
50
+ },
51
+ "devDependencies": {
52
+ "@mongodb-js/eslint-config-devtools": "0.9.10",
53
+ "@mongodb-js/mocha-config-devtools": "^1.0.3",
54
+ "@mongodb-js/prettier-config-devtools": "^1.0.1",
55
+ "@mongodb-js/tsconfig-devtools": "^1.0.2",
56
+ "@types/chai": "^4.2.21",
57
+ "@types/mocha": "^9.1.1",
58
+ "@types/sinon-chai": "^3.2.5",
59
+ "chai": "^4.3.6",
60
+ "depcheck": "^1.4.1",
61
+ "eslint": "^7.25.0",
62
+ "gen-esm-wrapper": "^1.1.0",
63
+ "mocha": "^8.4.0",
64
+ "nyc": "^15.1.0",
65
+ "prettier": "^2.3.2",
66
+ "sinon": "^9.2.3",
67
+ "typescript": "^5.0.4"
68
+ },
69
+ "gitHead": "c88269832d44edcec0e637db242456c2f7975598"
28
70
  }
@@ -1,74 +0,0 @@
1
- # For most projects, this workflow file will not need changing; you simply need
2
- # to commit it to your repository.
3
- #
4
- # You may wish to alter this file to override the set of languages analyzed,
5
- # or to provide custom queries or build logic.
6
- #
7
- # ******** NOTE ********
8
- # We have attempted to detect the languages in your repository. Please check
9
- # the `language` matrix defined below to confirm you have the correct set of
10
- # supported CodeQL languages.
11
- #
12
- name: "CodeQL"
13
-
14
- on:
15
- push:
16
- branches: ["master"]
17
- pull_request:
18
- # The branches below must be a subset of the branches above
19
- branches: ["master"]
20
- schedule:
21
- - cron: "30 14 * * 4"
22
-
23
- jobs:
24
- analyze:
25
- name: Analyze
26
- runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
27
- timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
28
- permissions:
29
- actions: read
30
- contents: read
31
- security-events: write
32
-
33
- strategy:
34
- fail-fast: false
35
- matrix:
36
- language: ["javascript"]
37
- # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
38
- # Use only 'java' to analyze code written in Java, Kotlin or both
39
- # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
40
- # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
41
-
42
- steps:
43
- - name: Checkout repository
44
- uses: actions/checkout@v3
45
-
46
- # Initializes the CodeQL tools for scanning.
47
- - name: Initialize CodeQL
48
- uses: github/codeql-action/init@v2
49
- with:
50
- languages: ${{ matrix.language }}
51
- # If you wish to specify custom queries, you can do so here or in a config file.
52
- # By default, queries listed here will override any specified in a config file.
53
- # Prefix the list here with "+" to use these queries and those in the config file.
54
-
55
- # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
56
- # queries: security-extended,security-and-quality
57
- config: |
58
- paths-ignore:
59
- - '**/*.test.js'
60
- - '**/*.spec.js'
61
- - '**/*.test.ts'
62
- - '**/*.spec.ts'
63
- - '**/*.test.tsx'
64
- - '**/*.spec.tsx'
65
-
66
- # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
67
- # If this step fails, then you should remove it and run the build manually (see below)
68
- - name: Autobuild
69
- uses: github/codeql-action/autobuild@v2
70
-
71
- - name: Perform CodeQL Analysis
72
- uses: github/codeql-action/analyze@v2
73
- with:
74
- category: "/language:${{matrix.language}}"
package/README.md DELETED
@@ -1,47 +0,0 @@
1
- # mongodb-redact [![][npm_img]][npm_url] [![][travis_img]][travis_url]
2
-
3
- Remove potentially sensitive information from objects without changing the shape.
4
-
5
- Inspired by [fruitsalad][fruitsalad] and [mongo-redact][mongo-redact].
6
-
7
- ## Installation
8
-
9
- ```bash
10
- npm install --save mongodb-redact
11
- ```
12
-
13
- ## API
14
-
15
- ```javascript
16
- var redact = require('mongodb-redact');
17
-
18
- // `variable` can be of any type, including object and array.
19
- var result = redact(variable);
20
- ```
21
-
22
- ## Redaction
23
-
24
- The following types of strings are currently redacted:
25
-
26
- - Certificates and private keys
27
- - Electron application resource directories (Windows, OS X, Linux)
28
- - Generic user directories (Windows, OS X, Linux)
29
- - Email addresses
30
- - IP addresses
31
- - URLs
32
- - MongoDB connection strings
33
-
34
- Does **not redact** any non-string types (e.g. numbers, dates, etc).
35
-
36
- For examples, see `./test/index.test.js`.
37
-
38
-
39
- ## License
40
- Apache 2.0
41
-
42
- [travis_img]: https://secure.travis-ci.org/mongodb-js/redact.svg?branch=master
43
- [travis_url]: https://travis-ci.org/mongodb-js/redact
44
- [npm_img]: https://img.shields.io/npm/v/mongodb-redact.svg
45
- [npm_url]: https://www.npmjs.org/package/mongodb-redact
46
- [fruitsalad]: https://github.com/rueckstiess/fruitsalad
47
- [mongo-redact]: https://github.com/jonrangel/mongo-redact
package/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare function redact<T>(input: T): T;
2
- export = redact;
package/index.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./lib');
package/lib/index.js DELETED
@@ -1,26 +0,0 @@
1
- var _ = require('lodash');
2
- var regexes = require('./regexes');
3
-
4
- function redact(message) {
5
- if (_.isPlainObject(message)) {
6
- // recursively walk through all values of an object
7
- return _.mapValues(message, redact);
8
- }
9
- if (_.isArray(message)) {
10
- // walk through array and redact each value
11
- return _.map(message, redact);
12
- }
13
- if (!_.isString(message)) {
14
- // all non-string types can be safely returned
15
- return message;
16
- }
17
- // apply all available regexes to the string
18
- _.each(regexes, function(values) {
19
- var regex = values[0];
20
- var replacement = values[1];
21
- message = message.replace(regex, replacement);
22
- });
23
- return message;
24
- }
25
-
26
- module.exports = redact;
package/lib/regexes.js DELETED
@@ -1,32 +0,0 @@
1
- var regexes = [
2
- // Certificates and keys
3
- [/-----BEGIN CERTIFICATE-----.*-----END CERTIFICATE-----/mg, '<certificate>'],
4
- [/-----BEGIN RSA PRIVATE KEY-----.*-----END RSA PRIVATE KEY-----/mg, '<private key>'],
5
-
6
- // Electron app resources specific directories
7
- [/(file:\/\/)?\S+\/Contents\/Resources\/app\//mg, '$1/<path>/'],
8
- [/(file:\/\/)?([a-zA-Z]:)?\\\S+\\resources\\app\\/mg, '$1\\<path>\\'],
9
- [/(file:\/\/)?([a-zA-Z]:)?\/\S+\/resources\/app\//mg, '$1/<path>/'],
10
-
11
- // Generic user directories
12
- [/\/(Users?)\/[^/]*\//mg, '/$1/<user>/'],
13
- [/\/(usr|home|user|users|u01|var\/users|export\/home)\/[^/]*\//mg, '/$1/<user>/'],
14
- [/\\(Users|Documents and Settings|Profiles)\\[^/\\]*\\/mg, '\\$1\\<user>\\'],
15
-
16
- // Email addresses
17
- [/(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/mgi, '<email>'],
18
-
19
- // IP addresses
20
- [/((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])/mg, '<ip address>'],
21
-
22
- // URLs
23
- [/(http(s)?:\/\/)(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}(\.[a-z]{2,6})?\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)/mgi, '<url>'],
24
-
25
- // MongoDB connection strings
26
- [/(mongodb:\/\/)(www\.)?[-a-zA-Z0-9@:%._\+~#=,]{2,256}(\.[a-z]{2,6})?\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)/mgi, '<mongodb uri>'],
27
-
28
- // Compass Schema URL fragments
29
- [/#schema\/\w+\.\w+/, '#schema/<namespace>']
30
- ];
31
-
32
- module.exports = regexes;