@contrast/assess 1.1.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 (111) hide show
  1. package/coverage/lcov-report/base.css +224 -0
  2. package/coverage/lcov-report/block-navigation.js +87 -0
  3. package/coverage/lcov-report/favicon.png +0 -0
  4. package/coverage/lcov-report/index.html +266 -0
  5. package/coverage/lcov-report/lib/dataflow/common.js.html +154 -0
  6. package/coverage/lcov-report/lib/dataflow/event-factory.js.html +598 -0
  7. package/coverage/lcov-report/lib/dataflow/index.html +191 -0
  8. package/coverage/lcov-report/lib/dataflow/index.js.html +190 -0
  9. package/coverage/lcov-report/lib/dataflow/propagation/common.js.html +145 -0
  10. package/coverage/lcov-report/lib/dataflow/propagation/index.html +131 -0
  11. package/coverage/lcov-report/lib/dataflow/propagation/index.js.html +190 -0
  12. package/coverage/lcov-report/lib/dataflow/propagation/install/contrast-methods/index.html +131 -0
  13. package/coverage/lcov-report/lib/dataflow/propagation/install/contrast-methods/index.js.html +184 -0
  14. package/coverage/lcov-report/lib/dataflow/propagation/install/contrast-methods/plus.js.html +397 -0
  15. package/coverage/lcov-report/lib/dataflow/propagation/install/string/concat.js.html +478 -0
  16. package/coverage/lcov-report/lib/dataflow/propagation/install/string/index.html +176 -0
  17. package/coverage/lcov-report/lib/dataflow/propagation/install/string/index.js.html +202 -0
  18. package/coverage/lcov-report/lib/dataflow/propagation/install/string/replace.js.html +496 -0
  19. package/coverage/lcov-report/lib/dataflow/propagation/install/string/substring.js.html +415 -0
  20. package/coverage/lcov-report/lib/dataflow/propagation/install/string/trim.js.html +403 -0
  21. package/coverage/lcov-report/lib/dataflow/signatures.js.html +5923 -0
  22. package/coverage/lcov-report/lib/dataflow/sinks/common.js.html +145 -0
  23. package/coverage/lcov-report/lib/dataflow/sinks/index.html +131 -0
  24. package/coverage/lcov-report/lib/dataflow/sinks/index.js.html +211 -0
  25. package/coverage/lcov-report/lib/dataflow/sinks/install/fastify/index.html +146 -0
  26. package/coverage/lcov-report/lib/dataflow/sinks/install/fastify/index.js.html +172 -0
  27. package/coverage/lcov-report/lib/dataflow/sinks/install/fastify/unvalidated-redirect.js.html +319 -0
  28. package/coverage/lcov-report/lib/dataflow/sinks/install/fastify/xss.js.html +721 -0
  29. package/coverage/lcov-report/lib/dataflow/sinks/install/http.js.html +340 -0
  30. package/coverage/lcov-report/lib/dataflow/sinks/install/index.html +116 -0
  31. package/coverage/lcov-report/lib/dataflow/sources/common.js.html +145 -0
  32. package/coverage/lcov-report/lib/dataflow/sources/index.html +131 -0
  33. package/coverage/lcov-report/lib/dataflow/sources/index.js.html +226 -0
  34. package/coverage/lcov-report/lib/dataflow/sources/install/fastify.js.html +379 -0
  35. package/coverage/lcov-report/lib/dataflow/sources/install/http.js.html +502 -0
  36. package/coverage/lcov-report/lib/dataflow/sources/install/index.html +146 -0
  37. package/coverage/lcov-report/lib/dataflow/sources/install/qs.js.html +322 -0
  38. package/coverage/lcov-report/lib/dataflow/tag-utils.js.html +418 -0
  39. package/coverage/lcov-report/lib/dataflow/tracker.js.html +466 -0
  40. package/coverage/lcov-report/lib/dataflow/utils/index.html +116 -0
  41. package/coverage/lcov-report/lib/dataflow/utils/is-vulnerable.js.html +424 -0
  42. package/coverage/lcov-report/lib/index.html +116 -0
  43. package/coverage/lcov-report/lib/index.js.html +193 -0
  44. package/coverage/lcov-report/prettify.css +1 -0
  45. package/coverage/lcov-report/prettify.js +2 -0
  46. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  47. package/coverage/lcov-report/sorter.js +196 -0
  48. package/coverage/lcov.info +4856 -0
  49. package/coverage/tmp/coverage-9548-1675168551025-0.json +1 -0
  50. package/coverage/tmp/coverage-9551-1675168550963-0.json +1 -0
  51. package/coverage/tmp/coverage-9552-1675168550969-0.json +1 -0
  52. package/coverage/tmp/coverage-9553-1675168550970-0.json +1 -0
  53. package/coverage/tmp/coverage-9554-1675168550962-0.json +1 -0
  54. package/coverage/tmp/coverage-9555-1675168550965-0.json +1 -0
  55. package/coverage/tmp/coverage-9556-1675168550964-0.json +1 -0
  56. package/coverage/tmp/coverage-9557-1675168550969-0.json +1 -0
  57. package/coverage/tmp/coverage-9558-1675168550964-0.json +1 -0
  58. package/coverage/tmp/coverage-9559-1675168550971-0.json +1 -0
  59. package/lib/dataflow/event-factory.js +256 -0
  60. package/lib/dataflow/index.js +35 -0
  61. package/lib/dataflow/propagation/common.js +26 -0
  62. package/lib/dataflow/propagation/index.js +50 -0
  63. package/lib/dataflow/propagation/install/array-prototype-join.js +125 -0
  64. package/lib/dataflow/propagation/install/contrast-methods/add.js +104 -0
  65. package/lib/dataflow/propagation/install/contrast-methods/index.js +34 -0
  66. package/lib/dataflow/propagation/install/contrast-methods/tag.js +102 -0
  67. package/lib/dataflow/propagation/install/decode-uri-component.js +88 -0
  68. package/lib/dataflow/propagation/install/ejs/escape-xml.js +89 -0
  69. package/lib/dataflow/propagation/install/ejs/index.js +30 -0
  70. package/lib/dataflow/propagation/install/encode-uri-component.js +87 -0
  71. package/lib/dataflow/propagation/install/escape-html.js +89 -0
  72. package/lib/dataflow/propagation/install/escape.js +89 -0
  73. package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.js +89 -0
  74. package/lib/dataflow/propagation/install/mysql-connection-escape.js +111 -0
  75. package/lib/dataflow/propagation/install/pug/index.js +64 -0
  76. package/lib/dataflow/propagation/install/pug-runtime-escape.js +89 -0
  77. package/lib/dataflow/propagation/install/sql-template-strings.js +103 -0
  78. package/lib/dataflow/propagation/install/string/concat.js +108 -0
  79. package/lib/dataflow/propagation/install/string/format-methods.js +83 -0
  80. package/lib/dataflow/propagation/install/string/html-methods.js +163 -0
  81. package/lib/dataflow/propagation/install/string/index.js +38 -0
  82. package/lib/dataflow/propagation/install/string/replace.js +197 -0
  83. package/lib/dataflow/propagation/install/string/substring.js +117 -0
  84. package/lib/dataflow/propagation/install/string/trim.js +115 -0
  85. package/lib/dataflow/propagation/install/unescape.js +90 -0
  86. package/lib/dataflow/propagation/install/url/domain-parsers.js +89 -0
  87. package/lib/dataflow/propagation/install/url/index.js +33 -0
  88. package/lib/dataflow/propagation/install/validator/hooks.js +172 -0
  89. package/lib/dataflow/propagation/install/validator/index.js +28 -0
  90. package/lib/dataflow/propagation/install/validator/methods.js +82 -0
  91. package/lib/dataflow/signatures.js +2022 -0
  92. package/lib/dataflow/sinks/common.js +20 -0
  93. package/lib/dataflow/sinks/index.js +44 -0
  94. package/lib/dataflow/sinks/install/fastify/index.js +30 -0
  95. package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.js +107 -0
  96. package/lib/dataflow/sinks/install/http.js +119 -0
  97. package/lib/dataflow/sinks/install/postgres/index.js +129 -0
  98. package/lib/dataflow/sources/common.js +20 -0
  99. package/lib/dataflow/sources/handler.js +114 -0
  100. package/lib/dataflow/sources/index.js +35 -0
  101. package/lib/dataflow/sources/install/fastify/cookie.js +61 -0
  102. package/lib/dataflow/sources/install/fastify/fastify.js +89 -0
  103. package/lib/dataflow/sources/install/fastify/index.js +31 -0
  104. package/lib/dataflow/sources/install/http.js +181 -0
  105. package/lib/dataflow/sources/install/qs.js +88 -0
  106. package/lib/dataflow/tag-utils.js +122 -0
  107. package/lib/dataflow/tracker.js +127 -0
  108. package/lib/dataflow/utils/is-safe-content-type.js +30 -0
  109. package/lib/dataflow/utils/is-vulnerable.js +113 -0
  110. package/lib/index.js +36 -0
  111. package/package.json +21 -0
@@ -0,0 +1,102 @@
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 { patchType } = require('../../common');
19
+
20
+ module.exports = function (core) {
21
+ const {
22
+ assess: {
23
+ dataflow: {
24
+ tracker,
25
+ eventFactory: { createPropagationEvent },
26
+ },
27
+ },
28
+ patcher,
29
+ scopes: { sources, instrumentation },
30
+ } = core;
31
+
32
+ const tag = {
33
+ install() {
34
+ patcher.patch(global.ContrastMethods, 'tag', {
35
+ name: 'ContrastMethods.tag',
36
+ patchType,
37
+ post(data) {
38
+ if (
39
+ !data.result ||
40
+ !sources.getStore()?.assess ||
41
+ instrumentation.isLocked()
42
+ ) {
43
+ return;
44
+ }
45
+
46
+ const resultData = tracker.getData(data.result);
47
+ if (!resultData || data.result === data.args[1]) {
48
+ return;
49
+ }
50
+
51
+ const [strings, ...args] = data.args;
52
+ const argsData = [
53
+ strings.map((str) => ({
54
+ value: str,
55
+ isTracked: false,
56
+ })),
57
+ ];
58
+
59
+ const history = new Set();
60
+ args.forEach((arg) => {
61
+ const argData = tracker.getData(arg);
62
+ argsData.push({
63
+ value: argData?.value ?? arg,
64
+ isTracked: !!argData,
65
+ });
66
+ if (argData) history.add(argData);
67
+ });
68
+
69
+ Object.assign(
70
+ resultData,
71
+ createPropagationEvent({
72
+ name: 'ContrastMethods.tag',
73
+ history: Array.from(history),
74
+ object: {
75
+ value: 'ContrastMethods@0000',
76
+ isTracked: false,
77
+ },
78
+ args: argsData,
79
+ result: {
80
+ value: resultData.value,
81
+ isTracked: true,
82
+ },
83
+ tags: resultData.tags,
84
+ source: 'P',
85
+ target: 'R',
86
+ stacktraceOpts: {
87
+ constructorOpt: data.hooked,
88
+ prependFrames: [data.orig],
89
+ },
90
+ }),
91
+ );
92
+ },
93
+ });
94
+ },
95
+ uninstall() {
96
+ global.ContrastMethods.tag = patcher.unwrap(global.ContrastMethods.tag);
97
+ },
98
+ };
99
+
100
+ core.assess.dataflow.propagation.contrastMethodsInstrumentation.tag = tag;
101
+ return tag;
102
+ };
@@ -0,0 +1,88 @@
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 {
19
+ createFullLengthCopyTags
20
+ } = require('../../tag-utils');
21
+ const { patchType, createObjectLabel } = require('../common');
22
+
23
+ module.exports = function(core) {
24
+ const {
25
+ scopes: { sources, instrumentation },
26
+ patcher,
27
+ assess: {
28
+ dataflow: { tracker, eventFactory: { createPropagationEvent } }
29
+ }
30
+ } = core;
31
+
32
+ return core.assess.dataflow.propagation.decodeURIComponent = {
33
+ install() {
34
+ patcher.patch(global, 'decodeURIComponent', {
35
+ name: 'global.decodeURIComponent',
36
+ patchType,
37
+ post(data) {
38
+ const { args, result, hooked, orig } = data;
39
+ if (!result || !args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
40
+
41
+ const argInfo = tracker.getData(args[0]);
42
+
43
+ if (!argInfo) return;
44
+
45
+ // This native method seems to create a new string instance
46
+ // as even when it returns the argument without any change
47
+ // the result is not tracked, so we don't need to check for that
48
+ const history = [argInfo];
49
+ const newTags = createFullLengthCopyTags(argInfo.tags, result.length);
50
+ delete newTags['url-encoded'];
51
+
52
+ if (!Object.keys(newTags).length) return;
53
+
54
+ const event = createPropagationEvent({
55
+ name: 'global.decodeURIComponent',
56
+ object: {
57
+ value: createObjectLabel('global'),
58
+ isTracked: false
59
+ },
60
+ result: {
61
+ value: result,
62
+ isTracked: true
63
+ },
64
+ args: [{ value: argInfo.value, isTracked: true }],
65
+ tags: newTags,
66
+ history,
67
+ removedTags: ['url-encoded'],
68
+ stacktraceOpts: {
69
+ constructorOpt: hooked,
70
+ prependFrames: [orig]
71
+ },
72
+ });
73
+
74
+ if (!event) return;
75
+
76
+ const { extern } = tracker.track(result, event);
77
+
78
+ if (extern) {
79
+ data.result = extern;
80
+ }
81
+ }
82
+ });
83
+ },
84
+ uninstall() {
85
+ global.decodeURIComponent = patcher.unwrap(global.decodeURIComponent);
86
+ },
87
+ };
88
+ };
@@ -0,0 +1,89 @@
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 {
19
+ createFullLengthCopyTags
20
+ } = require('../../../tag-utils');
21
+ const { patchType, createModuleLabel } = require('../../common');
22
+
23
+ module.exports = function(core) {
24
+ const {
25
+ scopes: { sources, instrumentation },
26
+ patcher,
27
+ depHooks,
28
+ assess: {
29
+ dataflow: { tracker, eventFactory: { createPropagationEvent } }
30
+ }
31
+ } = core;
32
+
33
+ return core.assess.dataflow.propagation.ejsInstrumentation.escapeXML = {
34
+ install() {
35
+ depHooks.resolve({ name: 'ejs', file: 'lib/utils.js', version: '>=2.6.2' }, (ejsUtils, version) => {
36
+ patcher.patch(ejsUtils, 'escapeXML', {
37
+ name: 'ejs.utils.escapeXML',
38
+ patchType,
39
+ post(data) {
40
+ const { args, result, hooked, orig } = data;
41
+ if (!result || !args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
42
+
43
+ const argInfo = tracker.getData(args[0]);
44
+
45
+ if (!argInfo) return;
46
+
47
+ const resultInfo = tracker.getData(result);
48
+ const history = [argInfo];
49
+ const newTags = createFullLengthCopyTags(argInfo.tags, result.length);
50
+
51
+ newTags['weak-url-encoded'] = [0, result.length - 1];
52
+
53
+ const event = createPropagationEvent({
54
+ name: 'ejs.utils.escapeXML',
55
+ object: {
56
+ value: `[${createModuleLabel('ejs', version)}].utils`,
57
+ isTracked: false
58
+ },
59
+ result: {
60
+ value: resultInfo ? resultInfo.value : result,
61
+ isTracked: true
62
+ },
63
+ args: [{ value: argInfo.value, isTracked: true }],
64
+ tags: newTags,
65
+ addedTags: ['weak-url-encoded'],
66
+ history,
67
+ stacktraceOpts: {
68
+ constructorOpt: hooked,
69
+ prependFrames: [orig]
70
+ },
71
+ });
72
+
73
+ if (!event) return;
74
+
75
+ if (resultInfo) {
76
+ Object.assign(resultInfo, event);
77
+ }
78
+
79
+ const { extern } = resultInfo || tracker.track(result, event);
80
+
81
+ if (extern) {
82
+ data.result = extern;
83
+ }
84
+ }
85
+ });
86
+ });
87
+ },
88
+ };
89
+ };
@@ -0,0 +1,30 @@
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 { callChildComponentMethodsSync } = require('@contrast/common');
19
+
20
+ module.exports = function(core) {
21
+ const ejsInstrumentation = core.assess.dataflow.propagation.ejsInstrumentation = {
22
+ install() {
23
+ callChildComponentMethodsSync(ejsInstrumentation, 'install');
24
+ },
25
+ };
26
+
27
+ require('./escape-xml')(core);
28
+
29
+ return ejsInstrumentation;
30
+ };
@@ -0,0 +1,87 @@
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 {
19
+ createFullLengthCopyTags
20
+ } = require('../../tag-utils');
21
+ const { patchType, createObjectLabel } = require('../common');
22
+
23
+ module.exports = function(core) {
24
+ const {
25
+ scopes: { sources, instrumentation },
26
+ patcher,
27
+ assess: {
28
+ dataflow: { tracker, eventFactory: { createPropagationEvent } }
29
+ }
30
+ } = core;
31
+
32
+ return core.assess.dataflow.propagation.encodeURIComponent = {
33
+ install() {
34
+ patcher.patch(global, 'encodeURIComponent', {
35
+ name: 'global.encodeURIComponent',
36
+ patchType,
37
+ post(data) {
38
+ const { args, result, hooked, orig } = data;
39
+ if (!result || !args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
40
+
41
+ const argInfo = tracker.getData(args[0]);
42
+
43
+ if (!argInfo) return;
44
+
45
+ // This native method seems to create a new string instance
46
+ // as even when it returns the argument without any change
47
+ // the result is not tracked, so we don't need to check for that
48
+ const history = [argInfo];
49
+ const newTags = createFullLengthCopyTags(argInfo.tags, result.length);
50
+
51
+ newTags['url-encoded'] = [0, result.length - 1];
52
+
53
+ const event = createPropagationEvent({
54
+ name: 'global.encodeURIComponent',
55
+ object: {
56
+ value: createObjectLabel('global'),
57
+ isTracked: false
58
+ },
59
+ result: {
60
+ value: result,
61
+ isTracked: true
62
+ },
63
+ args: [{ value: argInfo.value, isTracked: true }],
64
+ tags: newTags,
65
+ history,
66
+ addedTags: ['url-encoded'],
67
+ stacktraceOpts: {
68
+ constructorOpt: hooked,
69
+ prependFrames: [orig]
70
+ },
71
+ });
72
+
73
+ if (!event) return;
74
+
75
+ const { extern } = tracker.track(result, event);
76
+
77
+ if (extern) {
78
+ data.result = extern;
79
+ }
80
+ }
81
+ });
82
+ },
83
+ uninstall() {
84
+ global.encodeURIComponent = patcher.unwrap(global.encodeURIComponent);
85
+ },
86
+ };
87
+ };
@@ -0,0 +1,89 @@
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 {
19
+ createFullLengthCopyTags
20
+ } = require('../../tag-utils');
21
+ const { patchType, createModuleLabel } = require('../common');
22
+
23
+ module.exports = function(core) {
24
+ const {
25
+ scopes: { sources, instrumentation },
26
+ patcher,
27
+ depHooks,
28
+ assess: {
29
+ dataflow: { tracker, eventFactory: { createPropagationEvent } }
30
+ }
31
+ } = core;
32
+
33
+ return core.assess.dataflow.propagation.escapeHtml = {
34
+ install() {
35
+ depHooks.resolve({ name: 'escape-html' }, (escapeHtml, version) =>
36
+ patcher.patch(escapeHtml, {
37
+ name: 'escape-html',
38
+ patchType,
39
+ post(data) {
40
+ const { args, result, hooked, orig } = data;
41
+ if (!result || !args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
42
+
43
+ const argInfo = tracker.getData(args[0]);
44
+
45
+ if (!argInfo) return;
46
+
47
+ const resultInfo = tracker.getData(result);
48
+ const history = [argInfo];
49
+ const newTags = createFullLengthCopyTags(argInfo.tags, result.length);
50
+
51
+ newTags['html-encoded'] = [0, result.length - 1];
52
+
53
+ const event = createPropagationEvent({
54
+ name: 'escape-html',
55
+ object: {
56
+ value: createModuleLabel('escape-html', version),
57
+ isTracked: false
58
+ },
59
+ result: {
60
+ value: resultInfo ? resultInfo.value : result,
61
+ isTracked: true
62
+ },
63
+ args: [{ value: argInfo.value, isTracked: true }],
64
+ tags: newTags,
65
+ history,
66
+ addedTags: ['html-encoded'],
67
+ stacktraceOpts: {
68
+ constructorOpt: hooked,
69
+ prependFrames: [orig]
70
+ },
71
+ });
72
+
73
+ if (!event) return;
74
+
75
+ if (resultInfo) {
76
+ Object.assign(resultInfo, event);
77
+ }
78
+
79
+ const { extern } = resultInfo || tracker.track(result, event);
80
+
81
+ if (extern) {
82
+ data.result = extern;
83
+ }
84
+ }
85
+ })
86
+ );
87
+ },
88
+ };
89
+ };
@@ -0,0 +1,89 @@
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 {
19
+ createFullLengthCopyTags
20
+ } = require('../../tag-utils');
21
+ const { patchType, createObjectLabel } = require('../common');
22
+
23
+ module.exports = function(core) {
24
+ const {
25
+ scopes: { sources, instrumentation },
26
+ patcher,
27
+ assess: {
28
+ dataflow: { tracker, eventFactory: { createPropagationEvent } }
29
+ }
30
+ } = core;
31
+
32
+ return core.assess.dataflow.propagation.escape = {
33
+ install() {
34
+ patcher.patch(global, 'escape', {
35
+ name: 'global.escape',
36
+ patchType,
37
+ post(data) {
38
+ const { args, result, hooked, orig } = data;
39
+ if (!result || !args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
40
+
41
+ const argInfo = tracker.getData(args[0]);
42
+
43
+ if (!argInfo) return;
44
+
45
+ const resultInfo = tracker.getData(result);
46
+ const history = [argInfo];
47
+ const newTags = createFullLengthCopyTags(argInfo.tags, result.length);
48
+
49
+ newTags['weak-url-encoded'] = [0, result.length - 1];
50
+
51
+ const event = createPropagationEvent({
52
+ name: 'global.escape',
53
+ object: {
54
+ value: createObjectLabel('global'),
55
+ isTracked: false
56
+ },
57
+ result: {
58
+ value: resultInfo ? resultInfo.value : result,
59
+ isTracked: true
60
+ },
61
+ args: [{ value: argInfo.value, isTracked: true }],
62
+ tags: newTags,
63
+ history,
64
+ addedTags: ['weak-url-encoded'],
65
+ stacktraceOpts: {
66
+ constructorOpt: hooked,
67
+ prependFrames: [orig]
68
+ },
69
+ });
70
+
71
+ if (!event) return;
72
+
73
+ if (resultInfo) {
74
+ Object.assign(resultInfo, event);
75
+ }
76
+
77
+ const { extern } = resultInfo || tracker.track(result, event);
78
+
79
+ if (extern) {
80
+ data.result = extern;
81
+ }
82
+ }
83
+ });
84
+ },
85
+ uninstall() {
86
+ global.escape = patcher.unwrap(global.escape);
87
+ },
88
+ };
89
+ };
@@ -0,0 +1,89 @@
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 {
19
+ createFullLengthCopyTags
20
+ } = require('../../tag-utils');
21
+ const { patchType, createModuleLabel } = require('../common');
22
+
23
+ module.exports = function(core) {
24
+ const {
25
+ scopes: { sources, instrumentation },
26
+ patcher,
27
+ depHooks,
28
+ assess: {
29
+ dataflow: { tracker, eventFactory: { createPropagationEvent } }
30
+ }
31
+ } = core;
32
+
33
+ return core.assess.dataflow.propagation.handlebarsEscapeExpression = {
34
+ install() {
35
+ depHooks.resolve({ name: 'handlebars', version: '>=4.0.0' }, (handlebars, version) => {
36
+ patcher.patch(handlebars.Utils, 'escapeExpression', {
37
+ name: 'handlebars.Utils.escapeExpression',
38
+ patchType,
39
+ post(data) {
40
+ const { args, result, hooked, orig } = data;
41
+ if (!result || !args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
42
+
43
+ const argInfo = tracker.getData(args[0]);
44
+
45
+ if (!argInfo) return;
46
+
47
+ const resultInfo = tracker.getData(result);
48
+ const history = [argInfo];
49
+ const newTags = createFullLengthCopyTags(argInfo.tags, result.length);
50
+
51
+ newTags['html-encoded'] = [0, result.length - 1];
52
+
53
+ const event = createPropagationEvent({
54
+ name: 'handlebars.Utils.escapeExpression',
55
+ object: {
56
+ value: `[${createModuleLabel('handlebars', version)}].Utils`,
57
+ isTracked: false
58
+ },
59
+ result: {
60
+ value: resultInfo ? resultInfo.value : result,
61
+ isTracked: true
62
+ },
63
+ args: [{ value: argInfo.value, isTracked: true }],
64
+ tags: newTags,
65
+ addedTags: ['html-encoded'],
66
+ history,
67
+ stacktraceOpts: {
68
+ constructorOpt: hooked,
69
+ prependFrames: [orig]
70
+ },
71
+ });
72
+
73
+ if (!event) return;
74
+
75
+ if (resultInfo) {
76
+ Object.assign(resultInfo, event);
77
+ }
78
+
79
+ const { extern } = resultInfo || tracker.track(result, event);
80
+
81
+ if (extern) {
82
+ data.result = extern;
83
+ }
84
+ }
85
+ });
86
+ });
87
+ },
88
+ };
89
+ };