@contrast/assess 1.7.0 → 1.9.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 (68) hide show
  1. package/lib/dataflow/event-factory.js +17 -13
  2. package/lib/dataflow/propagation/index.js +5 -0
  3. package/lib/dataflow/propagation/install/JSON/index.js +34 -0
  4. package/lib/dataflow/propagation/install/JSON/parse-fn.js +248 -0
  5. package/lib/dataflow/propagation/install/JSON/parse.js +196 -0
  6. package/lib/dataflow/propagation/install/JSON/stringify.js +292 -0
  7. package/lib/dataflow/propagation/install/array-prototype-join.js +21 -14
  8. package/lib/dataflow/propagation/install/buffer.js +81 -0
  9. package/lib/dataflow/propagation/install/contrast-methods/add.js +2 -0
  10. package/lib/dataflow/propagation/install/contrast-methods/index.js +1 -0
  11. package/lib/dataflow/propagation/install/contrast-methods/number.js +58 -0
  12. package/lib/dataflow/propagation/install/contrast-methods/string.js +53 -6
  13. package/lib/dataflow/propagation/install/contrast-methods/tag.js +3 -1
  14. package/lib/dataflow/propagation/install/decode-uri-component.js +9 -2
  15. package/lib/dataflow/propagation/install/ejs/escape-xml.js +8 -2
  16. package/lib/dataflow/propagation/install/encode-uri-component.js +9 -2
  17. package/lib/dataflow/propagation/install/escape-html.js +13 -5
  18. package/lib/dataflow/propagation/install/escape.js +9 -2
  19. package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.js +11 -4
  20. package/lib/dataflow/propagation/install/isnumeric-0.js +59 -0
  21. package/lib/dataflow/propagation/install/mongoose/index.js +36 -0
  22. package/lib/dataflow/propagation/install/mongoose/schema-string.js +156 -0
  23. package/lib/dataflow/propagation/install/mysql-connection-escape.js +5 -0
  24. package/lib/dataflow/propagation/install/parse-int.js +60 -0
  25. package/lib/dataflow/propagation/install/pug-runtime-escape.js +9 -2
  26. package/lib/dataflow/propagation/install/querystring/parse.js +11 -9
  27. package/lib/dataflow/propagation/install/sequelize.js +6 -3
  28. package/lib/dataflow/propagation/install/sql-template-strings.js +9 -2
  29. package/lib/dataflow/propagation/install/string/concat.js +8 -2
  30. package/lib/dataflow/propagation/install/string/format-methods.js +7 -2
  31. package/lib/dataflow/propagation/install/string/html-methods.js +15 -5
  32. package/lib/dataflow/propagation/install/string/match.js +14 -9
  33. package/lib/dataflow/propagation/install/string/replace.js +22 -14
  34. package/lib/dataflow/propagation/install/string/slice.js +13 -5
  35. package/lib/dataflow/propagation/install/string/split.js +15 -11
  36. package/lib/dataflow/propagation/install/string/substring.js +16 -6
  37. package/lib/dataflow/propagation/install/string/trim.js +3 -0
  38. package/lib/dataflow/propagation/install/unescape.js +9 -2
  39. package/lib/dataflow/propagation/install/url/domain-parsers.js +7 -2
  40. package/lib/dataflow/propagation/install/validator/hooks.js +6 -2
  41. package/lib/dataflow/sinks/install/child-process.js +116 -50
  42. package/lib/dataflow/sinks/install/express/unvalidated-redirect.js +6 -3
  43. package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.js +7 -4
  44. package/lib/dataflow/sinks/install/fs.js +44 -12
  45. package/lib/dataflow/sinks/install/http.js +5 -2
  46. package/lib/dataflow/sinks/install/koa/unvalidated-redirect.js +7 -4
  47. package/lib/dataflow/sinks/install/marsdb.js +3 -0
  48. package/lib/dataflow/sinks/install/mongodb.js +249 -149
  49. package/lib/dataflow/sinks/install/mssql.js +9 -2
  50. package/lib/dataflow/sinks/install/mysql.js +9 -4
  51. package/lib/dataflow/sinks/install/postgres.js +6 -3
  52. package/lib/dataflow/sinks/install/sequelize.js +7 -5
  53. package/lib/dataflow/sinks/install/sqlite3.js +7 -3
  54. package/lib/dataflow/sources/handler.js +141 -26
  55. package/lib/dataflow/sources/index.js +2 -7
  56. package/lib/dataflow/sources/install/body-parser1.js +19 -6
  57. package/lib/dataflow/sources/install/express/index.js +4 -1
  58. package/lib/dataflow/sources/install/express/params.js +81 -0
  59. package/lib/dataflow/sources/install/express/parsedUrl.js +87 -0
  60. package/lib/dataflow/sources/install/http.js +33 -19
  61. package/lib/dataflow/sources/install/querystring.js +75 -0
  62. package/lib/dataflow/tag-utils.js +92 -1
  63. package/lib/dataflow/tracker.js +6 -6
  64. package/lib/index.js +2 -0
  65. package/lib/response-scanning/handlers/utils.js +2 -2
  66. package/lib/session-configuration/index.js +34 -0
  67. package/lib/session-configuration/install/http.js +79 -0
  68. package/package.json +2 -2
@@ -34,8 +34,10 @@ module.exports = function(core) {
34
34
 
35
35
  return core.assess.dataflow.propagation.encodeURIComponent = {
36
36
  install() {
37
+ const name = 'global.encodeURIComponent';
38
+
37
39
  patcher.patch(global, 'encodeURIComponent', {
38
- name: 'global.encodeURIComponent',
40
+ name,
39
41
  patchType,
40
42
  post(data) {
41
43
  const { args, result, hooked, orig } = data;
@@ -54,7 +56,10 @@ module.exports = function(core) {
54
56
  newTags[URL_ENCODED] = [0, result.length - 1];
55
57
 
56
58
  const event = createPropagationEvent({
57
- name: 'global.encodeURIComponent',
59
+ name,
60
+ moduleName: 'global',
61
+ methodName: 'encodeURIComponent',
62
+ context: `encodeURIComponent('${argInfo.value}')`,
58
63
  object: {
59
64
  value: createObjectLabel('global'),
60
65
  tracked: false
@@ -66,6 +71,8 @@ module.exports = function(core) {
66
71
  args: [{ value: argInfo.value, tracked: true }],
67
72
  tags: newTags,
68
73
  history,
74
+ source: 'P',
75
+ target: 'R',
69
76
  addedTags: [URL_ENCODED],
70
77
  stacktraceOpts: {
71
78
  constructorOpt: hooked,
@@ -35,9 +35,11 @@ module.exports = function(core) {
35
35
 
36
36
  return core.assess.dataflow.propagation.escapeHtml = {
37
37
  install() {
38
- depHooks.resolve({ name: 'escape-html' }, (escapeHtml, version) =>
39
- patcher.patch(escapeHtml, {
40
- name: 'escape-html',
38
+ depHooks.resolve({ name: 'escape-html' }, (escapeHtml) => {
39
+ const name = 'escape-html';
40
+
41
+ return patcher.patch(escapeHtml, {
42
+ name,
41
43
  patchType,
42
44
  post(data) {
43
45
  const { args, result, hooked, orig } = data;
@@ -54,7 +56,10 @@ module.exports = function(core) {
54
56
  newTags[HTML_ENCODED] = [0, result.length - 1];
55
57
 
56
58
  const event = createPropagationEvent({
57
- name: 'escape-html',
59
+ name,
60
+ moduleName: 'escape-html',
61
+ methodName: '',
62
+ context: `escapeHtml(${argInfo.value})`,
58
63
  object: {
59
64
  value: 'escape-html',
60
65
  tracked: false
@@ -66,6 +71,8 @@ module.exports = function(core) {
66
71
  args: [{ value: argInfo.value, tracked: true }],
67
72
  tags: newTags,
68
73
  history,
74
+ source: 'P',
75
+ target: 'R',
69
76
  addedTags: [HTML_ENCODED],
70
77
  stacktraceOpts: {
71
78
  constructorOpt: hooked,
@@ -85,7 +92,8 @@ module.exports = function(core) {
85
92
  data.result = extern;
86
93
  }
87
94
  }
88
- })
95
+ });
96
+ }
89
97
  );
90
98
  },
91
99
  };
@@ -34,8 +34,10 @@ module.exports = function(core) {
34
34
 
35
35
  return core.assess.dataflow.propagation.escape = {
36
36
  install() {
37
+ const name = 'global.escape';
38
+
37
39
  patcher.patch(global, 'escape', {
38
- name: 'global.escape',
40
+ name,
39
41
  patchType,
40
42
  post(data) {
41
43
  const { args, result, hooked, orig } = data;
@@ -52,7 +54,10 @@ module.exports = function(core) {
52
54
  newTags[WEAK_URL_ENCODED] = [0, result.length - 1];
53
55
 
54
56
  const event = createPropagationEvent({
55
- name: 'global.escape',
57
+ name,
58
+ moduleName: 'global',
59
+ methodName: 'escape',
60
+ context: `escape('${argInfo.value}')`,
56
61
  object: {
57
62
  value: createObjectLabel('global'),
58
63
  tracked: false
@@ -64,6 +69,8 @@ module.exports = function(core) {
64
69
  args: [{ value: argInfo.value, tracked: true }],
65
70
  tags: newTags,
66
71
  history,
72
+ source: 'P',
73
+ target: 'R',
67
74
  addedTags: [WEAK_URL_ENCODED],
68
75
  stacktraceOpts: {
69
76
  constructorOpt: hooked,
@@ -21,7 +21,7 @@ const {
21
21
  const {
22
22
  createFullLengthCopyTags
23
23
  } = require('../../tag-utils');
24
- const { patchType, createModuleLabel } = require('../common');
24
+ const { patchType } = require('../common');
25
25
 
26
26
  module.exports = function(core) {
27
27
  const {
@@ -36,8 +36,10 @@ module.exports = function(core) {
36
36
  return core.assess.dataflow.propagation.handlebarsEscapeExpression = {
37
37
  install() {
38
38
  depHooks.resolve({ name: 'handlebars', version: '>=4.0.0' }, (handlebars, version) => {
39
+ const name = 'handlebars.Utils.escapeExpression';
40
+
39
41
  patcher.patch(handlebars.Utils, 'escapeExpression', {
40
- name: 'handlebars.Utils.escapeExpression',
42
+ name,
41
43
  patchType,
42
44
  post(data) {
43
45
  const { args, result, hooked, orig } = data;
@@ -54,9 +56,12 @@ module.exports = function(core) {
54
56
  newTags[HTML_ENCODED] = [0, result.length - 1];
55
57
 
56
58
  const event = createPropagationEvent({
57
- name: 'handlebars.Utils.escapeExpression',
59
+ name,
60
+ moduleName: 'handlebars',
61
+ methodName: 'Utils.escapeExpression',
62
+ context: `${name}('${argInfo.value}')`,
58
63
  object: {
59
- value: `[${createModuleLabel('handlebars', version)}].Utils`,
64
+ value: 'handlebars.Utils',
60
65
  tracked: false
61
66
  },
62
67
  result: {
@@ -67,6 +72,8 @@ module.exports = function(core) {
67
72
  tags: newTags,
68
73
  addedTags: [HTML_ENCODED],
69
74
  history,
75
+ source: 'P',
76
+ target: 'R',
70
77
  stacktraceOpts: {
71
78
  constructorOpt: hooked,
72
79
  prependFrames: [orig]
@@ -0,0 +1,59 @@
1
+ /*
2
+ * Copyright: 2022 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
+
16
+ 'use strict';
17
+
18
+ const { isString } = require('@contrast/common');
19
+ const { patchType } = require('../common');
20
+
21
+ module.exports = function(core) {
22
+ const {
23
+ logger,
24
+ scopes: { sources, instrumentation },
25
+ patcher,
26
+ depHooks,
27
+ assess: {
28
+ dataflow: { tracker }
29
+ }
30
+ } = core;
31
+
32
+ return core.assess.dataflow.propagation.isnumericInstrumentation = {
33
+ install() {
34
+ const name = 'isnumeric';
35
+
36
+ depHooks.resolve({ name, version: '<1.0.0' }, (_export, { version }) => {
37
+ const fullName = `${name}@${version}`;
38
+ return patcher.patch(_export, {
39
+ name,
40
+ patchType,
41
+ post(data) {
42
+ const { args: [value], result } = data;
43
+ if (
44
+ !result ||
45
+ !value ||
46
+ !isString(value) ||
47
+ !sources.getStore()?.assess ||
48
+ instrumentation.isLocked() ||
49
+ !tracker.getData(value)
50
+ ) return;
51
+
52
+ tracker.untrack(value);
53
+ logger.trace({ sanitizer: fullName, value }, 'untracked a string value');
54
+ }
55
+ });
56
+ });
57
+ },
58
+ };
59
+ };
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright: 2022 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
+
16
+ 'use strict';
17
+
18
+ const c = require('@contrast/common');
19
+
20
+ module.exports = function(core) {
21
+ const component = core.assess.dataflow.propagation.mongooseInstrumentation = {
22
+ install() {
23
+ c.callChildComponentMethodsSync(component, 'install');
24
+ }
25
+ };
26
+
27
+ // todo NODE-3103
28
+ // require('./schema-map')(core);
29
+
30
+ // todo NODE-3102
31
+ // require('./schema-mixed')(core);
32
+
33
+ require('./schema-string')(core);
34
+
35
+ return component;
36
+ };
@@ -0,0 +1,156 @@
1
+ /*
2
+ * Copyright: 2022 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
+
16
+ 'use strict';
17
+
18
+ const { DataflowTag, substring } = require('@contrast/common');
19
+ const { patchType } = require('../../common');
20
+
21
+ module.exports = function(core) {
22
+ const {
23
+ scopes: { sources },
24
+ patcher,
25
+ depHooks,
26
+ assess: {
27
+ dataflow: {
28
+ tracker,
29
+ eventFactory: { createPropagationEvent }
30
+ }
31
+ }
32
+ } = core;
33
+
34
+ return core.assess.dataflow.propagation.mongooseInstrumentation.schemaString = {
35
+ install() {
36
+ depHooks.resolve(
37
+ { name: 'mongoose', file: 'lib/schema/string.js', version: '>=6.0.0' },
38
+ (SchemaString) => {
39
+ patchEnum(SchemaString);
40
+ patchDoValidate(SchemaString);
41
+ patchDoValidateSync(SchemaString);
42
+ }
43
+ );
44
+ },
45
+ };
46
+
47
+ function patchEnum(SchemaString) {
48
+ patcher.patch(SchemaString.prototype, 'enum', {
49
+ name: 'mongoose.SchemaString.prototype.enum',
50
+ patchType,
51
+ post(data) {
52
+ if (!data.result) return;
53
+
54
+ const enumValidator = data.result.validators.find(
55
+ (validator) => validator.type === 'enum'
56
+ );
57
+
58
+ if (!enumValidator) return;
59
+
60
+ patcher.patch(enumValidator, 'validator', {
61
+ name: 'mongoose.SchemaString.prototype.enum.validator',
62
+ patchType,
63
+ post(data) {
64
+ const sourceContext = sources.getStore()?.assess;
65
+ if (!sourceContext) return;
66
+
67
+ if (data.result) {
68
+ tracker.untrack(data.args[0]);
69
+ }
70
+ }
71
+ });
72
+ }
73
+ });
74
+ }
75
+
76
+ function patchDoValidate(SchemaString) {
77
+ // called when `Model.validate(data)` static method is used, as well as `model.validate()` instance method
78
+ const name = 'mongoose.SchemaString.prototype.doValidate';
79
+ patcher.patch(SchemaString.prototype, 'doValidate', {
80
+ name,
81
+ patchType,
82
+ pre(data) {
83
+ const [value, cb] = data.args;
84
+ if (value && typeof cb === 'function' && sources.getStore()?.assess) {
85
+ data.args[1] = patcher.patch(cb, {
86
+ name,
87
+ patchType,
88
+ pre({ args: [err] }) {
89
+ if (!err) propagate(name, data.orig, value);
90
+ }
91
+ });
92
+ }
93
+ }
94
+ });
95
+ }
96
+
97
+ function patchDoValidateSync(SchemaString) {
98
+ const name = 'mongoose.SchemaString.prototype.doValidateSync';
99
+ patcher.patch(SchemaString.prototype, 'doValidateSync', {
100
+ name,
101
+ patchType,
102
+ post({ orig, args: [value] }) {
103
+ if (value?.length) {
104
+ propagate(name, orig, value);
105
+ }
106
+ }
107
+ });
108
+
109
+ }
110
+
111
+ function propagate(name, orig, value) {
112
+ const strInfo = tracker.getData(value);
113
+ if (!strInfo) return;
114
+
115
+ const methodName = substring(name, name.indexOf('.') + 1);
116
+ // copy because we mutate the metadata value inline
117
+ const history = [{ ...strInfo }];
118
+ const event = createPropagationEvent({
119
+ addedTags: [DataflowTag.STRING_TYPE_CHECKED],
120
+ name,
121
+ moduleName: 'mongoose',
122
+ methodName,
123
+ history,
124
+ object: {
125
+ tracked: false,
126
+ value: 'mongoose.SchemaString',
127
+ },
128
+ args: [{ tracked: true, value: strInfo.value }],
129
+ result: {
130
+ tracked: false,
131
+ value: undefined,
132
+ },
133
+ source: 'P0',
134
+ tags: {
135
+ ...strInfo.tags,
136
+ [DataflowTag.STRING_TYPE_CHECKED]: [0, value.length - 1],
137
+ },
138
+ target: 'P0',
139
+ stacktraceOpts: {
140
+ prependFrames: [orig],
141
+ }
142
+ });
143
+
144
+ if (!event) {
145
+ return;
146
+ }
147
+
148
+ // in case the event type changed e.g. Source->Propagation
149
+ for (const key of Object.keys(strInfo)) {
150
+ if (key === 'value' || key === 'extern') continue;
151
+ delete strInfo[key];
152
+ }
153
+
154
+ Object.assign(strInfo, event);
155
+ }
156
+ };
@@ -50,6 +50,9 @@ module.exports = function(core) {
50
50
 
51
51
  const event = createPropagationEvent({
52
52
  name: eventName,
53
+ moduleName: 'mysql',
54
+ methodName: 'escape',
55
+ context: `mysql.escape('${argInfo.value}')`,
53
56
  object: {
54
57
  value: objectValue,
55
58
  tracked: false
@@ -62,6 +65,8 @@ module.exports = function(core) {
62
65
  tags: newTags,
63
66
  addedTags: [SQL_ENCODED],
64
67
  history,
68
+ source: 'P',
69
+ target: 'R',
65
70
  stacktraceOpts: {
66
71
  constructorOpt: hooked,
67
72
  prependFrames: [orig]
@@ -0,0 +1,60 @@
1
+ /*
2
+ * Copyright: 2022 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
+
16
+ 'use strict';
17
+
18
+ const { isString } = require('@contrast/common');
19
+ const { patchType } = require('../common');
20
+
21
+ module.exports = function(core) {
22
+ const {
23
+ logger,
24
+ scopes: { instrumentation, sources },
25
+ patcher,
26
+ assess: {
27
+ dataflow: { tracker }
28
+ }
29
+ } = core;
30
+
31
+ const name = 'global.parseInt';
32
+
33
+ return core.assess.dataflow.propagation.parseIntInstrumentation = {
34
+ install() {
35
+ patcher.patch(global, 'parseInt', {
36
+ name,
37
+ patchType,
38
+ post(data) {
39
+ const { args: [value], result } = data;
40
+ if (
41
+ isNaN(result) ||
42
+ !value ||
43
+ !isString(value) ||
44
+ !sources.getStore()?.assess ||
45
+ instrumentation.isLocked() ||
46
+ !tracker.getData(value)
47
+ ) return;
48
+
49
+ // todo NODE-3118 to handle when value has trailing non-integer values
50
+
51
+ tracker.untrack(value);
52
+ logger.trace({ sanitizer: name, value }, 'untracked a string value');
53
+ }
54
+ });
55
+ },
56
+ uninstall() {
57
+ global.parseInt = patcher.unwrap(global.parseInt);
58
+ },
59
+ };
60
+ };
@@ -36,8 +36,10 @@ module.exports = function(core) {
36
36
  return core.assess.dataflow.propagation.pugRuntimeEscape = {
37
37
  install() {
38
38
  depHooks.resolve({ name: 'pug-runtime' }, (pugRuntime, version) => {
39
+ const name = 'pug-runtime.escape';
40
+
39
41
  patcher.patch(pugRuntime, 'escape', {
40
- name: 'pug-runtime.escape',
42
+ name,
41
43
  patchType,
42
44
  post(data) {
43
45
  const { args, result, hooked, orig } = data;
@@ -54,7 +56,10 @@ module.exports = function(core) {
54
56
  newTags[WEAK_URL_ENCODED] = [0, result.length - 1];
55
57
 
56
58
  const event = createPropagationEvent({
57
- name: 'pug-runtime.escape',
59
+ name,
60
+ moduleName: 'pug-runtime',
61
+ methodName: 'escape',
62
+ context: `pugRuntime.escape('${argInfo.value}')`,
58
63
  object: {
59
64
  value: createModuleLabel('pug-runtime', version),
60
65
  tracked: false
@@ -67,6 +72,8 @@ module.exports = function(core) {
67
72
  tags: newTags,
68
73
  addedTags: [WEAK_URL_ENCODED],
69
74
  history,
75
+ source: 'P',
76
+ target: 'R',
70
77
  stacktraceOpts: {
71
78
  constructorOpt: hooked,
72
79
  prependFrames: [orig]
@@ -15,10 +15,11 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const util = require('util');
19
18
  const querystring = require('querystring');
20
19
  const {
21
- DataflowTag: { URL_ENCODED }
20
+ DataflowTag: { URL_ENCODED },
21
+ inspect,
22
+ join
22
23
  } = require('@contrast/common');
23
24
 
24
25
  const { patchType } = require('../../common');
@@ -46,20 +47,21 @@ module.exports = function(core) {
46
47
  if (!tagRanges) return result;
47
48
 
48
49
  const resultInfo = tracker.getData(result);
50
+ const [, ...restOfArgsValues] = data.origArgs.map(inspect);
49
51
  const event = createPropagationEvent({
50
52
  name: data.name,
53
+ context: `querystring.parse('${trackingData.value}', ${join(restOfArgsValues, ', ')})`,
54
+ moduleName: 'querystring',
55
+ methodName: 'parse',
51
56
  history: [trackingData],
52
57
  object: {
53
58
  value: part,
54
59
  tracked: true,
55
60
  },
56
- args: data.origArgs.map((arg) => {
57
- const argInfo = tracker.getData(arg);
58
- return {
59
- value: argInfo ? argInfo.value : util.inspect(arg),
60
- tracked: !!argInfo
61
- };
62
- }),
61
+ args: data.origArgs.map((_arg, idx) => ({
62
+ value: idx === 0 ? trackingData.value : restOfArgsValues[idx - 1],
63
+ tracked: !!idx === 0
64
+ })),
63
65
  result: {
64
66
  value: result,
65
67
  tracked: !!resultInfo
@@ -21,7 +21,7 @@ const {
21
21
  } = require('@contrast/common');
22
22
  const { patchType, createModuleLabel } = require('../common');
23
23
 
24
- module.exports = function (core) {
24
+ module.exports = function(core) {
25
25
  const {
26
26
  scopes: { sources, instrumentation },
27
27
  patcher,
@@ -58,9 +58,10 @@ module.exports = function (core) {
58
58
  { name: 'sequelize', file: 'lib/sql-string.js' },
59
59
  (sqlString, version) => {
60
60
  const origEscape = sqlString.escape;
61
+ const name = 'sequelize.escape';
61
62
 
62
63
  patcher.patch(sqlString, 'escape', {
63
- name: 'sequelize.escape',
64
+ name,
64
65
  patchType,
65
66
  post(data) {
66
67
  const { args, result, hooked, orig } = data;
@@ -85,8 +86,10 @@ module.exports = function (core) {
85
86
  newTags[SQL_ENCODED] = [0, result.length - 1];
86
87
 
87
88
  const event = createPropagationEvent({
88
- context: 'sequelize.escape',
89
+ context: `sequelize.escape('${argInfo.value}')`,
89
90
  name: 'sequelize/lib/sql-string.escape',
91
+ moduleName: 'sequelize',
92
+ methodName: 'escape',
90
93
  object: {
91
94
  value: createModuleLabel('sequelize/lib/sql-string.escape', version),
92
95
  tracked: false,
@@ -33,8 +33,10 @@ module.exports = function(core) {
33
33
  return core.assess.dataflow.propagation.sqlTemplateStrings = {
34
34
  install() {
35
35
  depHooks.resolve({ name: 'sql-template-strings' }, (sqlTemplateStrings, version) => {
36
+ const name = 'sql-template-strings.SQL';
37
+
36
38
  patcher.patch(sqlTemplateStrings, 'SQL', {
37
- name: 'sql-template-strings.SQL',
39
+ name,
38
40
  patchType,
39
41
  post(data) {
40
42
  const { args, result, hooked, orig } = data;
@@ -55,7 +57,10 @@ module.exports = function(core) {
55
57
  newTags[SQL_ENCODED] = [0, resultValue.length - 1];
56
58
 
57
59
  const event = createPropagationEvent({
58
- name: 'sql-template-strings.SQL',
60
+ name,
61
+ moduleName: 'sql-template-strings',
62
+ methodName: 'SQL',
63
+ context: `SQL\`${argInfo.value}\``,
59
64
  object: {
60
65
  value: createModuleLabel('sql-template-strings', version),
61
66
  tracked: false
@@ -68,6 +73,8 @@ module.exports = function(core) {
68
73
  tags: newTags,
69
74
  addedTags: [SQL_ENCODED],
70
75
  history,
76
+ source: 'P',
77
+ target: 'R',
71
78
  stacktraceOpts: {
72
79
  constructorOpt: hooked,
73
80
  prependFrames: [orig]
@@ -18,6 +18,7 @@
18
18
  const {
19
19
  createAppendTags
20
20
  } = require('../../../tag-utils');
21
+ const { join, inspect } = require('@contrast/common');
21
22
  const { patchType } = require('../../common');
22
23
 
23
24
  module.exports = function(core) {
@@ -31,8 +32,10 @@ module.exports = function(core) {
31
32
 
32
33
  return core.assess.dataflow.propagation.stringInstrumentation.concat = {
33
34
  install() {
35
+ const name = 'String.prototype.concat';
36
+
34
37
  patcher.patch(String.prototype, 'concat', {
35
- name: 'String.prototype.concat',
38
+ name,
36
39
  patchType,
37
40
  post(data) {
38
41
  const { args, obj, result, hooked, orig } = data;
@@ -70,7 +73,10 @@ module.exports = function(core) {
70
73
 
71
74
  if (history.size) {
72
75
  const event = createPropagationEvent({
73
- name: 'String.prototype.concat',
76
+ name,
77
+ moduleName: 'String',
78
+ methodName: 'prototype.concat',
79
+ context: `${inspect(objInfo?.value) || String(obj)}.concat(${join(argsData.map(d => d.value), ', ')})`,
74
80
  object: {
75
81
  value: objInfo?.value || String(obj),
76
82
  tracked: !!objInfo
@@ -29,8 +29,10 @@ module.exports = function(core) {
29
29
  return core.assess.dataflow.propagation.stringInstrumentation.formatMethods = {
30
30
  install() {
31
31
  ['toLowerCase', 'toUpperCase', 'toLocaleLowerCase', 'toLocaleUpperCase'].forEach((method) => {
32
+ const name = `String.prototype.${method}`;
33
+
32
34
  patcher.patch(String.prototype, method, {
33
- name: `String.prototype.${method}`,
35
+ name,
34
36
  patchType,
35
37
  post(data) {
36
38
  const { obj, result, hooked, orig } = data;
@@ -43,7 +45,10 @@ module.exports = function(core) {
43
45
  const history = [objInfo];
44
46
 
45
47
  const event = createPropagationEvent({
46
- name: `String.prototype.${method}`,
48
+ name,
49
+ moduleName: 'String',
50
+ methodName: `prototype.${method}`,
51
+ context: `'${objInfo.value}'.${method}()`,
47
52
  object: {
48
53
  value: objInfo.value,
49
54
  tracked: true