@contrast/assess 1.46.1 → 1.46.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.
Files changed (157) hide show
  1. package/package.json +14 -11
  2. package/lib/crypto-analysis/install/crypto.test.js +0 -146
  3. package/lib/crypto-analysis/install/math.test.js +0 -65
  4. package/lib/dataflow/index.test.js +0 -36
  5. package/lib/dataflow/propagation/index.test.js +0 -103
  6. package/lib/dataflow/propagation/install/JSON/index.test.js +0 -50
  7. package/lib/dataflow/propagation/install/JSON/parse-fn.test.js +0 -232
  8. package/lib/dataflow/propagation/install/JSON/parse.test.js +0 -968
  9. package/lib/dataflow/propagation/install/JSON/stringify.test.js +0 -265
  10. package/lib/dataflow/propagation/install/array-prototype-join.test.js +0 -106
  11. package/lib/dataflow/propagation/install/buffer.test.js +0 -112
  12. package/lib/dataflow/propagation/install/contrast-methods/add.test.js +0 -94
  13. package/lib/dataflow/propagation/install/contrast-methods/index.test.js +0 -49
  14. package/lib/dataflow/propagation/install/contrast-methods/number.test.js +0 -50
  15. package/lib/dataflow/propagation/install/contrast-methods/string.test.js +0 -148
  16. package/lib/dataflow/propagation/install/contrast-methods/tag.test.js +0 -145
  17. package/lib/dataflow/propagation/install/decode-uri-component.test.js +0 -78
  18. package/lib/dataflow/propagation/install/ejs/escape-xml.test.js +0 -69
  19. package/lib/dataflow/propagation/install/ejs/template.test.js +0 -62
  20. package/lib/dataflow/propagation/install/encode-uri.test.js +0 -83
  21. package/lib/dataflow/propagation/install/escape-html.test.js +0 -71
  22. package/lib/dataflow/propagation/install/escape.test.js +0 -73
  23. package/lib/dataflow/propagation/install/fastify-send.test.js +0 -42
  24. package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.test.js +0 -71
  25. package/lib/dataflow/propagation/install/isnumeric-0.test.js +0 -58
  26. package/lib/dataflow/propagation/install/joi/any.test.js +0 -270
  27. package/lib/dataflow/propagation/install/joi/array.test.js +0 -912
  28. package/lib/dataflow/propagation/install/joi/boolean.test.js +0 -103
  29. package/lib/dataflow/propagation/install/joi/expression.test.js +0 -76
  30. package/lib/dataflow/propagation/install/joi/index.test.js +0 -39
  31. package/lib/dataflow/propagation/install/joi/number.test.js +0 -103
  32. package/lib/dataflow/propagation/install/joi/object.test.js +0 -119
  33. package/lib/dataflow/propagation/install/joi/ref.test.js +0 -607
  34. package/lib/dataflow/propagation/install/joi/string-schema.test.js +0 -513
  35. package/lib/dataflow/propagation/install/mongoose/index.test.js +0 -42
  36. package/lib/dataflow/propagation/install/mongoose/schema-map.test.js +0 -348
  37. package/lib/dataflow/propagation/install/mongoose/schema-mixed.test.js +0 -511
  38. package/lib/dataflow/propagation/install/mongoose/schema-string.test.js +0 -199
  39. package/lib/dataflow/propagation/install/mustache-escape.test.js +0 -62
  40. package/lib/dataflow/propagation/install/mysql-connection-escape.test.js +0 -74
  41. package/lib/dataflow/propagation/install/parse-int.test.js +0 -48
  42. package/lib/dataflow/propagation/install/path/basename.test.js +0 -143
  43. package/lib/dataflow/propagation/install/path/dirname.test.js +0 -167
  44. package/lib/dataflow/propagation/install/path/extname.test.js +0 -141
  45. package/lib/dataflow/propagation/install/path/format.test.js +0 -250
  46. package/lib/dataflow/propagation/install/path/index.test.js +0 -45
  47. package/lib/dataflow/propagation/install/path/join-and-resolve.test.js +0 -485
  48. package/lib/dataflow/propagation/install/path/normalize.test.js +0 -176
  49. package/lib/dataflow/propagation/install/path/parse.test.js +0 -238
  50. package/lib/dataflow/propagation/install/path/relative.test.js +0 -239
  51. package/lib/dataflow/propagation/install/path/toNamespacedPath.test.js +0 -158
  52. package/lib/dataflow/propagation/install/pug/index.test.js +0 -55
  53. package/lib/dataflow/propagation/install/pug-runtime-escape.test.js +0 -69
  54. package/lib/dataflow/propagation/install/querystring/escape.test.js +0 -63
  55. package/lib/dataflow/propagation/install/querystring/index.test.js +0 -40
  56. package/lib/dataflow/propagation/install/querystring/parse.test.js +0 -272
  57. package/lib/dataflow/propagation/install/querystring/stringify.test.js +0 -301
  58. package/lib/dataflow/propagation/install/reg-exp-prototype-exec.test.js +0 -283
  59. package/lib/dataflow/propagation/install/send.test.js +0 -63
  60. package/lib/dataflow/propagation/install/sequelize/query-generator.test.js +0 -74
  61. package/lib/dataflow/propagation/install/sequelize/sql-string.test.js +0 -119
  62. package/lib/dataflow/propagation/install/sql-template-strings.test.js +0 -100
  63. package/lib/dataflow/propagation/install/string/concat.test.js +0 -145
  64. package/lib/dataflow/propagation/install/string/format-methods.test.js +0 -74
  65. package/lib/dataflow/propagation/install/string/html-methods.test.js +0 -177
  66. package/lib/dataflow/propagation/install/string/index.test.js +0 -103
  67. package/lib/dataflow/propagation/install/string/match-all.test.js +0 -412
  68. package/lib/dataflow/propagation/install/string/match.test.js +0 -374
  69. package/lib/dataflow/propagation/install/string/replace.test.js +0 -601
  70. package/lib/dataflow/propagation/install/string/slice.test.js +0 -278
  71. package/lib/dataflow/propagation/install/string/split.test.js +0 -513
  72. package/lib/dataflow/propagation/install/string/substring.test.js +0 -251
  73. package/lib/dataflow/propagation/install/string/trim.test.js +0 -135
  74. package/lib/dataflow/propagation/install/unescape.test.js +0 -78
  75. package/lib/dataflow/propagation/install/url/domain-parsers.test.js +0 -63
  76. package/lib/dataflow/propagation/install/url/parse.test.js +0 -391
  77. package/lib/dataflow/propagation/install/url/searchParams.test.js +0 -538
  78. package/lib/dataflow/propagation/install/url/url.test.js +0 -466
  79. package/lib/dataflow/propagation/install/util-format.test.js +0 -336
  80. package/lib/dataflow/propagation/install/validator/hooks.test.js +0 -211
  81. package/lib/dataflow/sinks/index.test.js +0 -78
  82. package/lib/dataflow/sinks/install/child-process.test.js +0 -338
  83. package/lib/dataflow/sinks/install/eval.test.js +0 -95
  84. package/lib/dataflow/sinks/install/express/index.test.js +0 -33
  85. package/lib/dataflow/sinks/install/express/reflected-xss.test.js +0 -109
  86. package/lib/dataflow/sinks/install/express/unvalidated-redirect.test.js +0 -144
  87. package/lib/dataflow/sinks/install/fastify/index.test.js +0 -32
  88. package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.test.js +0 -130
  89. package/lib/dataflow/sinks/install/fs.test.js +0 -138
  90. package/lib/dataflow/sinks/install/function.test.js +0 -103
  91. package/lib/dataflow/sinks/install/hapi/index.test.js +0 -32
  92. package/lib/dataflow/sinks/install/hapi/unvalidated-redirect.test.js +0 -130
  93. package/lib/dataflow/sinks/install/http/index.test.js +0 -33
  94. package/lib/dataflow/sinks/install/http/request.test.js +0 -184
  95. package/lib/dataflow/sinks/install/http/server-response.test.js +0 -160
  96. package/lib/dataflow/sinks/install/koa/index.test.js +0 -32
  97. package/lib/dataflow/sinks/install/koa/unvalidated-redirect.test.js +0 -200
  98. package/lib/dataflow/sinks/install/libxmljs.test.js +0 -158
  99. package/lib/dataflow/sinks/install/marsdb.test.js +0 -166
  100. package/lib/dataflow/sinks/install/mongodb.test.js +0 -617
  101. package/lib/dataflow/sinks/install/mssql.test.js +0 -134
  102. package/lib/dataflow/sinks/install/mysql.test.js +0 -224
  103. package/lib/dataflow/sinks/install/node-serialize.test.js +0 -83
  104. package/lib/dataflow/sinks/install/postgres.test.js +0 -152
  105. package/lib/dataflow/sinks/install/restify.test.js +0 -140
  106. package/lib/dataflow/sinks/install/sequelize.test.js +0 -100
  107. package/lib/dataflow/sinks/install/sqlite3.test.js +0 -118
  108. package/lib/dataflow/sinks/install/vm.test.js +0 -326
  109. package/lib/dataflow/sources/handler.test.js +0 -501
  110. package/lib/dataflow/sources/index.test.js +0 -60
  111. package/lib/dataflow/sources/install/body-parser1.test.js +0 -244
  112. package/lib/dataflow/sources/install/busboy.test.js +0 -152
  113. package/lib/dataflow/sources/install/cookie-parser1.test.js +0 -141
  114. package/lib/dataflow/sources/install/express/params.test.js +0 -110
  115. package/lib/dataflow/sources/install/express/parsedUrl.test.js +0 -107
  116. package/lib/dataflow/sources/install/fastify/fastify.test.js +0 -207
  117. package/lib/dataflow/sources/install/fastify/index.test.js +0 -33
  118. package/lib/dataflow/sources/install/formidable1.test.js +0 -119
  119. package/lib/dataflow/sources/install/graphql-http.test.js +0 -133
  120. package/lib/dataflow/sources/install/hapi/hapi.test.js +0 -171
  121. package/lib/dataflow/sources/install/hapi/index.test.js +0 -33
  122. package/lib/dataflow/sources/install/http.test.js +0 -149
  123. package/lib/dataflow/sources/install/koa/index.test.js +0 -40
  124. package/lib/dataflow/sources/install/koa/koa-bodyparsers.test.js +0 -160
  125. package/lib/dataflow/sources/install/koa/koa-multer.test.js +0 -197
  126. package/lib/dataflow/sources/install/koa/koa-routers.test.js +0 -146
  127. package/lib/dataflow/sources/install/koa/koa2.test.js +0 -145
  128. package/lib/dataflow/sources/install/multer1.test.js +0 -143
  129. package/lib/dataflow/sources/install/qs6.test.js +0 -131
  130. package/lib/dataflow/sources/install/querystring.test.js +0 -82
  131. package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.test.js +0 -86
  132. package/lib/dataflow/sources/install/restify/index.test.js +0 -38
  133. package/lib/dataflow/sources/install/restify/jsonBodyParser.test.js +0 -140
  134. package/lib/dataflow/sources/install/restify/router.test.js +0 -81
  135. package/lib/dataflow/tag-utils-complete.test.js +0 -27
  136. package/lib/dataflow/tag-utils.test.js +0 -192
  137. package/lib/dataflow/tracker.test.js +0 -216
  138. package/lib/dataflow/utils/is-safe-content-type.test.js +0 -16
  139. package/lib/dataflow/utils/is-vulnerable.test.js +0 -115
  140. package/lib/event-factory.test.js +0 -326
  141. package/lib/get-policy.test.js +0 -194
  142. package/lib/get-source-context.test.js +0 -161
  143. package/lib/index.test.js +0 -45
  144. package/lib/make-source-context.test.js +0 -50
  145. package/lib/response-scanning/handlers/index.test.js +0 -419
  146. package/lib/response-scanning/handlers/utils.test.js +0 -380
  147. package/lib/response-scanning/index.test.js +0 -41
  148. package/lib/response-scanning/install/http.test.js +0 -175
  149. package/lib/rule-scopes.test.js +0 -27
  150. package/lib/sampler/common.test.js +0 -101
  151. package/lib/sampler/index.test.js +0 -313
  152. package/lib/session-configuration/handlers.test.js +0 -84
  153. package/lib/session-configuration/index.test.js +0 -36
  154. package/lib/session-configuration/install/express-session.test.js +0 -218
  155. package/lib/session-configuration/install/fastify-cookie.test.js +0 -63
  156. package/lib/session-configuration/install/hapi.test.js +0 -269
  157. package/lib/session-configuration/install/koa.test.js +0 -92
@@ -1,265 +0,0 @@
1
- 'use strict';
2
-
3
- const { expect } = require('chai');
4
- const { initAssessFixture } = require('@contrast/test/fixtures');
5
- const {
6
- primordials: { UtilInspect },
7
- DataflowTag: { UNTRUSTED },
8
- } = require('@contrast/common');
9
- const origStringify = JSON.stringify;
10
-
11
- describe('assess dataflow propagation JSON stringify', function () {
12
- let core,
13
- simulateRequestScope,
14
- trackString,
15
- tracker,
16
- objWithoutTrackedStr,
17
- objWithTrackedStr,
18
- standardEvent;
19
-
20
- beforeEach(function () {
21
- ({ core, trackString, simulateRequestScope } = initAssessFixture());
22
-
23
- tracker = core.assess.dataflow.tracker;
24
-
25
- core.assess.dataflow.propagation.jsonInstrumentation.stringify.install();
26
- core.assess.dataflow.propagation.stringInstrumentation.concat.install();
27
-
28
- objWithoutTrackedStr = {
29
- prop1: 'test',
30
- prop2: 'test2',
31
- arr: [1, 2, 'test3'],
32
- nested: {
33
- obj: 'prop',
34
- },
35
- };
36
-
37
- simulateRequestScope(() => {
38
- objWithTrackedStr = {
39
- prop1: trackString('test'),
40
- prop2: trackString('test2'),
41
- arr: [1, 2, trackString('test3')],
42
- nested: {
43
- obj: trackString('prop'),
44
- },
45
- };
46
- });
47
-
48
- standardEvent = {
49
- object: {
50
- tracked: false,
51
- value: 'JSON',
52
- },
53
- args: [{ tracked: false, value: 'Object' }],
54
- context: `JSON.stringify(${origStringify(objWithTrackedStr)})`,
55
- name: 'JSON.stringify',
56
- moduleName: 'JSON',
57
- methodName: 'stringify',
58
- source: 'P0',
59
- target: 'R',
60
- result: {
61
- tracked: true,
62
- value: origStringify(objWithTrackedStr),
63
- },
64
- value: origStringify(objWithTrackedStr),
65
- tags: {
66
- [UNTRUSTED]: [10, 13, 25, 29, 44, 48, 69, 72],
67
- },
68
- };
69
- });
70
-
71
- afterEach(function () {
72
- core.assess.dataflow.propagation.jsonInstrumentation.stringify.uninstall();
73
- });
74
-
75
- it('results in an untracked string when the object is with all strings untracked ', function () {
76
- simulateRequestScope(() => {
77
- const ret = JSON.stringify(objWithoutTrackedStr);
78
- expect(ret).to.equal(origStringify(objWithoutTrackedStr));
79
- expect(tracker.getData(ret)).to.be.null;
80
- });
81
- });
82
-
83
- it('results in an untracked string when there is no Assess policy in request scope', function () {
84
- simulateRequestScope(() => {
85
- const ret = JSON.stringify(objWithTrackedStr);
86
- expect(ret).to.equal(origStringify(objWithTrackedStr));
87
- expect(tracker.getData(ret)).to.be.null;
88
- }, { assess: { policy: null } });
89
- });
90
-
91
- it('results in an untracked string when instrumentation is locked', function () {
92
- simulateRequestScope(() => {
93
- core.scopes.instrumentation.run({ lock: true }, () => {
94
- const ret = JSON.stringify(objWithTrackedStr);
95
- expect(ret).to.equal(origStringify(objWithTrackedStr));
96
- expect(tracker.getData(ret)).to.be.null;
97
- });
98
- });
99
- });
100
-
101
- it('propagates correctly all kinds of string properties in a generic JSON.stringify call', function () {
102
- simulateRequestScope(() => {
103
- const ret = JSON.stringify(objWithTrackedStr);
104
- expect(ret).to.equal(standardEvent.value);
105
- expect(tracker.getData(ret)).to.be.like(standardEvent);
106
- });
107
- });
108
-
109
- it('propagates correctly all kinds of string properties in a JSON.stringify call with predefined spaces', function () {
110
- simulateRequestScope(() => {
111
- const stringifyArgs = [objWithTrackedStr, (_k, v) => v, 's'];
112
- const ret = JSON.stringify(...stringifyArgs);
113
- expect(ret).to.equal(origStringify(...stringifyArgs));
114
- expect(tracker.getData(ret)).to.be.like({
115
- ...standardEvent,
116
- context: `JSON.stringify(${origStringify(...stringifyArgs)})`,
117
- args: [
118
- {
119
- tracked: false,
120
- value: 'Object'
121
- },
122
- {
123
- tracked: false,
124
- value: 'Function',
125
- },
126
- {
127
- tracked: false,
128
- value: 'String',
129
- }
130
- ],
131
- value: origStringify(...stringifyArgs),
132
- result: {
133
- tracked: true,
134
- value: origStringify(...stringifyArgs),
135
- },
136
- tags: {
137
- [UNTRUSTED]: [13, 16, 31, 35, 62, 66, 96, 99],
138
- },
139
- });
140
- });
141
- });
142
-
143
- it('propagates correctly a JSON.stringify call with untrusted specified spaces', function () {
144
- simulateRequestScope(() => {
145
- const stringifyArgs = [
146
- objWithoutTrackedStr,
147
- (_k, v) => v,
148
- trackString('user'),
149
- ];
150
- const ret = JSON.stringify(...stringifyArgs);
151
-
152
- expect(ret).to.equal(origStringify(...stringifyArgs));
153
- expect(tracker.getData(ret)).to.be.like({
154
- ...standardEvent,
155
- context: `JSON.stringify(${origStringify(...stringifyArgs)})`,
156
- args: [
157
- {
158
- tracked: false,
159
- value: 'Object',
160
- },
161
- {
162
- tracked: false,
163
- value: 'Function',
164
- },
165
- {
166
- tracked: true,
167
- value: UtilInspect(stringifyArgs[2]),
168
- },
169
- ],
170
- value: origStringify(...stringifyArgs),
171
- source: 'P2',
172
- result: {
173
- tracked: true,
174
- value: origStringify(...stringifyArgs),
175
- },
176
- tags: {
177
- [UNTRUSTED]: [
178
- 2, 5, 23, 26, 45, 48, 58, 65, 69, 76, 80, 87, 96, 99, 103, 106, 119,
179
- 126, 141, 144,
180
- ],
181
- },
182
- });
183
- });
184
- });
185
-
186
- it('propagates correctly all kind of string properties in a JSON.stringify call with untrusted specified spaces', function () {
187
- simulateRequestScope(() => {
188
- const stringifyArgs = [
189
- objWithTrackedStr,
190
- (_k, v) => v,
191
- trackString('user'),
192
- ];
193
- const ret = JSON.stringify(...stringifyArgs);
194
- expect(ret).to.equal(origStringify(...stringifyArgs));
195
- expect(tracker.getData(ret)).to.be.like({
196
- ...standardEvent,
197
- context: `JSON.stringify(${origStringify(...stringifyArgs)})`,
198
- args: [
199
- {
200
- tracked: false,
201
- value: 'Object',
202
- },
203
- {
204
- tracked: false,
205
- value: 'Function',
206
- },
207
- {
208
- tracked: true,
209
- value: UtilInspect(stringifyArgs[2]),
210
- },
211
- ],
212
- value: origStringify(...stringifyArgs),
213
- source: 'P',
214
- result: {
215
- tracked: true,
216
- value: origStringify(...stringifyArgs),
217
- },
218
- tags: {
219
- [UNTRUSTED]: [
220
- 2, 5, 16, 19, 23, 26, 37, 41, 45, 48, 58, 65, 69, 76, 80, 87, 89,
221
- 93, 96, 99, 103, 106, 119, 126, 135, 138, 141, 144,
222
- ],
223
- },
224
- });
225
- });
226
- });
227
-
228
- describe('some edge cases', function () {
229
- it('handles cases when the second argument is an array', function () {
230
- simulateRequestScope(() => {
231
- const stringifyArgs = [objWithTrackedStr, ['arr', 'nested', 'obj']];
232
- const ret = JSON.stringify(...stringifyArgs);
233
- expect(ret).to.equal(origStringify(...stringifyArgs));
234
- expect(tracker.getData(ret).tags).to.deep.equal({
235
- [UNTRUSTED]: [13, 17, 38, 41],
236
- });
237
- });
238
- });
239
-
240
- it('handles cases when the third argument is not entirely tagged', function () {
241
- simulateRequestScope(() => {
242
- const concatSpaces = 'd'.concat(
243
- trackString('us'),
244
- 'd',
245
- trackString('us')
246
- );
247
- const stringifyArgs = [
248
- objWithoutTrackedStr,
249
- (_k, v) => v,
250
- concatSpaces,
251
- ];
252
- const ret = JSON.stringify(...stringifyArgs);
253
- expect(ret).to.equal(origStringify(...stringifyArgs));
254
- expect(tracker.getData(ret).tags).to.deep.equal({
255
- [UNTRUSTED]: [
256
- 3, 4, 6, 7, 26, 27, 29, 30, 50, 51, 53, 54, 65, 66, 68, 69, 71, 72,
257
- 74, 75, 80, 81, 83, 84, 86, 87, 89, 90, 95, 96, 98, 99, 101, 102,
258
- 104, 105, 115, 116, 118, 119, 124, 125, 127, 128, 142, 143, 145,
259
- 146, 148, 149, 151, 152, 168, 169, 171, 172,
260
- ],
261
- });
262
- });
263
- });
264
- });
265
- });
@@ -1,106 +0,0 @@
1
- 'use strict';
2
-
3
- const { expect } = require('chai');
4
- const sinon = require('sinon');
5
- const { initAssessFixture } = require('@contrast/test/fixtures');
6
-
7
- describe('assess dataflow propagation array join', function () {
8
- let core, trackString, simulateRequestScope, tracker;
9
-
10
- beforeEach(function () {
11
- ({
12
- core,
13
- simulateRequestScope,
14
- trackString
15
- } = initAssessFixture());
16
-
17
- tracker = core.assess.dataflow.tracker;
18
- core.assess.dataflow.propagation.arrayJoin.install();
19
- });
20
-
21
- afterEach(function () {
22
- core.assess.dataflow.propagation.arrayJoin.uninstall();
23
- sinon.resetHistory();
24
- });
25
-
26
- [
27
- {
28
- expected: { untrusted: [12, 18, 38, 51] }
29
- },
30
- {
31
- separator: 'not-tracked',
32
- expected: { untrusted: [22, 28, 68, 81] }
33
- },
34
- {
35
- separator: 'tracked-sep',
36
- tags: {
37
- untrusted: [0, 10]
38
- },
39
- expected: { untrusted: [11, 39, 57, 81] }
40
- }
41
- ].forEach(({ separator, tags, expected }) => {
42
- it('propagates correctly', function () {
43
- simulateRequestScope(function () {
44
- const arr = [
45
- 'not-tracked',
46
- trackString('tracked', { tags: { untrusted: [0, 6] } }),
47
- 'another-untracked',
48
- trackString('another-tracked', { tags: { untrusted: [0, 13] } })
49
- ];
50
- let source = 'O';
51
-
52
- if (tags) {
53
- separator = trackString(separator, { tags });
54
- source = 'A';
55
- }
56
-
57
- const result = arr.join(separator);
58
- const strInfo = tracker.getData(result);
59
- expect(strInfo?.tags).to.deep.equal(expected);
60
- expect(strInfo?.source).to.equal(source);
61
- });
62
- });
63
- });
64
-
65
- it('propagates correctly nested arrays', function () {
66
- simulateRequestScope(function () {
67
- const str = trackString('tracked', { tags: { untrusted: [0, 6] } });
68
- const arr = [
69
- 'not-tracked',
70
- [
71
- 'not-tracked',
72
- str
73
- ],
74
- [
75
- 'not-tracked',
76
- [
77
- 'not-tracked',
78
- str
79
- ]
80
- ]
81
- ];
82
-
83
- const result = arr.join();
84
- const resultInfo = tracker.getData(result);
85
- expect(resultInfo?.tags).to.deep.equal({ untrusted: [24, 30, 56, 62] });
86
- });
87
- });
88
-
89
- it('will not propagate if there is no assess policy in source context', function () {
90
- simulateRequestScope(function () {
91
- const value = trackString('foo');
92
- const result = ['not-tracked', value].join();
93
- expect(tracker.getData(result)).to.be.null;
94
- }, { assess: { policy: null } });
95
- });
96
-
97
- it('will not propagate if there instrumentation is locked', function () {
98
- simulateRequestScope(function () {
99
- core.scopes.instrumentation.run({ lock: true }, function () {
100
- const value = trackString('foo');
101
- const result = ['not-tracked', value].join();
102
- expect(tracker.getData(result)).to.be.null;
103
- });
104
- });
105
- });
106
- });
@@ -1,112 +0,0 @@
1
- 'use strict';
2
-
3
- const { expect } = require('chai');
4
- const sinon = require('sinon');
5
- const { initAssessFixture } = require('@contrast/test/fixtures');
6
-
7
- describe('assess dataflow propagation Buffer', function () {
8
- let core, simulateRequestScope, tracker, trackString, createSourceEvent;
9
-
10
- beforeEach(function () {
11
- ({ core, simulateRequestScope, trackString } = initAssessFixture());
12
-
13
- tracker = core.assess.dataflow.tracker;
14
- createSourceEvent = core.assess.eventFactory.createSourceEvent;
15
- core.assess.dataflow.propagation.bufferInstrumentation.install();
16
- });
17
-
18
- afterEach(function () {
19
- core.assess.dataflow.propagation.arrayJoin.uninstall();
20
- sinon.resetHistory();
21
- });
22
-
23
- describe('Buffer.prototype.toString', function () {
24
- [
25
- 'utf8',
26
- 'latin1',
27
- 'ascii',
28
- // todo
29
- ].forEach((encoding) => {
30
- const value = 'foo';
31
-
32
- it(`value when buffer is tracked (${encoding})`, function () {
33
- simulateRequestScope(() => {
34
- const b = Buffer.from(value, encoding);
35
- const event = createSourceEvent({
36
- name: 'body-parser-mock',
37
- result: { tracked: true, value: b },
38
- inputType: 'BODY',
39
- tags: {
40
- UNTRUSTED: [0, 2],
41
- },
42
- stack: [],
43
- });
44
-
45
- tracker.track(b, event);
46
- expect(tracker.getData(b.toString(encoding))).to.deep.include({
47
- addedTags: [],
48
- args: [{ tracked: false, value: encoding }],
49
- moduleName: 'Buffer',
50
- methodName: 'prototype.toString',
51
- context: 'buffer.toString()',
52
- name: 'global.Buffer.prototype.toString',
53
- object: { tracked: true, value: 'Buffer' },
54
- removedTags: [],
55
- result: { tracked: true, value },
56
- source: 'O',
57
- stack: [],
58
- tags: {
59
- UNTRUSTED: [0, 2]
60
- },
61
- target: 'R',
62
- value,
63
- });
64
- });
65
- });
66
- });
67
- });
68
-
69
- describe('Buffer.from', function () {
70
- // todo: implementation for other types. see https://nodejs.org/api/buffer.html
71
-
72
- const trkInfoCommon = {
73
- object: { tracked: true, value: 'Buffer' },
74
- source: 'P0',
75
- target: 'R',
76
- tags: { UNTRUSTED: [0, 7] },
77
- name: 'global.Buffer.from',
78
- moduleName: 'Buffer',
79
- methodName: 'from',
80
- };
81
-
82
- [
83
- {
84
- getArgs: () => trackString('a string'),
85
- argType: 'string',
86
- expected: {
87
- ...trkInfoCommon,
88
- context: 'Buffer.from(a string)',
89
- args: [{ tracked: true, value: 'a string' }],
90
- }
91
- },
92
- {
93
- getArgs: () => Buffer.from(trackString('a buffer')),
94
- argType: 'buffer',
95
- expected: {
96
- ...trkInfoCommon,
97
- context: 'Buffer.from(a buffer)',
98
- args: [{ tracked: true, value: 'a buffer' }],
99
- }
100
- },
101
-
102
- ].forEach(({ argType, getArgs, expected }) => {
103
- it(`tracks result when argument is tracked (arg type ${argType})`, function () {
104
- simulateRequestScope(() => {
105
- const b = Buffer.from(getArgs());
106
- const trkInfo = tracker.getData(b);
107
- expect(trkInfo).to.deep.include(expected);
108
- });
109
- });
110
- });
111
- });
112
- });
@@ -1,94 +0,0 @@
1
- 'use strict';
2
-
3
- const {
4
- DataflowTag: {
5
- UNTRUSTED,
6
- }
7
- } = require('@contrast/common');
8
- const { expect } = require('chai');
9
- const sinon = require('sinon');
10
- const { initAssessFixture } = require('@contrast/test/fixtures');
11
-
12
- describe('assess dataflow propagation contrast-methods add', function () {
13
- let core, simulateRequestScope, trackString, tracker;
14
-
15
- beforeEach(function () {
16
- ({ core, simulateRequestScope, trackString } = initAssessFixture());
17
- tracker = core.assess.dataflow.tracker;
18
-
19
- core.contrastMethods.install();
20
- core.assess.dataflow.propagation.contrastMethodsInstrumentation.add.install();
21
- });
22
-
23
- afterEach(function () {
24
- core.assess.dataflow.propagation.contrastMethodsInstrumentation.add.uninstall();
25
- });
26
-
27
- const foo = () => trackString('foo');
28
- const bar = () => 'bar';
29
-
30
- [
31
- {
32
- name: 'tracked A, untracked B',
33
- args: [foo, bar],
34
- expected: {
35
- [UNTRUSTED]: [0, 2],
36
- },
37
- },
38
- {
39
- name: 'tracked A, tracked B',
40
- args: [foo, foo],
41
- expected: {
42
- [UNTRUSTED]: [0, 5],
43
- },
44
- },
45
- {
46
- name: 'untracked A, tracked B',
47
- args: [bar, foo],
48
- expected: {
49
- [UNTRUSTED]: [3, 5],
50
- },
51
- },
52
- {
53
- name: 'empty A, tracked B',
54
- args: [() => '', foo],
55
- expected: {
56
- [UNTRUSTED]: [0, 2],
57
- },
58
- },
59
- ].forEach(({ name, args, expected }) => {
60
- it(`propagates ${name} correctly`, function () {
61
- simulateRequestScope(function () {
62
- const result = global.ContrastMethods.add(...args.map(Reflect.apply));
63
-
64
- expect(tracker.getData(result))
65
- .to.have.property('tags')
66
- .that.deep.equals(expected);
67
- });
68
- });
69
- });
70
-
71
- it('will not propagate if there is no result or not in proper source scope', function () {
72
- const { extern } = tracker.track('foo', { tags: { UNTRUSTED: [0, 2] } });
73
-
74
- sinon.spy(tracker, 'track');
75
- sinon.spy(tracker, 'getData');
76
-
77
- core.scopes.sources.run({}, function () {
78
- global.ContrastMethods.add('', '');
79
- });
80
-
81
- core.scopes.sources.run(null, function () {
82
- global.ContrastMethods.add(extern, 'bar');
83
- });
84
-
85
- core.scopes.instrumentation.run({ lock: true }, function () {
86
- core.scopes.sources.run({}, function () {
87
- global.ContrastMethods.add(extern, 'bar');
88
- });
89
- });
90
-
91
- expect(tracker.track).not.to.have.been.called;
92
- expect(tracker.getData).not.to.have.been.called;
93
- });
94
- });
@@ -1,49 +0,0 @@
1
- 'use strict';
2
-
3
- const sinon = require('sinon');
4
- const { expect } = require('chai');
5
- const { initAssessFixture } = require('@contrast/test/fixtures');
6
-
7
- describe('assess dataflow propagation contrast-methods', function () {
8
- let core, instr;
9
-
10
- const propagators = ['add', 'tag', 'number'];
11
-
12
- beforeEach(function () {
13
- ({ core } = initAssessFixture());
14
- instr = core.assess.dataflow.propagation.contrastMethodsInstrumentation;
15
- });
16
-
17
- it('composes different installers', function () {
18
- propagators.forEach((name) => {
19
- expect(instr[name]).to.have.property('install').and.be.a('function');
20
- expect(instr[name]).to.have.property('uninstall').and.be.a('function');
21
- });
22
- });
23
-
24
- it('dispatches installation to sub-components', function () {
25
- const installs = [];
26
- const uninstalls = [];
27
- // stub these to prevent side effects
28
- propagators.forEach((name) => {
29
- const instr =
30
- core.assess.dataflow.propagation.contrastMethodsInstrumentation;
31
- installs.push(sinon.stub(instr[name], 'install'));
32
- uninstalls.push(sinon.stub(instr[name], 'uninstall'));
33
- });
34
-
35
- instr.install();
36
-
37
- expect(installs).to.have.lengthOf(propagators.length);
38
- installs.forEach((installer) => {
39
- expect(installer).to.have.been.called;
40
- });
41
-
42
- instr.uninstall();
43
-
44
- expect(uninstalls).to.have.lengthOf(propagators.length);
45
- uninstalls.forEach((installer) => {
46
- expect(installer).to.have.been.called;
47
- });
48
- });
49
- });
@@ -1,50 +0,0 @@
1
- 'use strict';
2
-
3
- const { expect } = require('chai');
4
- const { initAssessFixture } = require('@contrast/test/fixtures');
5
-
6
- describe('assess dataflow propagation contrast-methods number', function () {
7
- let core, simulateRequestScope, trackString, tracker;
8
-
9
- beforeEach(function () {
10
- ({ core, simulateRequestScope, trackString } = initAssessFixture());
11
- tracker = core.assess.dataflow.tracker;
12
- core.contrastMethods.install();
13
- core.assess.dataflow.propagation.contrastMethodsInstrumentation.number.install();
14
- });
15
-
16
- afterEach(function () {
17
- core.assess.dataflow.propagation.contrastMethodsInstrumentation.number.uninstall();
18
- });
19
-
20
- it('will not sanitize if Number coercion fails', function () {
21
- simulateRequestScope(() => {
22
- const str = trackString('foo');
23
- global.ContrastMethods.Number(str);
24
- expect(tracker.getData(str)).to.deep.include({
25
- context: 'UNKNOWN.val',
26
- name: 'assess-dataflow-fixture',
27
- fieldName: 'val',
28
- pathName: 'val',
29
- stack: [],
30
- inputType: 'UNKNOWN',
31
- tags: { UNTRUSTED: [0, 2] },
32
- result: { tracked: true, value: 'foo' },
33
- });
34
- });
35
- });
36
-
37
- it('will untrack if Number coercion succeeds', function () {
38
- simulateRequestScope(() => {
39
- const str = trackString('30000');
40
- global.ContrastMethods.Number(str);
41
- expect(tracker.getData(str)).to.be.null;
42
- expect(core.logger.trace).to.have.been.calledWithMatch({
43
- funcKey: 'assess-dataflow-propagator:ContrastMethods.Number',
44
- sanitizer: 'ContrastMethods.Number',
45
- value: '30000',
46
- }, 'untracked a string value');
47
-
48
- });
49
- });
50
- });