@contrast/assess 1.18.0 → 1.20.0

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.
Files changed (160) hide show
  1. package/LICENSE +1 -1
  2. package/lib/constants.js +26 -0
  3. package/lib/crypto-analysis/common.js +20 -0
  4. package/lib/crypto-analysis/index.js +44 -0
  5. package/lib/crypto-analysis/install/crypto.js +156 -0
  6. package/lib/crypto-analysis/install/math.js +104 -0
  7. package/lib/dataflow/index.js +1 -1
  8. package/lib/dataflow/propagation/common.js +1 -1
  9. package/lib/dataflow/propagation/index.js +1 -1
  10. package/lib/dataflow/propagation/install/JSON/index.js +1 -1
  11. package/lib/dataflow/propagation/install/JSON/parse-fn.js +1 -1
  12. package/lib/dataflow/propagation/install/JSON/parse.js +15 -14
  13. package/lib/dataflow/propagation/install/JSON/stringify.js +2 -2
  14. package/lib/dataflow/propagation/install/array-prototype-join.js +1 -1
  15. package/lib/dataflow/propagation/install/buffer.js +1 -1
  16. package/lib/dataflow/propagation/install/contrast-methods/add.js +1 -1
  17. package/lib/dataflow/propagation/install/contrast-methods/index.js +1 -1
  18. package/lib/dataflow/propagation/install/contrast-methods/number.js +4 -3
  19. package/lib/dataflow/propagation/install/contrast-methods/string.js +1 -1
  20. package/lib/dataflow/propagation/install/contrast-methods/tag.js +1 -1
  21. package/lib/dataflow/propagation/install/decode-uri-component.js +1 -1
  22. package/lib/dataflow/propagation/install/ejs/escape-xml.js +3 -3
  23. package/lib/dataflow/propagation/install/ejs/index.js +2 -1
  24. package/lib/dataflow/propagation/install/ejs/template.js +79 -0
  25. package/lib/dataflow/propagation/install/encode-uri.js +1 -1
  26. package/lib/dataflow/propagation/install/escape-html.js +1 -1
  27. package/lib/dataflow/propagation/install/escape.js +1 -1
  28. package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.js +1 -1
  29. package/lib/dataflow/propagation/install/isnumeric-0.js +3 -3
  30. package/lib/dataflow/propagation/install/joi/any.js +1 -1
  31. package/lib/dataflow/propagation/install/joi/boolean.js +1 -1
  32. package/lib/dataflow/propagation/install/joi/expression.js +1 -1
  33. package/lib/dataflow/propagation/install/joi/index.js +1 -1
  34. package/lib/dataflow/propagation/install/joi/keys.js +1 -1
  35. package/lib/dataflow/propagation/install/joi/number.js +1 -1
  36. package/lib/dataflow/propagation/install/joi/object.js +1 -1
  37. package/lib/dataflow/propagation/install/joi/string-schema.js +1 -1
  38. package/lib/dataflow/propagation/install/joi/utils.js +1 -1
  39. package/lib/dataflow/propagation/install/joi/values.js +1 -1
  40. package/lib/dataflow/propagation/install/mongoose/common.js +1 -1
  41. package/lib/dataflow/propagation/install/mongoose/index.js +1 -1
  42. package/lib/dataflow/propagation/install/mongoose/schema-map.js +1 -1
  43. package/lib/dataflow/propagation/install/mongoose/schema-mixed.js +1 -1
  44. package/lib/dataflow/propagation/install/mongoose/schema-string.js +1 -1
  45. package/lib/dataflow/propagation/install/mustache-escape.js +1 -1
  46. package/lib/dataflow/propagation/install/mysql-connection-escape.js +1 -1
  47. package/lib/dataflow/propagation/install/parse-int.js +3 -3
  48. package/lib/dataflow/propagation/install/path/basename.js +1 -1
  49. package/lib/dataflow/propagation/install/path/common.js +1 -1
  50. package/lib/dataflow/propagation/install/path/dirname.js +1 -1
  51. package/lib/dataflow/propagation/install/path/extname.js +1 -1
  52. package/lib/dataflow/propagation/install/path/format.js +1 -1
  53. package/lib/dataflow/propagation/install/path/index.js +1 -1
  54. package/lib/dataflow/propagation/install/path/join-and-resolve.js +1 -1
  55. package/lib/dataflow/propagation/install/path/normalize.js +1 -1
  56. package/lib/dataflow/propagation/install/path/parse.js +1 -1
  57. package/lib/dataflow/propagation/install/path/relative.js +1 -1
  58. package/lib/dataflow/propagation/install/path/toNamespacedPath.js +1 -1
  59. package/lib/dataflow/propagation/install/pug/index.js +3 -3
  60. package/lib/dataflow/propagation/install/pug-runtime-escape.js +1 -1
  61. package/lib/dataflow/propagation/install/querystring/escape.js +1 -1
  62. package/lib/dataflow/propagation/install/querystring/index.js +1 -1
  63. package/lib/dataflow/propagation/install/querystring/parse.js +1 -1
  64. package/lib/dataflow/propagation/install/querystring/stringify.js +1 -1
  65. package/lib/dataflow/propagation/install/reg-exp-prototype-exec.js +1 -1
  66. package/lib/dataflow/propagation/install/send.js +1 -1
  67. package/lib/dataflow/propagation/install/sequelize/index.js +1 -1
  68. package/lib/dataflow/propagation/install/sequelize/query-generator.js +1 -1
  69. package/lib/dataflow/propagation/install/sequelize/sql-string.js +1 -1
  70. package/lib/dataflow/propagation/install/sql-template-strings.js +1 -1
  71. package/lib/dataflow/propagation/install/string/concat.js +1 -1
  72. package/lib/dataflow/propagation/install/string/format-methods.js +1 -1
  73. package/lib/dataflow/propagation/install/string/html-methods.js +1 -1
  74. package/lib/dataflow/propagation/install/string/index.js +1 -1
  75. package/lib/dataflow/propagation/install/string/match-all.js +1 -1
  76. package/lib/dataflow/propagation/install/string/match.js +1 -1
  77. package/lib/dataflow/propagation/install/string/replace.js +1 -1
  78. package/lib/dataflow/propagation/install/string/slice.js +1 -1
  79. package/lib/dataflow/propagation/install/string/split.js +1 -1
  80. package/lib/dataflow/propagation/install/string/substring.js +1 -1
  81. package/lib/dataflow/propagation/install/string/trim.js +1 -1
  82. package/lib/dataflow/propagation/install/unescape.js +1 -1
  83. package/lib/dataflow/propagation/install/url/domain-parsers.js +1 -1
  84. package/lib/dataflow/propagation/install/url/index.js +1 -1
  85. package/lib/dataflow/propagation/install/url/parse.js +1 -1
  86. package/lib/dataflow/propagation/install/url/searchParams.js +1 -1
  87. package/lib/dataflow/propagation/install/url/url.js +1 -1
  88. package/lib/dataflow/propagation/install/util-format.js +10 -4
  89. package/lib/dataflow/propagation/install/validator/hooks.js +1 -1
  90. package/lib/dataflow/propagation/install/validator/index.js +1 -1
  91. package/lib/dataflow/propagation/install/validator/methods.js +1 -1
  92. package/lib/dataflow/sinks/common.js +1 -1
  93. package/lib/dataflow/sinks/index.js +1 -1
  94. package/lib/dataflow/sinks/install/child-process.js +21 -15
  95. package/lib/dataflow/sinks/install/eval.js +17 -15
  96. package/lib/dataflow/sinks/install/express/index.js +1 -1
  97. package/lib/dataflow/sinks/install/express/unvalidated-redirect.js +15 -9
  98. package/lib/dataflow/sinks/install/fastify/index.js +1 -1
  99. package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.js +13 -6
  100. package/lib/dataflow/sinks/install/fs.js +8 -8
  101. package/lib/dataflow/sinks/install/function.js +9 -13
  102. package/lib/dataflow/sinks/install/http/index.js +1 -1
  103. package/lib/dataflow/sinks/install/http/request.js +17 -9
  104. package/lib/dataflow/sinks/install/http/server-response.js +12 -3
  105. package/lib/dataflow/sinks/install/koa/index.js +1 -1
  106. package/lib/dataflow/sinks/install/koa/unvalidated-redirect.js +16 -9
  107. package/lib/dataflow/sinks/install/libxmljs.js +16 -11
  108. package/lib/dataflow/sinks/install/marsdb.js +17 -12
  109. package/lib/dataflow/sinks/install/mongodb.js +32 -22
  110. package/lib/dataflow/sinks/install/mssql.js +21 -10
  111. package/lib/dataflow/sinks/install/mysql.js +16 -9
  112. package/lib/dataflow/sinks/install/node-serialize.js +16 -18
  113. package/lib/dataflow/sinks/install/postgres.js +18 -5
  114. package/lib/dataflow/sinks/install/sequelize.js +23 -17
  115. package/lib/dataflow/sinks/install/sqlite3.js +21 -8
  116. package/lib/dataflow/sinks/install/vm.js +20 -18
  117. package/lib/dataflow/sources/common.js +1 -1
  118. package/lib/dataflow/sources/handler.js +11 -10
  119. package/lib/dataflow/sources/index.js +2 -2
  120. package/lib/dataflow/sources/install/body-parser1.js +11 -13
  121. package/lib/dataflow/sources/install/{busboy1.js → busboy.js} +15 -15
  122. package/lib/dataflow/sources/install/cookie-parser1.js +7 -6
  123. package/lib/dataflow/sources/install/express/index.js +1 -1
  124. package/lib/dataflow/sources/install/express/params.js +9 -10
  125. package/lib/dataflow/sources/install/express/parsedUrl.js +1 -1
  126. package/lib/dataflow/sources/install/fastify/fastify.js +6 -7
  127. package/lib/dataflow/sources/install/fastify/index.js +1 -1
  128. package/lib/dataflow/sources/install/formidable1.js +8 -6
  129. package/lib/dataflow/sources/install/http.js +17 -45
  130. package/lib/dataflow/sources/install/koa/index.js +2 -1
  131. package/lib/dataflow/sources/install/koa/koa-bodyparsers.js +10 -9
  132. package/lib/dataflow/sources/install/koa/koa-multer.js +102 -0
  133. package/lib/dataflow/sources/install/koa/koa-routers.js +6 -8
  134. package/lib/dataflow/sources/install/koa/koa2.js +42 -38
  135. package/lib/dataflow/sources/install/multer1.js +26 -52
  136. package/lib/dataflow/sources/install/qs6.js +7 -6
  137. package/lib/dataflow/sources/install/querystring.js +5 -8
  138. package/lib/dataflow/tag-utils.js +1 -1
  139. package/lib/dataflow/tracker.js +1 -1
  140. package/lib/dataflow/utils/is-safe-content-type.js +1 -1
  141. package/lib/dataflow/utils/is-vulnerable.js +1 -1
  142. package/lib/event-factory.js +75 -26
  143. package/lib/get-policy.js +68 -0
  144. package/lib/get-source-context.js +62 -0
  145. package/lib/index.d.ts +64 -0
  146. package/lib/index.js +21 -20
  147. package/lib/make-source-context.js +78 -0
  148. package/lib/response-scanning/handlers/index.js +56 -29
  149. package/lib/response-scanning/handlers/utils.js +1 -1
  150. package/lib/response-scanning/index.js +1 -1
  151. package/lib/response-scanning/install/http.js +14 -8
  152. package/lib/rule-scopes.js +48 -0
  153. package/lib/session-configuration/common.js +1 -1
  154. package/lib/session-configuration/handlers.js +66 -47
  155. package/lib/session-configuration/index.js +3 -1
  156. package/lib/session-configuration/install/express-session.js +23 -26
  157. package/lib/session-configuration/install/fastify-cookie.js +110 -0
  158. package/lib/session-configuration/install/hapi.js +8 -11
  159. package/lib/session-configuration/install/koa.js +101 -0
  160. package/package.json +2 -2
@@ -0,0 +1,110 @@
1
+ /*
2
+ * Copyright: 2024 Contrast Security, Inc
3
+ * Contact: support@contrastsecurity.com
4
+ * License: Commercial
5
+
6
+ * NOTICE: This Software and the patented inventions embodied within may only be
7
+ * used as part of Contrast Security’s commercial offerings. Even though it is
8
+ * made available through public repositories, use of this Software is subject to
9
+ * the applicable End User Licensing Agreement found at
10
+ * https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
+ * between Contrast Security and the End User. The Software may not be reverse
12
+ * engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
+ * way not consistent with the End User License Agreement.
14
+ */
15
+ 'use strict';
16
+
17
+ const { inspect } = require('util');
18
+ const { toLowerCase } = require('@contrast/common');
19
+ const { patchType } = require('../common');
20
+
21
+ /**
22
+ * @param {{
23
+ * assess: import('@contrast/assess').Assess,
24
+ * scopes: import('@contrast/scopes').Scopes,
25
+ * }} core
26
+ */
27
+ module.exports = function (core) {
28
+ const {
29
+ assess: {
30
+ getSourceContext,
31
+ eventFactory: { createSessionEvent },
32
+ sessionConfiguration: {
33
+ handleHttpOnly,
34
+ handleSecure,
35
+ },
36
+ },
37
+ depHooks,
38
+ patcher,
39
+ } = core;
40
+
41
+ return core.assess.sessionConfiguration.fastifyCookie = {
42
+ install () {
43
+ depHooks.resolve({ name: '@fastify/cookie' }, (_export) => {
44
+ const patched = patcher.patch(_export, {
45
+ name: 'express.hookedSessionConstructor',
46
+ patchType,
47
+ pre(data) {
48
+ const [server, options] = data.args;
49
+
50
+ // neither default to safe (truthy) values
51
+ const httpOnly = options?.parseOptions?.httpOnly;
52
+ const secure = options?.parseOptions?.secure;
53
+ if (httpOnly && secure) return;
54
+
55
+ const displayArg = inspect({ parseOptions: { httpOnly, secure } });
56
+ const sessionEvent = createSessionEvent({
57
+ args: [{
58
+ tracked: false,
59
+ value: displayArg
60
+ }],
61
+ context: `fastifyCookie(${displayArg})`,
62
+ history: [],
63
+ name: 'fastifyCookie',
64
+ moduleName: '@fastify/cookie',
65
+ methodName: '',
66
+ object: {
67
+ tracked: false,
68
+ value: '@fastify/cookie',
69
+ },
70
+ result: {
71
+ tracked: false,
72
+ },
73
+ source: 'P0',
74
+ stack: [],
75
+ tags: {},
76
+ framework: '@fastify/cookie',
77
+ });
78
+
79
+ server.addHook('onRequest', async (request, reply) => {
80
+ patcher.patch(reply, 'header', {
81
+ patchType,
82
+ name: 'fastify.Reply.header',
83
+ pre(data) {
84
+ const [key, value] = data.args;
85
+ if (toLowerCase(key) !== 'set-cookie') return;
86
+
87
+ const sourceContext = getSourceContext();
88
+ if (!sourceContext) return;
89
+
90
+ if (!httpOnly) {
91
+ handleHttpOnly(sourceContext, value, sessionEvent);
92
+ }
93
+
94
+ if (!secure) {
95
+ handleSecure(sourceContext, value, sessionEvent);
96
+ }
97
+ }
98
+ });
99
+ });
100
+ }
101
+ });
102
+
103
+ _export.default = patched;
104
+ _export.fastifyCookie = patched;
105
+
106
+ return patched;
107
+ });
108
+ }
109
+ };
110
+ };
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2023 Contrast Security, Inc
2
+ * Copyright: 2024 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -36,7 +36,6 @@ module.exports = function (core) {
36
36
  const inspect = patcher.unwrap(util.inspect);
37
37
 
38
38
  hapiSession.install = function () {
39
-
40
39
  return depHooks.resolve({ name: '@hapi/hapi', version: '>=18 <21' }, (hapi) => {
41
40
  ['server', 'Server'].forEach((server) => {
42
41
  patcher.patch(hapi, server, {
@@ -47,14 +46,12 @@ module.exports = function (core) {
47
46
  name: 'state',
48
47
  patchType,
49
48
  post(data) {
50
-
51
49
  const options = data.args[1];
52
-
53
50
  const httpOnly = Object.prototype.hasOwnProperty.call(options, 'isHttpOnly') ? options.isHttpOnly : true;
54
51
  const isSecure = Object.prototype.hasOwnProperty.call(options, 'isSecure') ? options.isSecure : true;
55
-
52
+
56
53
  if (httpOnly && isSecure) return;
57
-
54
+
58
55
  const sessionEvent = createSessionEvent({
59
56
  args: [{
60
57
  tracked: false,
@@ -80,18 +77,18 @@ module.exports = function (core) {
80
77
  framework: 'hapi',
81
78
  options
82
79
  });
83
-
80
+
84
81
  data.obj.ext('onPostResponse', ({ response: { headers } }) => {
85
82
  const value = headers?.['set-cookie']?.[0];
86
83
  if (!value) return;
87
-
84
+
88
85
  const sourceContext = sources.getStore()?.assess;
89
86
  if (!sourceContext) return;
90
-
87
+
91
88
  if (!httpOnly) {
92
89
  handleHttpOnly(sourceContext, `set-cookie: ${value}`, sessionEvent);
93
90
  }
94
-
91
+
95
92
  if (!isSecure) {
96
93
  handleSecure(sourceContext, `set-cookie: ${value}`, sessionEvent);
97
94
  }
@@ -99,7 +96,7 @@ module.exports = function (core) {
99
96
  }
100
97
  });
101
98
  }
102
- });
99
+ });
103
100
  });
104
101
  });
105
102
  };
@@ -0,0 +1,101 @@
1
+ /*
2
+ * Copyright: 2024 Contrast Security, Inc
3
+ * Contact: support@contrastsecurity.com
4
+ * License: Commercial
5
+
6
+ * NOTICE: This Software and the patented inventions embodied within may only be
7
+ * used as part of Contrast Security’s commercial offerings. Even though it is
8
+ * made available through public repositories, use of this Software is subject to
9
+ * the applicable End User Licensing Agreement found at
10
+ * https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
+ * between Contrast Security and the End User. The Software may not be reverse
12
+ * engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
+ * way not consistent with the End User License Agreement.
14
+ */
15
+ 'use strict';
16
+
17
+ const { inspect } = require('util');
18
+ const { patchType } = require('../common');
19
+
20
+ /**
21
+ * @param {{
22
+ * assess: import('@contrast/assess').Assess,
23
+ * scopes: import('@contrast/scopes').Scopes,
24
+ * }} core
25
+ */
26
+ module.exports = function (core) {
27
+ const {
28
+ assess: {
29
+ getSourceContext,
30
+ eventFactory: { createSessionEvent },
31
+ sessionConfiguration: {
32
+ handleHttpOnly,
33
+ handleSecure,
34
+ },
35
+ },
36
+ depHooks,
37
+ patcher,
38
+ } = core;
39
+
40
+ return core.assess.sessionConfiguration.koa = {
41
+ install () {
42
+ depHooks.resolve({ name: 'koa', version: '>=2.3.0' }, (Koa) => {
43
+ patcher.patch(Koa.prototype, 'use', {
44
+ name: 'Koa.Application',
45
+ patchType,
46
+ pre(data) {
47
+ const origCtx = data.args[0];
48
+ data.args[0] = function(...args) {
49
+ patcher.patch(args[0].cookies, 'set', {
50
+ name: 'ctx.cookies',
51
+ patchType,
52
+ pre({ args }) {
53
+ const sourceContext = getSourceContext();
54
+ if (!sourceContext) return;
55
+
56
+ const [name,, options] = args;
57
+
58
+ const httpOnly = options?.httpOnly;
59
+ const secure = options?.secure;
60
+ if (httpOnly && secure) return;
61
+
62
+ const displayArg = inspect(options);
63
+ const sessionEvent = createSessionEvent({
64
+ args: [{
65
+ tracked: false,
66
+ value: displayArg
67
+ }],
68
+ context: `ctx.cookies.set(${displayArg})`,
69
+ history: [],
70
+ name: 'koaCookie',
71
+ moduleName: 'koa',
72
+ methodName: '',
73
+ object: {
74
+ tracked: false,
75
+ value: 'koa',
76
+ },
77
+ result: {
78
+ tracked: false,
79
+ },
80
+ source: 'P',
81
+ stack: [],
82
+ tags: {},
83
+ framework: 'koa',
84
+ });
85
+ if (!httpOnly) {
86
+ handleHttpOnly(sourceContext, name, sessionEvent);
87
+ }
88
+
89
+ if (!secure) {
90
+ handleSecure(sourceContext, name, sessionEvent);
91
+ }
92
+ }
93
+ });
94
+ return origCtx.apply(this, args);
95
+ };
96
+ }
97
+ });
98
+ });
99
+ }
100
+ };
101
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/assess",
3
- "version": "1.18.0",
3
+ "version": "1.20.0",
4
4
  "description": "Contrast service providing framework-agnostic Assess support",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -17,7 +17,7 @@
17
17
  "test": "../scripts/test.sh"
18
18
  },
19
19
  "dependencies": {
20
- "@contrast/common": "1.15.1",
20
+ "@contrast/common": "1.16.0",
21
21
  "@contrast/distringuish": "^4.4.0",
22
22
  "@contrast/scopes": "1.4.0"
23
23
  }