ac-sanitizer 4.0.0 → 4.0.2

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,30 @@
1
+ # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
+
4
+ name: Node.js CI
5
+
6
+ on:
7
+ push:
8
+ branches: [ master ]
9
+ pull_request:
10
+ branches: [ master ]
11
+
12
+ jobs:
13
+ build:
14
+
15
+ runs-on: ubuntu-latest
16
+
17
+ strategy:
18
+ matrix:
19
+ node-version: [16.x, 18.x]
20
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21
+
22
+ steps:
23
+ - uses: actions/checkout@v3
24
+ - name: Use Node.js ${{ matrix.node-version }}
25
+ uses: actions/setup-node@v3
26
+ with:
27
+ node-version: ${{ matrix.node-version }}
28
+
29
+ - run: yarn install
30
+ - run: yarn run test
package/CHANGELOG.md CHANGED
@@ -1,3 +1,43 @@
1
+ <a name="4.0.2"></a>
2
+
3
+ ## [4.0.2](https://github.com/mmpro/ac-sanitizer/compare/v4.0.1..v4.0.2) (2023-06-18 11:35:24)
4
+
5
+
6
+ ### Bug Fix
7
+
8
+ * **App:** If base64 is an object, parse the converted string | MP | [cf9a49d9df121c7829932ae37192fd22f3d98438](https://github.com/mmpro/ac-sanitizer/commit/cf9a49d9df121c7829932ae37192fd22f3d98438)
9
+ Base64 might be a string or a stringified object. Try parsing the string to determine if it is an object
10
+ Related issues: [undefined/undefined#master](undefined/browse/master)
11
+ ### Chores
12
+
13
+ * **App:** Updated packages | MP | [49da6b224e9382aa7cc6a298b2a0af06648931b8](https://github.com/mmpro/ac-sanitizer/commit/49da6b224e9382aa7cc6a298b2a0af06648931b8)
14
+ Updated packages
15
+ Related issues: [undefined/undefined#master](undefined/browse/master)
16
+ ### Chores
17
+
18
+ * **App:** Add Github workflow | MP | [72668a139dda85330516077ef471af4aa4b68c3b](https://github.com/mmpro/ac-sanitizer/commit/72668a139dda85330516077ef471af4aa4b68c3b)
19
+ Add Github workflow
20
+ Related issues: [undefined/undefined#master](undefined/browse/master)
21
+ <a name="4.0.1"></a>
22
+
23
+ ## [4.0.1](https://github.com/mmpro/ac-sanitizer/compare/v4.0.0..v4.0.1) (2023-04-18 18:38:15)
24
+
25
+
26
+ ### Bug Fix
27
+
28
+ * **App:** Sanitize array of objects | MP | [c00ea6869a250672b1af1f1c1520223686cc59b9](https://github.com/mmpro/ac-sanitizer/commit/c00ea6869a250672b1af1f1c1520223686cc59b9)
29
+ Make sure to sanitize (remove non-defined properties from) array of objects
30
+ Related issues: [undefined/undefined#master](undefined/browse/master)
31
+ ### Tests
32
+
33
+ * **App:** Added test for array of objects | MP | [7c3b698a09ef48398b95fdacc22542b14ef5cd30](https://github.com/mmpro/ac-sanitizer/commit/7c3b698a09ef48398b95fdacc22542b14ef5cd30)
34
+ Added test for array of objects
35
+ Related issues: [undefined/undefined#master](undefined/browse/master)
36
+ ### Chores
37
+
38
+ * **App:** Updated packages | MP | [40d542dced814eebb74d384d999532f3e1c718ed](https://github.com/mmpro/ac-sanitizer/commit/40d542dced814eebb74d384d999532f3e1c718ed)
39
+ Updated packages
40
+ Related issues: [undefined/undefined#master](undefined/browse/master)
1
41
  <a name="4.0.0"></a>
2
42
 
3
43
  ## [4.0.0](https://github.com/mmpro/ac-sanitizer/compare/v3.10.7..v4.0.0) (2023-03-30 16:00:08)
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # AC Sanitizer
2
2
  Sanitizes payloads with given field definitions
3
3
 
4
+ [![Node.js CI](https://github.com/AdmiralCloud/ac-sanitizer/actions/workflows/node.js.yml/badge.svg)](https://github.com/AdmiralCloud/ac-sanitizer/actions/workflows/node.js.yml)
5
+
4
6
  ### Version 4 - Breaking changes
5
7
  Version 4 requires Node 16.
6
8
 
package/index.js CHANGED
@@ -265,7 +265,7 @@ const sanitizer = function() {
265
265
  else if (field.minSize && _.size(value) < field.minSize) error = { message: fieldName + '_minSizeBoundary', additionalInfo: { minSize: field.minSize } }
266
266
  else if (field.valueType) {
267
267
  // very value of the array must be of this type
268
- _.every(value, v => {
268
+ _.every(value, (v, index, value) => {
269
269
  const fieldsToCheck = {
270
270
  params: {},
271
271
  fields: [{ field: fieldName, type: _.get(field, 'valueType'), properties: _.get(field, 'properties'), wildcardAllowed: _.get(field, 'wildcardAllowed') }]
@@ -276,6 +276,8 @@ const sanitizer = function() {
276
276
  error = { message: fieldName + '_atLeastOneValueFailed', additionalInfo: { error: _.get(check, 'error'), value: v, type: _.get(field, 'valueType') } }
277
277
  return false
278
278
  }
279
+ // set the sanitized value
280
+ value[index] = _.get(check, `params.${fieldName}`)
279
281
  return true
280
282
  })
281
283
  }
@@ -328,6 +330,13 @@ const sanitizer = function() {
328
330
  if (!validator.isBase64(_.padEnd(value, (l+pad), '='))) error = { message: fieldName + '_notABase64String' }
329
331
  else if (field.convert) {
330
332
  _.set(paramsToCheck, fieldName, Buffer.from(value, 'base64').toString())
333
+ // the value might be a stringified object - try converting it
334
+ try {
335
+ _.set(paramsToCheck, fieldName, JSON.parse(_.get(paramsToCheck, fieldName)))
336
+ }
337
+ catch(e) {
338
+ // ignore
339
+ }
331
340
  }
332
341
  }
333
342
  }
package/package.json CHANGED
@@ -4,21 +4,21 @@
4
4
  "author": "Mark Poepping (https://www.admiralcloud.com)",
5
5
  "license": "MIT",
6
6
  "repository": "admiralcloud/ac-sanitizer",
7
- "version": "4.0.0",
7
+ "version": "4.0.2",
8
8
  "homepage": "https://www.admiralcloud.com",
9
9
  "dependencies": {
10
10
  "ac-countrylist": "^1.0.7",
11
11
  "ac-file-extensions": "^2.0.5",
12
12
  "ac-ip": "^3.0.1",
13
13
  "chai": "^4.3.7",
14
- "date-and-time": "^2.4.3",
15
- "hashids": "^2.2.11",
14
+ "date-and-time": "^3.0.2",
15
+ "hashids": "^2.3.0",
16
16
  "lodash": "^4.17.21",
17
17
  "validator": "^13.9.0"
18
18
  },
19
19
  "devDependencies": {
20
- "ac-semantic-release": "^0.3.5",
21
- "eslint": "^8.37.0",
20
+ "ac-semantic-release": "^0.4.1",
21
+ "eslint": "^8.43.0",
22
22
  "mocha": "^10.2.0",
23
23
  "nyc": "^15.1.0"
24
24
  },
@@ -30,6 +30,13 @@ module.exports = {
30
30
  { name: 'Array of fileExtensions - contains invalid', type: 'array', valueType: 'fileExtension', value: ['jpg', 'textimage'], error: 'array_atLeastOneValueFailed' },
31
31
  { name: 'Array of objects - valid', type: 'array', value: [{ 'createdAt': 'asc' }], enum: [{ 'createdAt': 'asc' }], expected: [{ 'createdAt': 'asc' }] },
32
32
  { name: 'Array of objects - invalid', type: 'array', value: [{ 'createdAt': 'desc' }], enum: [{ 'createdAt': 'asc' }], error: 'array_notAnAllowedValue' },
33
+ { name: 'Array of objects - check that object payload is sanitized',
34
+ type: 'array',
35
+ valueType: 'object',
36
+ properties: [{ field: 'p1', type: 'string' }],
37
+ value: [{ p1: 'isAString', p2: 'shouldBeRemoved' }, { p1: 'isAString2', p2: 'shouldBeRemoved2' }],
38
+ expected: [{ p1: 'isAString' }, { p1: 'isAString2' }]
39
+ }
33
40
  ]
34
41
 
35
42
 
@@ -40,7 +47,7 @@ module.exports = {
40
47
  array: _.get(test, 'value')
41
48
  },
42
49
  fields: [
43
- { field: 'array', type: _.get(test, 'type'), required: _.get(test, 'required'), valueType: _.get(test, 'valueType'), minSize: _.get(test, 'minSize'), maxSize: _.get(test, 'maxSize') }
50
+ { field: 'array', type: _.get(test, 'type'), required: _.get(test, 'required'), valueType: _.get(test, 'valueType'), minSize: _.get(test, 'minSize'), maxSize: _.get(test, 'maxSize'), properties: _.get(test, "properties")}
44
51
  ]
45
52
  }
46
53
  if (test.enum) {
@@ -13,6 +13,8 @@ module.exports = {
13
13
  { name: 'Invalid base64 with convert', type: 'base64', convert: true, value: 123, error: 'base64_mustBeString' },
14
14
  { name: 'Base64 app.admiralcloud.com - requires padding', type: 'base64', value: 'aHR0cHM6Ly9hcHAuYWRtaXJhbGNsb3VkLmNvbQ', convert: true, expected: 'https://app.admiralcloud.com' },
15
15
  { name: 'Base64 app.admiralcloud.com - with padding', type: 'base64', value: 'aHR0cHM6Ly9hcHAuYWRtaXJhbGNsb3VkLmNvbQ==', convert: true, expected: 'https://app.admiralcloud.com' },
16
+ { name: 'Base64 encoded object', type: 'base64', value: 'eyJ1c2VySWQiOjEyMywiY3VzdG9tZXJJZCI6MTQ2LCJyZWFzb24iOiJCZWNhdXNlIEkgY2FuIn0=', convert: true, expected: { userId: 123, customerId: 146, reason: 'Because I can' } },
17
+ { name: 'Base64 encoded object', type: 'base64', value: 'eyJ1c2VySWQiOjEyMywiY3VzdG9tZXJJZCI6MTQ2LCJyZWFzbOiJCZWNhdXNlIEkgY2FuIn0=', convert: true, error: 'base64_notABase64String' },
16
18
  ]
17
19
 
18
20
  _.forEach(baseTests, (test) => {
@@ -34,7 +36,7 @@ module.exports = {
34
36
  }
35
37
  }
36
38
  else {
37
- expect(_.get(r, 'params.base64')).to.equal(_.get(test, 'expected'))
39
+ expect(_.get(r, 'params.base64')).to.eql(_.get(test, 'expected'))
38
40
  }
39
41
  return done()
40
42
  })
@@ -33,6 +33,26 @@ module.exports = {
33
33
  enum: "blue",
34
34
  },
35
35
  },
36
+ {
37
+ name: "Object with non-allowed properties - should be removed from payload by sanitizer",
38
+ type: "object",
39
+ properties: [
40
+ { field: "settings", type: "object", properties:[
41
+ { field: 'allowed', type: 'boolean' }
42
+ ] },
43
+ ],
44
+ value: {
45
+ settings: {
46
+ allowed: true,
47
+ notAllowed: true
48
+ }
49
+ },
50
+ expected: {
51
+ settings: {
52
+ allowed: true
53
+ }
54
+ }
55
+ },
36
56
  {
37
57
  name: "Object with non-allowed properties - do not ignore in strict mode",
38
58
  type: "object",