@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,74 +0,0 @@
1
- 'use strict';
2
-
3
- const { expect } = require('chai');
4
- const sinon = require('sinon');
5
- const {
6
- DataflowTag: { UNTRUSTED, SQL_ENCODED }
7
- } = require('@contrast/common');
8
- const { initAssessFixture } = require('@contrast/test/fixtures');
9
-
10
- describe('assess dataflow propagation sequelize QueryGenerators', function() {
11
- let core, component, trackString, simulateRequestScope, tracker;
12
-
13
- class QueryGeneratorMock {
14
- quoteIdentifier(identifier) {
15
- return '`'.concat(identifier).concat('`');
16
- }
17
- }
18
-
19
- before(function() {
20
- ({ core, trackString, simulateRequestScope } = initAssessFixture());
21
- tracker = core.assess.dataflow.tracker;
22
- core.assess.dataflow.propagation.stringInstrumentation.concat.install();
23
- component = require('./query-generator')(core);
24
- });
25
-
26
- after(function() {
27
- core.assess.dataflow.propagation.stringInstrumentation.concat.uninstall();
28
- });
29
-
30
- [
31
- {
32
- Ctor: class MSSQLQueryGenerator extends QueryGeneratorMock {},
33
- file: 'lib/dialects/mssql/query-generator.js',
34
- },
35
- {
36
- Ctor: class MySqlQueryGenerator extends QueryGeneratorMock {},
37
- file: 'lib/dialects/mysql/query-generator.js',
38
- },
39
- {
40
- Ctor: class PostgresQueryGenerator extends QueryGeneratorMock {},
41
- file: 'lib/dialects/postgres/query-generator.js',
42
- },
43
- {
44
- Ctor: class SQLiteQueryGenerator extends QueryGeneratorMock {},
45
- file: 'lib/dialects/sqlite/query-generator.js',
46
- },
47
- ].forEach(({ Ctor, file }) => {
48
- it(`${Ctor.name}.prototype.quoteIdentifier adds sql-encoded tag`, function() {
49
- core.depHooks.resolve.withArgs(sinon.match({ name: 'sequelize', file })).yields(Ctor);
50
- component.install();
51
-
52
- simulateRequestScope(() => {
53
- const tracked = trackString('foo');
54
- const result = new Ctor().quoteIdentifier(tracked);
55
- const strInfo = tracker.getData(result);
56
-
57
- expect(strInfo).to.deep.include({
58
- args: [{ tracked: true, value: 'foo' }],
59
- moduleName: 'sequelize',
60
- methodName: `${Ctor.name}.prototype.quoteIdentifier`,
61
- object: { tracked: false, value: Ctor.name },
62
- result: { tracked: true, value: '`foo`' },
63
- source: 'P',
64
- tags: {
65
- [UNTRUSTED]: [1, 3],
66
- [SQL_ENCODED]: [0, 4],
67
- },
68
- target: 'R',
69
- });
70
- expect(strInfo.history).to.have.lengthOf(1);
71
- });
72
- });
73
- });
74
- });
@@ -1,119 +0,0 @@
1
- 'use strict';
2
-
3
- const { expect } = require('chai');
4
- const sinon = require('sinon');
5
- const {
6
- DataflowTag: { SQL_ENCODED, UNTRUSTED },
7
- } = require('@contrast/common');
8
- const { initAssessFixture } = require('@contrast/test/fixtures');
9
-
10
- describe('assess dataflow propagation sequelize sql-string', function () {
11
- let core, trackString, simulateRequestScope, tracker, mockSequelizeSqlString;
12
-
13
- beforeEach(function () {
14
- ({
15
- core,
16
- simulateRequestScope,
17
- trackString
18
- } = initAssessFixture());
19
-
20
- mockSequelizeSqlString = {
21
- escape: (str) => str,
22
- format(str, repl) {
23
- repl.forEach((r) => {
24
- str = str.replace(/\?/, r);
25
- });
26
-
27
- return str;
28
- },
29
- formatNamedParameters(str, repl) {
30
- Object.keys(repl).forEach((key) => {
31
- str = str.replace(new RegExp(`:${key}`), repl[key]);
32
- });
33
-
34
- return str;
35
- }
36
- };
37
- tracker = core.assess.dataflow.tracker;
38
- core.assess.dataflow.propagation.stringInstrumentation.install();
39
- core.assess.dataflow.propagation.sequelizeInstrumentation.install();
40
- core.depHooks.resolve.yield(mockSequelizeSqlString);
41
- });
42
-
43
- afterEach(function () {
44
- core.assess.dataflow.propagation.stringInstrumentation.uninstall();
45
- sinon.resetHistory();
46
- });
47
-
48
- [
49
- {
50
- method: 'escape',
51
- args: [() => trackString('inserted-value')],
52
- notTrackedArgs: ['safe-value'],
53
- expectedTags: {
54
- [UNTRUSTED]: [0, 13],
55
- [SQL_ENCODED]: [0, 13]
56
- }
57
- },
58
- {
59
- method: 'format',
60
- args: [() => 'SELECT ? FROM ?', () => ['id', trackString('users')]],
61
- notTrackedArgs: ['SELECT ? FROM ?', ['id', 'users']],
62
- expectedTags: {
63
- [UNTRUSTED]: [15, 19],
64
- [SQL_ENCODED]: [15, 19]
65
- }
66
- },
67
- {
68
- onlySanitizeCheck: true,
69
- method: 'format',
70
- args: [() => trackString('SELECT password FROM users'), () => ['id', trackString('users')]],
71
- notTrackedArgs: ['SELECT ? FROM ?', ['id', 'users']],
72
- expectedTags: {
73
- [UNTRUSTED]: [0, 25],
74
- }
75
- },
76
- {
77
- method: 'formatNamedParameters',
78
- args: [() => 'SELECT :columns FROM :table', () => ({ columns: 'id', table: trackString('users') })],
79
- notTrackedArgs: ['SELECT :columns FROM :table', { columns: 'id', table: 'users' }],
80
- expectedTags: {
81
- [UNTRUSTED]: [15, 19],
82
- [SQL_ENCODED]: [15, 19]
83
- }
84
- },
85
- {
86
- onlySanitizeCheck: true,
87
- method: 'formatNamedParameters',
88
- args: [() => trackString('SELECT password FROM users'), () => ({ columns: 'id', table: trackString('users') })],
89
- notTrackedArgs: ['SELECT ? FROM ?', ['id', 'users']],
90
- expectedTags: {
91
- [UNTRUSTED]: [0, 25],
92
- }
93
- },
94
- ].forEach(({ onlySanitizeCheck, method, args, notTrackedArgs, expectedTags }) => {
95
- describe(method, function () {
96
- it('sanitizes correctly', function () {
97
- simulateRequestScope(function () {
98
- const notTrackedResult = mockSequelizeSqlString[method](...notTrackedArgs);
99
- const notTrackedStrInfo = tracker.getData(notTrackedResult);
100
-
101
- const trackedResult = mockSequelizeSqlString[method](...args.map(a => a()));
102
- const trackedStrInfo = tracker.getData(trackedResult);
103
-
104
- expect(notTrackedStrInfo).to.be.null;
105
- expect(trackedStrInfo?.tags).to.deep.equal(expectedTags);
106
- });
107
- });
108
-
109
- if (!onlySanitizeCheck) {
110
- it('will not sanitize if there is no assess policy in request context', function () {
111
- simulateRequestScope(function () {
112
- const result = mockSequelizeSqlString[method](...args.map(a => a()));
113
- expect(tracker.getData(result)).to.be.null;
114
- }, { assess: { policy: null } });
115
- });
116
- }
117
- });
118
- });
119
- });
@@ -1,100 +0,0 @@
1
- 'use strict';
2
-
3
- const { expect } = require('chai');
4
- const sinon = require('sinon');
5
- const {
6
- DataflowTag: { UNTRUSTED, SQL_ENCODED }
7
- } = require('@contrast/common');
8
- const { initAssessFixture } = require('@contrast/test/fixtures');
9
-
10
- // TODO: The proper usage of the method is with a template string so
11
- // meaningful tests can be written after we add support for them (NODE-2826);
12
- describe('assess dataflow propagation sql-template-strings', function () {
13
- let core, trackString, simulateRequestScope, tracker, mockSqlTemplateStrings;
14
-
15
- beforeEach(function () {
16
- ({
17
- core,
18
- simulateRequestScope,
19
- trackString
20
- } = initAssessFixture());
21
-
22
- mockSqlTemplateStrings = {
23
- // SQL: (str) => ['mock-template-strings', str, 'mock-template-strings'].join('')
24
- SQL: (str) => {
25
- const ret = {
26
- strings: [],
27
- values: []
28
- };
29
- const valueLength = 'inserted-value'.length;
30
- let idx = str.indexOf('inserted-value');
31
- let newStr = str;
32
- while (idx >= 0) {
33
- ret.strings.push(newStr.substring(0, idx));
34
- ret.values.push(newStr.substring(idx, idx + valueLength));
35
-
36
- newStr = newStr.substring(idx + valueLength);
37
- idx = newStr.indexOf('inserted-value');
38
- }
39
-
40
- if (newStr) ret.strings.push(newStr);
41
-
42
- return ret;
43
- }
44
- };
45
-
46
- tracker = core.assess.dataflow.tracker;
47
- core.assess.dataflow.propagation.stringInstrumentation.install();
48
- core.assess.dataflow.propagation.arrayJoin.install();
49
- core.assess.dataflow.propagation.sqlTemplateStrings.install();
50
- core.depHooks.resolve.yield(mockSqlTemplateStrings);
51
- });
52
-
53
- afterEach(function () {
54
- sinon.resetHistory();
55
- });
56
-
57
- it('propagates correctly', function () {
58
- simulateRequestScope(function () {
59
- const trackedValue = trackString('inserted-value', { tags: { [UNTRUSTED]: [9, 13] } });
60
- const trackedContext = trackString('tracked-context', { tags: { [UNTRUSTED]: [0, 13] } });
61
-
62
- const notTrackedResult = mockSqlTemplateStrings.SQL('foo-inserted-value-bar-baz-inserted-value');
63
- const notTrackedStrInfoStrings = tracker.getData(notTrackedResult.strings.toString());
64
- const notTrackedStrInfoValues = tracker.getData(notTrackedResult.values.toString());
65
-
66
- const trackedResult = mockSqlTemplateStrings.SQL([trackedContext, 'foo', trackedValue, 'bar', trackedValue].join('-'));
67
- const trackedStrInfoStrings = tracker.getData(trackedResult.strings.toString());
68
- const trackedStrInfoValues = tracker.getData(trackedResult.values.toString());
69
-
70
- expect(notTrackedStrInfoStrings).to.be.null;
71
- expect(notTrackedStrInfoValues).to.be.null;
72
- expect(trackedStrInfoStrings?.tags).to.deep.equal({
73
- [UNTRUSTED]: [0, 13],
74
- [SQL_ENCODED]: [0, 19],
75
- }); // the string is 'tracked-context-foo-,-bar-'
76
- expect(trackedStrInfoValues?.tags).to.deep.equal({
77
- [UNTRUSTED]: [9, 13, 24, 28],
78
- [SQL_ENCODED]: [0, 13, 15, 28]
79
- }); // the string is 'inserted-value,inserted-value'
80
- });
81
- });
82
-
83
- it('will not propagate if there is no assess policy in request context', function () {
84
- simulateRequestScope(function () {
85
- const value = trackString('foo');
86
- const result = mockSqlTemplateStrings.SQL(['foo', value].join());
87
- expect(tracker.getData(result.strings.toString())).to.be.null;
88
- }, { assess: { policy: null } });
89
- });
90
-
91
- it('will not propagate if there instrumentation is locked', function () {
92
- simulateRequestScope(function () {
93
- core.scopes.instrumentation.run({ lock: true }, function () {
94
- const value = trackString('foo');
95
- const result = mockSqlTemplateStrings.SQL(['foo', value].join());
96
- expect(tracker.getData(result.strings.toString())).to.be.null;
97
- });
98
- });
99
- });
100
- });
@@ -1,145 +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 string concat', function () {
8
- let core, trackString, simulateRequestScope, tracker;
9
- const allPatcher = new Map();
10
-
11
- beforeEach(function () {
12
- ({
13
- core,
14
- simulateRequestScope,
15
- trackString
16
- } = initAssessFixture());
17
-
18
- tracker = core.assess.dataflow.tracker;
19
- core.assess.dataflow.propagation.stringInstrumentation.concat.install();
20
- });
21
-
22
- afterEach(function () {
23
- core.assess.dataflow.propagation.stringInstrumentation.concat.uninstall();
24
- sinon.resetHistory();
25
- });
26
-
27
- // eslint-disable-next-line mocha/no-sibling-hooks
28
- afterEach(function() {
29
- core.Perf.fromAllToMap('patcher', allPatcher);
30
- });
31
-
32
- after(function() {
33
- const stats = core.Perf.getStats(allPatcher);
34
- for (const [key, { n, totalMicros, mean }] of stats.entries()) {
35
- console.log(key, n, totalMicros, 'nsec', mean, 'mean');
36
- }
37
- });
38
-
39
- [
40
- {
41
- str: 'foo',
42
- tags: {
43
- untrusted: [0, 2]
44
- },
45
- args: [() => 'bar', () => 'baz'],
46
- expected: {
47
- untrusted: [0, 2]
48
- }
49
- },
50
- {
51
- str: 'foo',
52
- tags: {
53
- untrusted: [0, 2]
54
- },
55
- args: [
56
- () => trackString('bar', { tags: { untrusted: [0, 2] } }),
57
- () => trackString('baz', { tags: { untrusted: [0, 2] } }),
58
- ],
59
- expected: {
60
- untrusted: [0, 8]
61
- }
62
- },
63
- {
64
- str: 'boo',
65
- tags: {
66
- untrusted: [0, 2]
67
- },
68
- args: [
69
- () => trackString('bar', { tags: { untrusted: [0, 2] } }),
70
- () => null,
71
- () => undefined,
72
- () => trackString('baz', { tags: { untrusted: [0, 2] } }),
73
- ],
74
- expected: {
75
- untrusted: [0, 5, 19, 21]
76
- }
77
- },
78
- {
79
- str: 'foo',
80
- tags: {
81
- untrusted: [0, 2]
82
- },
83
- args: [
84
- () => trackString('bar', { other: 'metadata', tags: undefined }),
85
- () => trackString('baz', { tags: { untrusted: [0, 2] } }),
86
- ],
87
- expected: {
88
- untrusted: [0, 2, 6, 8]
89
- }
90
- },
91
- {
92
- str: 'not-tracked',
93
- args: [
94
- () => trackString('bar', { tags: { untrusted: [0, 2] } }),
95
- () => trackString('baz', { tags: { untrusted: [0, 2] } }),
96
- ],
97
- expected: {
98
- untrusted: [11, 16]
99
- }
100
- },
101
- ].forEach(({ str, tags, args, expected = null }) => {
102
- it('concat', function () {
103
- simulateRequestScope(function () {
104
- let result;
105
- const value = str !== 'not-tracked' ? trackString(str, { tags }) : str;
106
-
107
- if (str !== 'boo') {
108
- result = value.concat(...args.map((a) => a()));
109
- } else {
110
- result = value.concat.bind('', value, ...args.map((a) => a()))();
111
- }
112
-
113
- const strInfo = tracker.getData(result);
114
- expect(strInfo?.tags).to.deep.equal(expected);
115
- });
116
- });
117
- });
118
-
119
- it('will nto "retrack" if result is unchanged', function () {
120
- simulateRequestScope(function () {
121
- const value = trackString('foo');
122
- const result = value.concat('');
123
-
124
- expect(tracker.getData(value)).to.equal(tracker.getData(result));
125
- });
126
- });
127
-
128
- it('will not propagate if there is no assess policy in request context', function () {
129
- simulateRequestScope(function () {
130
- const value = trackString('foo');
131
- const result = value.concat('bar');
132
- expect(tracker.getData(result)).to.be.null;
133
- }, { assess: { policy: null } });
134
- });
135
-
136
- it('will not propagate if there instrumentation is locked', function () {
137
- simulateRequestScope(function () {
138
- core.scopes.instrumentation.run({ lock: true }, function () {
139
- const value = trackString('foo');
140
- const result = value.concat('bar');
141
- expect(tracker.getData(result)).to.be.null;
142
- });
143
- });
144
- });
145
- });
@@ -1,74 +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 string format-methods', function () {
8
- let core, trackString, simulateRequestScope, tracker;
9
- const allPatcher = new Map();
10
-
11
- beforeEach(function () {
12
- ({
13
- core,
14
- simulateRequestScope,
15
- trackString
16
- } = initAssessFixture());
17
-
18
- tracker = core.assess.dataflow.tracker;
19
- core.assess.dataflow.propagation.stringInstrumentation.formatMethods.install();
20
- });
21
-
22
- afterEach(function () {
23
- core.assess.dataflow.propagation.stringInstrumentation.formatMethods.uninstall();
24
- sinon.resetHistory();
25
- });
26
-
27
- // eslint-disable-next-line mocha/no-sibling-hooks
28
- afterEach(function() {
29
- core.Perf.fromAllToMap('patcher', allPatcher);
30
- });
31
-
32
- after(function() {
33
- const stats = core.Perf.getStats(allPatcher);
34
- for (const [key, { n, totalMicros, mean }] of stats.entries()) {
35
- console.log(key, n, totalMicros, 'nsec', mean, 'mean');
36
- }
37
- });
38
-
39
- ['toLowerCase', 'toUpperCase', 'toLocaleLowerCase', 'toLocaleUpperCase'].forEach((method) => {
40
- it(method, function () {
41
- simulateRequestScope(function () {
42
- const notTrackedValue = 'foo';
43
- const trackedValue = trackString('foo', { tags: { untrusted: [0, 2] } });
44
-
45
- const notTrackedResult = notTrackedValue[method]();
46
- const notTrackedStrInfo = tracker.getData(notTrackedResult);
47
-
48
- const trackedResult = trackedValue[method]();
49
- const trackedStrInfo = tracker.getData(trackedResult);
50
-
51
- expect(notTrackedStrInfo).to.be.null;
52
- expect(trackedStrInfo?.tags).to.deep.equal({ untrusted: [0, 2] });
53
- });
54
- });
55
- });
56
-
57
- it('will not propagate if there is no assess policy in request context', function () {
58
- simulateRequestScope(function () {
59
- const value = trackString('foo');
60
- const result = value.toLowerCase('bar');
61
- expect(tracker.getData(result)).to.be.null;
62
- }, { assess: { policy: null } });
63
- });
64
-
65
- it('will not propagate if there instrumentation is locked', function () {
66
- simulateRequestScope(function () {
67
- core.scopes.instrumentation.run({ lock: true }, function () {
68
- const value = trackString('foo');
69
- const result = value.toLowerCase('bar');
70
- expect(tracker.getData(result)).to.be.null;
71
- });
72
- });
73
- });
74
- });
@@ -1,177 +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 string html-methods', function () {
8
- let core, trackString, simulateRequestScope, tracker;
9
- const allPatcher = new Map();
10
-
11
- beforeEach(function () {
12
- ({
13
- core,
14
- simulateRequestScope,
15
- trackString
16
- } = initAssessFixture());
17
-
18
- tracker = core.assess.dataflow.tracker;
19
- core.assess.dataflow.propagation.stringInstrumentation.htmlMethods.install();
20
- });
21
-
22
- afterEach(function () {
23
- core.assess.dataflow.propagation.stringInstrumentation.htmlMethods.uninstall();
24
- sinon.resetHistory();
25
- });
26
-
27
- // eslint-disable-next-line mocha/no-sibling-hooks
28
- afterEach(function() {
29
- core.Perf.fromAllToMap('patcher', allPatcher);
30
- });
31
-
32
- after(function() {
33
- const stats = core.Perf.getStats(allPatcher);
34
- for (const [key, { n, totalMicros, mean }] of stats.entries()) {
35
- console.log(key, n, totalMicros, 'nsec', mean, 'mean');
36
- }
37
- });
38
-
39
- [
40
- {
41
- method: 'anchor',
42
- str: 'foo',
43
- args: [() => undefined, () => 'id', () => trackString('tracked-id', { tags: { untrusted: [0, 9] } })],
44
- tags: {
45
- untrusted: [0, 2]
46
- },
47
- expected: [{ untrusted: [20, 22] }, { untrusted: [13, 15] }, { untrusted: [9, 18, 21, 23] }],
48
- },
49
- {
50
- method: 'anchor',
51
- str: 'not-tracked',
52
- args: [() => 'id', () => trackString('tracked-id', { tags: { untrusted: [0, 9] } })],
53
- expected: [undefined, { untrusted: [9, 18] }]
54
- },
55
- {
56
- method: 'big',
57
- str: 'foo',
58
- tags: {
59
- untrusted: [0, 2]
60
- },
61
- expected: { untrusted: [5, 7] }
62
- },
63
- {
64
- method: 'big',
65
- str: 'not-tracked',
66
- },
67
- {
68
- method: 'blink',
69
- str: 'foo',
70
- tags: {
71
- untrusted: [0, 2]
72
- },
73
- expected: { untrusted: [7, 9] }
74
- },
75
- {
76
- method: 'blink',
77
- str: 'not-tracked',
78
- },
79
- {
80
- method: 'italics',
81
- str: 'foo',
82
- tags: {
83
- untrusted: [0, 2]
84
- },
85
- expected: { untrusted: [3, 5] }
86
- },
87
- {
88
- method: 'italics',
89
- str: 'not-tracked',
90
- },
91
- {
92
- method: 'small',
93
- str: 'foo',
94
- tags: {
95
- untrusted: [0, 2]
96
- },
97
- expected: { untrusted: [7, 9] }
98
- },
99
- {
100
- method: 'small',
101
- str: 'not-tracked',
102
- },
103
- {
104
- method: 'strike',
105
- str: 'foo',
106
- tags: {
107
- untrusted: [0, 2]
108
- },
109
- expected: { untrusted: [8, 10] }
110
- },
111
- {
112
- method: 'strike',
113
- str: 'not-tracked',
114
- },
115
- {
116
- method: 'sub',
117
- str: 'foo',
118
- tags: {
119
- untrusted: [0, 2]
120
- },
121
- expected: { untrusted: [5, 7] }
122
- },
123
- {
124
- method: 'sub',
125
- str: 'not-tracked',
126
- },
127
- {
128
- method: 'fixed',
129
- str: 'foo',
130
- tags: {
131
- untrusted: [0, 2]
132
- },
133
- expected: { untrusted: [4, 6] }
134
- },
135
- {
136
- method: 'fixed',
137
- str: 'not-tracked',
138
- },
139
- ].forEach(({ str, tags, args, method, expected }) => {
140
- it(method, function () {
141
- simulateRequestScope(function () {
142
- const value = str !== 'not-tracked' ? trackString(str, { tags }) : str;
143
-
144
- if (args?.length) {
145
- for (let i = 0; i < args.length; i++) {
146
- const result = value[method](args[i]());
147
- const strInfo = tracker.getData(result);
148
- expect(strInfo?.tags).to.deep.equal(expected[i]);
149
- }
150
- } else {
151
- const result = value[method]();
152
- const strInfo = tracker.getData(result);
153
- expect(strInfo?.tags).to.deep.equal(expected);
154
- }
155
-
156
- });
157
- });
158
- });
159
-
160
- it('will not propagate if there is no assess policy in request context', function () {
161
- simulateRequestScope(function () {
162
- const value = trackString('foo');
163
- const result = value.anchor('bar');
164
- expect(tracker.getData(result)).to.be.null;
165
- }, { assess: { policy: null } });
166
- });
167
-
168
- it('will not propagate if there instrumentation is locked', function () {
169
- simulateRequestScope(function () {
170
- core.scopes.instrumentation.run({ lock: true }, function () {
171
- const value = trackString('foo');
172
- const result = value.anchor('bar');
173
- expect(tracker.getData(result)).to.be.null;
174
- });
175
- });
176
- });
177
- });