@contrast/assess 1.46.0 → 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,144 +0,0 @@
1
- 'use strict';
2
-
3
- const { expect } = require('chai');
4
- const sinon = require('sinon');
5
- const {
6
- DataflowTag: {
7
- UNTRUSTED,
8
- URL_ENCODED,
9
- }
10
- } = require('@contrast/common');
11
- const { initAssessFixture } = require('@contrast/test/fixtures');
12
-
13
- describe('assess dataflow sinks express unvalidated-redirect', function () {
14
- let core, Response, simulateRequestScope, trackString, reportFindings, reportSafePositive;
15
-
16
- beforeEach(function () {
17
- ({ core, simulateRequestScope, trackString } = initAssessFixture());
18
- reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
19
- reportSafePositive = sinon.stub(core.assess.dataflow.sinks, 'reportSafePositive');
20
-
21
- const headers = {};
22
- const req = {
23
- headers,
24
- get: (key) => headers[key]
25
- };
26
-
27
- Response = {
28
- location: () => { },
29
- req
30
- };
31
- core.depHooks.resolve.yields(Response);
32
-
33
- require('./unvalidated-redirect')(core).install();
34
- });
35
-
36
- it('skips instrumentation if there is no assess store', function () {
37
- Response.location('hello');
38
- expect(reportFindings).to.not.have.been.called;
39
- });
40
-
41
- it('skips instrumentation if url does not exist', function () {
42
- simulateRequestScope(function () {
43
- Response.location();
44
- expect(reportFindings).to.not.have.been.called;
45
- });
46
- });
47
-
48
- it('skip instrumentation if url is not string', function () {
49
- simulateRequestScope(function () {
50
- Response.location(1, 2);
51
- expect(reportFindings).to.not.have.been.called;
52
- });
53
- });
54
-
55
- it('skips instrumentation if url is not tracked', function () {
56
- simulateRequestScope(function () {
57
- Response.location('url');
58
- expect(reportFindings).to.not.have.been.called;
59
- });
60
- });
61
-
62
- it('skips instrumentation when location in "back"', function () {
63
- simulateRequestScope(function () {
64
- const extern = trackString('back');
65
-
66
- Response.location(extern);
67
- expect(reportFindings).to.not.have.been.called;
68
- });
69
- });
70
-
71
- it('reports a "safe positive" event when safe tags overlap UNTRUSTED', function () {
72
- simulateRequestScope(function () {
73
- const value = 'https%3A%2F%2Fhello.com';
74
- const stop = value.length - 1;
75
- const extern = trackString(value, {
76
- tags: {
77
- [URL_ENCODED]: [0, stop],
78
- [UNTRUSTED]: [0, stop],
79
- },
80
- });
81
-
82
- Response.location(extern);
83
-
84
- expect(reportSafePositive).to.have.been.calledWithMatch({
85
- name: 'Express.Response.location',
86
- ruleId: 'unvalidated-redirect',
87
- safeTags: [URL_ENCODED],
88
- strInfo: {
89
- tags: { [URL_ENCODED]: [0, stop], [UNTRUSTED]: [0, stop] },
90
- value
91
- },
92
- });
93
- });
94
- });
95
-
96
- it('reports an unvalidated-redirect', function () {
97
- simulateRequestScope(function () {
98
- const value = 'https://hello.com';
99
- const extern = trackString(value, {
100
- tags: {
101
- [URL_ENCODED]: [0, 2],
102
- [UNTRUSTED]: [0, 16],
103
- },
104
- });
105
-
106
- Response.location(extern);
107
- expect(reportFindings).to.have.been.calledWithMatch({
108
- ruleId: 'unvalidated-redirect',
109
- sinkEvent: {
110
- args: [{ value, tracked: true }],
111
- context: 'response.location(\'https://hello.com\')',
112
- name: 'Express.Response.location',
113
- moduleName: 'express',
114
- methodName: 'Response.location',
115
- object: {
116
- value: 'Express.Response',
117
- tracked: false,
118
- },
119
- result: { value: undefined, tracked: false },
120
- source: 'P0',
121
- tags: {
122
- [UNTRUSTED]: [0, 16],
123
- [URL_ENCODED]: [0, 2],
124
- },
125
- },
126
- });
127
- });
128
- });
129
-
130
- it('does not report an unvalidated-redirect if the tainted data is not in the URI path', function () {
131
- simulateRequestScope(function () {
132
- const value = 'https://hello.com/query?test=value';
133
- const extern = trackString(value, {
134
- tags: {
135
- [URL_ENCODED]: [0, 2],
136
- [UNTRUSTED]: [24, 33],
137
- },
138
- });
139
-
140
- Response.location(extern);
141
- expect(reportFindings).to.not.have.been.called;
142
- });
143
- });
144
- });
@@ -1,32 +0,0 @@
1
- 'use strict';
2
-
3
- const { expect } = require('chai');
4
- const proxyquire = require('proxyquire');
5
- const sinon = require('sinon');
6
- const mocks = require('@contrast/test/mocks');
7
-
8
- const MODULES = ['unvalidatedRedirect'];
9
-
10
- describe('assess dataflow sinks fastify', function () {
11
- let core, fastify;
12
-
13
- beforeEach(function () {
14
- core = mocks.core();
15
- core.assess = { dataflow: { sinks: {} } };
16
-
17
- const moduleMock = (name) => (deps) => {
18
- deps.assess.dataflow.sinks.fastify[name] = { install: sinon.stub() };
19
- };
20
-
21
- fastify = proxyquire('.', {
22
- './unvalidated-redirect': moduleMock('unvalidatedRedirect'),
23
- })(core);
24
- });
25
-
26
- it('installs its components', function () {
27
- fastify.install();
28
- MODULES.forEach((module) => {
29
- expect(fastify[module].install).to.have.been.calledOnce;
30
- });
31
- });
32
- });
@@ -1,130 +0,0 @@
1
- 'use strict';
2
-
3
- const { expect } = require('chai');
4
- const sinon = require('sinon');
5
- const {
6
- DataflowTag: {
7
- UNTRUSTED,
8
- URL_ENCODED,
9
- }
10
- } = require('@contrast/common');
11
- const { initAssessFixture } = require('@contrast/test/fixtures');
12
-
13
- const ruleId = 'unvalidated-redirect';
14
-
15
- describe('assess dataflow sinks fastify unvalidated-redirect', function () {
16
- let core, simulateRequestScope, trackString, tracker, reportFindings, reportSafePositive;
17
-
18
- class Reply {
19
- redirect() { }
20
- }
21
-
22
- beforeEach(function () {
23
- ({ core, simulateRequestScope, trackString } = initAssessFixture());
24
- tracker = core.assess.dataflow.tracker;
25
- reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
26
- reportSafePositive = sinon.stub(core.assess.dataflow.sinks, 'reportSafePositive');
27
-
28
- core.depHooks.resolve.yields(Reply);
29
-
30
- require('./unvalidated-redirect')(core).install();
31
- });
32
-
33
- it('skips instrumentation if there is no assess store', function () {
34
- Reply.prototype.redirect('hello');
35
- expect(reportFindings).to.not.have.been.called;
36
- });
37
-
38
- it('skips instrumentation if url does not exist', function () {
39
- simulateRequestScope(function () {
40
- Reply.prototype.redirect();
41
- expect(reportFindings).to.not.have.been.called;
42
- });
43
- });
44
-
45
- it('skip sinstrumentation if url is not string', function () {
46
- simulateRequestScope(function () {
47
- Reply.prototype.redirect(1, 2);
48
- expect(reportFindings).to.not.have.been.called;
49
- });
50
- });
51
-
52
- it('skips instrumentation if url is not tracked', function () {
53
- simulateRequestScope(function () {
54
- Reply.prototype.redirect('url');
55
- expect(reportFindings).to.not.have.been.called;
56
- });
57
- });
58
-
59
- it('reports a "safe positive" event when safe tags overlap UNTRUSTED', function () {
60
- simulateRequestScope(function () {
61
- const value = 'https%3A%2F%2Fhello.com';
62
- const stop = value.length - 1;
63
- const extern = trackString(value, {
64
- tags: {
65
- [URL_ENCODED]: [0, stop],
66
- [UNTRUSTED]: [0, stop],
67
- },
68
- });
69
-
70
- Reply.prototype.redirect(extern);
71
-
72
- expect(reportSafePositive).to.have.been.calledWithMatch({
73
- name: 'fastify.Reply.prototype.redirect',
74
- ruleId,
75
- safeTags: [URL_ENCODED],
76
- strInfo: {
77
- tags: { [URL_ENCODED]: [0, stop], [UNTRUSTED]: [0, stop] },
78
- value
79
- },
80
- });
81
- });
82
- });
83
-
84
- it('reports an unvalidated-redirect', function () {
85
- simulateRequestScope(function () {
86
- const value = 'https://hello.com';
87
- const extern = trackString(value, {
88
- tags: {
89
- [URL_ENCODED]: [0, 2],
90
- [UNTRUSTED]: [0, 16],
91
- },
92
- });
93
-
94
- Reply.prototype.redirect(extern);
95
- expect(reportFindings).to.have.been.calledWithMatch({
96
- ruleId,
97
- sinkEvent: {
98
- args: [{ value, tracked: true }],
99
- context: 'reply.redirect(\'https://hello.com\')',
100
- name: 'fastify.Reply.prototype.redirect',
101
- moduleName: 'fastify',
102
- methodName: 'reply.redirect',
103
- object: {
104
- value: 'fastify.Reply',
105
- tracked: false,
106
- },
107
- result: { value: undefined, tracked: false },
108
- source: 'P0',
109
- tags: { [URL_ENCODED]: [0, 2], [UNTRUSTED]: [0, 16] },
110
- },
111
- });
112
- });
113
- });
114
-
115
- it('does not report an unvalidated-redirect if the tainted data is not in the URI path', function () {
116
- simulateRequestScope(function () {
117
- const url = 'https://hello.com/query?test=value';
118
- const str = trackString(url, {
119
- tags: {
120
- [URL_ENCODED]: [0, 2],
121
- [UNTRUSTED]: [24, 33],
122
- },
123
- });
124
- const { extern } = tracker.getData(str);
125
-
126
- Reply.prototype.redirect(extern);
127
- expect(reportFindings).to.not.have.been.called;
128
- });
129
- });
130
- });
@@ -1,138 +0,0 @@
1
- 'use strict';
2
-
3
- const sinon = require('sinon');
4
- const { expect } = require('chai');
5
- const { FS_METHODS, primordials: { ArrayPrototypeJoin, UtilInspect } } = require('@contrast/common');
6
- const { initAssessFixture } = require('@contrast/test/fixtures');
7
-
8
- describe('assess dataflow sinks path-traversal', function () {
9
- let fs,
10
- fsPromises,
11
- core,
12
- simulateRequestScope,
13
- trackString,
14
- reportFindings;
15
-
16
- beforeEach(function () {
17
- fs = {
18
- promises: {},
19
- };
20
- fsPromises = {};
21
-
22
- for (const { name, promises, sync } of FS_METHODS) {
23
- fs[name] = sinon.stub();
24
- if (sync) {
25
- fs[`${name}Sync`] = sinon.stub();
26
- }
27
- if (promises) {
28
- fsPromises[name] = sinon.stub();
29
- fs.promises[name] = sinon.stub();
30
- }
31
- }
32
-
33
- ({ core, simulateRequestScope, trackString } = initAssessFixture());
34
- reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
35
-
36
- core.depHooks.resolve.withArgs(sinon.match({ name: 'fs' })).yields(fs);
37
- core.depHooks.resolve.withArgs(sinon.match({ name: 'fs/promises' })).yields(fsPromises);
38
-
39
- require('./fs')(core).install();
40
- });
41
-
42
- it('skips instrumentation if assess store is missing', function () {
43
- fs.readFile('.../.../path');
44
- expect(reportFindings).not.to.have.been.called;
45
- });
46
-
47
- it('skips instrumentation if a value is not provided ', function () {
48
- simulateRequestScope(function () {
49
- fs.readFile();
50
- expect(reportFindings).not.to.have.been.called;
51
- });
52
- });
53
-
54
- it('skips instrumentation if the value is not a string', function () {
55
- simulateRequestScope(function () {
56
- fs.readFile([]);
57
- expect(reportFindings).not.to.have.been.called;
58
- });
59
- });
60
-
61
- it('skips instrumentation if the value is not tracked', function () {
62
- simulateRequestScope(function () {
63
- fs.readFile('.../.../path');
64
- expect(reportFindings).not.to.have.been.called;
65
- });
66
- });
67
-
68
- for (const { name, promises, sync, indices } of FS_METHODS) {
69
- const methodsUnderTest = [
70
- { name: `fs.${name}`, getFn: () => fs[name], methodName: name },
71
- ];
72
- if (sync) {
73
- methodsUnderTest.push({
74
- name: `fs.${name}Sync`,
75
- getFn: () => fs[`${name}Sync`],
76
- methodName: `${name}Sync`,
77
- });
78
- }
79
- if (promises) {
80
- methodsUnderTest.push({
81
- name: `fsPromises.${name}`,
82
- getFn: () => fsPromises[name],
83
- moduleName: 'fsPromises',
84
- methodName: name,
85
- });
86
- methodsUnderTest.push({
87
- name: `fs.promises.${name}`,
88
- getFn: () => fs.promises[name],
89
- moduleName: 'fs.promises',
90
- methodName: name,
91
- });
92
- }
93
-
94
- for (const { name, getFn, methodName, moduleName = 'fs' } of methodsUnderTest) {
95
- describe(name, function () {
96
- it('reports path-traversal', function () {
97
- simulateRequestScope(function () {
98
- const path = trackString('.../.../path', {
99
- tags: {
100
- UNTRUSTED: [0, 11],
101
- },
102
- });
103
-
104
- const method = getFn();
105
- const methodArgs =
106
- indices.length === 2 ? [path, path] : [path];
107
- method(...methodArgs);
108
-
109
- for (const idx of indices) {
110
- expect(reportFindings).to.have.been.calledWithMatch({
111
- ruleId: 'path-traversal',
112
- sinkEvent: {
113
- name,
114
- moduleName,
115
- methodName,
116
- context: `${name}(${ArrayPrototypeJoin.call(
117
- methodArgs.map((a) => UtilInspect(a)),
118
- ', '
119
- )})`,
120
- object: {
121
- value: 'fs',
122
- tracked: false,
123
- },
124
- args: methodArgs.map((value) => ({
125
- value,
126
- tracked: true,
127
- })),
128
- tags: { UNTRUSTED: [0, 11] },
129
- source: `P${idx}`,
130
- },
131
- });
132
- }
133
- });
134
- });
135
- });
136
- }
137
- }
138
- });
@@ -1,103 +0,0 @@
1
- 'use strict';
2
-
3
- const {
4
- DataflowTag: { UNTRUSTED, CUSTOM_VALIDATED },
5
- Rule: { UNSAFE_CODE_EXECUTION },
6
- } = require('@contrast/common');
7
- const sinon = require('sinon');
8
- const { expect } = require('chai');
9
- const { initAssessFixture } = require('@contrast/test/fixtures');
10
-
11
- describe('assess dataflow sinks function', function () {
12
- let core,
13
- simulateRequestScope,
14
- trackString,
15
- reportFindings,
16
- reportSafePositive;
17
-
18
- beforeEach(function () {
19
- ({ core, simulateRequestScope, trackString } = initAssessFixture());
20
- reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
21
- reportSafePositive = sinon.stub(
22
- core.assess.dataflow.sinks,
23
- 'reportSafePositive'
24
- );
25
- core.contrastMethods.install();
26
-
27
- require('./function')(core).install();
28
- });
29
-
30
- it('skips instrumentation if assess store is missing', function () {
31
- global.ContrastMethods.Function('test');
32
-
33
- expect(reportFindings).not.to.have.been.called;
34
- });
35
-
36
- it('skips instrumentation if a value is not provided ', function () {
37
- simulateRequestScope(function () {
38
- global.ContrastMethods.Function();
39
-
40
- expect(reportFindings).not.to.have.been.called;
41
- });
42
- });
43
-
44
- it('skips instrumentation if the argument is not a tracked', function () {
45
- simulateRequestScope(function () {
46
- global.ContrastMethods.Function('not-tracked');
47
-
48
- expect(reportFindings).not.to.have.been.called;
49
- });
50
- });
51
-
52
- it('skips instrumentation if the argument is sanitized', function () {
53
- simulateRequestScope(function () {
54
- const value = 'test';
55
- const extern = trackString('test', {
56
- tags: {
57
- [UNTRUSTED]: [0, 3],
58
- [CUSTOM_VALIDATED]: [0, 3],
59
- },
60
- });
61
-
62
- global.ContrastMethods.Function(extern);
63
-
64
- expect(reportFindings).not.to.have.been.called;
65
- expect(reportSafePositive).to.have.been.calledWith({
66
- name: 'global.ContrastMethods.Function',
67
- ruleId: UNSAFE_CODE_EXECUTION,
68
- safeTags: [CUSTOM_VALIDATED],
69
- strInfo: {
70
- value,
71
- tags: { [UNTRUSTED]: [0, 3], CUSTOM_VALIDATED: [0, 3] },
72
- },
73
- });
74
- });
75
- });
76
-
77
- it('reports an unsafe-code-execution', function () {
78
- simulateRequestScope(function () {
79
- const value = 'test';
80
- const extern = trackString('test', {
81
- tags: {
82
- [UNTRUSTED]: [0, 3],
83
- },
84
- });
85
-
86
- global.ContrastMethods.Function(extern);
87
-
88
- expect(reportFindings).to.have.been.calledWithMatch({
89
- ruleId: UNSAFE_CODE_EXECUTION,
90
- sinkEvent: {
91
- args: [{ value, tracked: true }],
92
- context: "global.ContrastMethods.Function('test')",
93
- name: 'global.ContrastMethods.Function',
94
- moduleName: 'global.ContrastMethods',
95
- methodName: 'Function',
96
- object: { value: 'global.ContrastMethods', tracked: false },
97
- source: 'P0',
98
- tags: { [UNTRUSTED]: [0, 3] },
99
- },
100
- });
101
- });
102
- });
103
- });
@@ -1,32 +0,0 @@
1
- 'use strict';
2
-
3
- const { expect } = require('chai');
4
- const proxyquire = require('proxyquire');
5
- const sinon = require('sinon');
6
- const mocks = require('@contrast/test/mocks');
7
-
8
- const MODULES = ['unvalidatedRedirect'];
9
-
10
- describe('assess dataflow sinks hapi', function () {
11
- let core, hapi;
12
-
13
- beforeEach(function () {
14
- core = mocks.core();
15
- core.assess = { dataflow: { sinks: {} } };
16
-
17
- const moduleMock = (name) => (deps) => {
18
- deps.assess.dataflow.sinks.hapi[name] = { install: sinon.stub() };
19
- };
20
-
21
- hapi = proxyquire('.', {
22
- './unvalidated-redirect': moduleMock('unvalidatedRedirect'),
23
- })(core);
24
- });
25
-
26
- it('installs its components', function () {
27
- hapi.install();
28
- MODULES.forEach((module) => {
29
- expect(hapi[module].install).to.have.been.calledOnce;
30
- });
31
- });
32
- });