@contrast/protect 1.50.0 → 1.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,47 +15,12 @@
|
|
|
15
15
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
|
-
const
|
|
19
|
-
const semver = require('semver');
|
|
18
|
+
const { Domain } = require('async-hook-domain');
|
|
20
19
|
|
|
21
20
|
module.exports = function(core) {
|
|
22
|
-
const {
|
|
23
|
-
logger,
|
|
24
|
-
protect: { errorHandlers }
|
|
25
|
-
} = core;
|
|
21
|
+
const { protect: { errorHandlers } } = core;
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return errorHandlers.initDomain = function(req, res) {
|
|
30
|
-
const { AsyncHookDomain, Domain } = errorHandlers;
|
|
31
|
-
|
|
32
|
-
if (AsyncHookDomain) {
|
|
33
|
-
new AsyncHookDomain(errorHandlers.commonHandler);
|
|
34
|
-
} else {
|
|
35
|
-
const domain = new Domain();
|
|
36
|
-
domain.add(req);
|
|
37
|
-
domain.add(res);
|
|
38
|
-
domain.on('error', errorHandlers.commonHandler);
|
|
39
|
-
return domain;
|
|
40
|
-
}
|
|
23
|
+
return errorHandlers.initDomain = function initDomain() {
|
|
24
|
+
return new Domain(errorHandlers.commonHandler);
|
|
41
25
|
};
|
|
42
|
-
|
|
43
|
-
function initSupportedDomainPackage() {
|
|
44
|
-
let AsyncHookDomain, Domain;
|
|
45
|
-
|
|
46
|
-
if (semver.lt(process.version, '16.0.0')) {
|
|
47
|
-
logger.info(
|
|
48
|
-
'%s. %s. %s.',
|
|
49
|
-
'falling back to deprecated \'domain\' module for async SecurityException handling',
|
|
50
|
-
'upgrade to Node 16 LTS or above to allow use of \'async-hook-domain\' modern alternative',
|
|
51
|
-
'upgrading will resolve any deprecation warnings and prevent the logging of this message'
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
Domain = require('domain').Domain;
|
|
55
|
-
} else {
|
|
56
|
-
AsyncHookDomain = require('async-hook-domain');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return { AsyncHookDomain, Domain };
|
|
60
|
-
}
|
|
61
26
|
};
|
|
@@ -5,30 +5,18 @@ const sinon = require('sinon');
|
|
|
5
5
|
const { initProtectFixture } = require('@contrast/test/fixtures');
|
|
6
6
|
|
|
7
7
|
describe('protect error-handlers init-domain', function () {
|
|
8
|
-
let core
|
|
8
|
+
let core;
|
|
9
9
|
|
|
10
10
|
beforeEach(function () {
|
|
11
11
|
({ core } = initProtectFixture());
|
|
12
12
|
|
|
13
13
|
sinon.stub(core.protect.errorHandlers, 'commonHandler');
|
|
14
|
-
|
|
15
|
-
errorHandlers = core.protect.errorHandlers;
|
|
16
|
-
initDomain = errorHandlers.initDomain;
|
|
17
14
|
});
|
|
18
15
|
|
|
19
16
|
describe('domain integration', function () {
|
|
20
|
-
beforeEach(function () {
|
|
21
|
-
sinon.stub(errorHandlers, 'AsyncHookDomain');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('initializes correct domain', function () {
|
|
25
|
-
expect(core.protect.errorHandlers.AsyncHookDomain).to.be.a('function');
|
|
26
|
-
expect(core.protect.errorHandlers.Domain).to.be.undefined;
|
|
27
|
-
});
|
|
28
|
-
|
|
29
17
|
it('instantiates async-hook-domain with common error handler', function () {
|
|
30
|
-
initDomain();
|
|
31
|
-
expect(
|
|
18
|
+
const d = core.protect.errorHandlers.initDomain();
|
|
19
|
+
expect(d.onerror).to.equal(core.protect.errorHandlers.commonHandler);
|
|
32
20
|
});
|
|
33
21
|
});
|
|
34
22
|
});
|
package/lib/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { ReqData, ProtectMessage, ResultMap, ProtectRuleMode } from '@contrast/c
|
|
|
17
17
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
18
18
|
import * as http from 'node:http';
|
|
19
19
|
import * as https from 'node:https';
|
|
20
|
-
import { Domain } from 'domain';
|
|
20
|
+
import { Domain } from 'async-hook-domain';
|
|
21
21
|
|
|
22
22
|
type Http = typeof http;
|
|
23
23
|
type Https = typeof https;
|
|
@@ -114,7 +114,7 @@ export interface Protect {
|
|
|
114
114
|
}
|
|
115
115
|
errorHandlers: {
|
|
116
116
|
commonHandler: (err: Error) => void;
|
|
117
|
-
initDomain: () =>
|
|
117
|
+
initDomain: () => Domain;
|
|
118
118
|
fastify3ErrorHandler: {
|
|
119
119
|
_userHandler: null | ((...args: any[]) => any),
|
|
120
120
|
defaultErrorHandler: (error: Error, request: IncomingMessage, reply: ServerResponse) => void,
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
|
+
const onFinished = require('on-finished');
|
|
18
19
|
const { Event, primordials: { StringPrototypeToLowerCase, ArrayPrototypeSlice } } = require('@contrast/common');
|
|
19
20
|
const { patchType } = require('../constants');
|
|
20
21
|
|
|
@@ -51,15 +52,8 @@ module.exports = function (core) {
|
|
|
51
52
|
|
|
52
53
|
function callNext() {
|
|
53
54
|
setImmediate(() => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (domain) {
|
|
57
|
-
domain.run(() => {
|
|
58
|
-
next.call(data.obj, ...data.args);
|
|
59
|
-
});
|
|
60
|
-
} else {
|
|
61
|
-
next.call(data.obj, ...data.args);
|
|
62
|
-
}
|
|
55
|
+
initDomain();
|
|
56
|
+
next.call(data.obj, ...data.args);
|
|
63
57
|
});
|
|
64
58
|
}
|
|
65
59
|
|
|
@@ -85,7 +79,7 @@ module.exports = function (core) {
|
|
|
85
79
|
resData,
|
|
86
80
|
} = store.protect;
|
|
87
81
|
|
|
88
|
-
res
|
|
82
|
+
onFinished(res, (/* err, req */) => {
|
|
89
83
|
resData.statusCode = res.statusCode;
|
|
90
84
|
inputAnalysis.handleRequestEnd(store.protect);
|
|
91
85
|
messages.emit(Event.PROTECT, store);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/protect",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.52.0",
|
|
4
4
|
"description": "Contrast service providing framework-agnostic Protect support",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
|
|
@@ -18,20 +18,19 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@contrast/agent-lib": "^7.0.1",
|
|
21
|
-
"@contrast/common": "1.
|
|
22
|
-
"@contrast/config": "1.
|
|
23
|
-
"@contrast/core": "1.
|
|
24
|
-
"@contrast/dep-hooks": "1.
|
|
25
|
-
"@contrast/esm-hooks": "2.
|
|
26
|
-
"@contrast/instrumentation": "1.
|
|
27
|
-
"@contrast/logger": "1.
|
|
28
|
-
"@contrast/patcher": "1.
|
|
29
|
-
"@contrast/rewriter": "1.
|
|
30
|
-
"@contrast/scopes": "1.
|
|
21
|
+
"@contrast/common": "1.29.0",
|
|
22
|
+
"@contrast/config": "1.39.0",
|
|
23
|
+
"@contrast/core": "1.44.0",
|
|
24
|
+
"@contrast/dep-hooks": "1.13.0",
|
|
25
|
+
"@contrast/esm-hooks": "2.18.0",
|
|
26
|
+
"@contrast/instrumentation": "1.23.0",
|
|
27
|
+
"@contrast/logger": "1.17.0",
|
|
28
|
+
"@contrast/patcher": "1.16.0",
|
|
29
|
+
"@contrast/rewriter": "1.20.0",
|
|
30
|
+
"@contrast/scopes": "1.14.0",
|
|
31
|
+
"async-hook-domain": "^4.0.1",
|
|
31
32
|
"ipaddr.js": "^2.0.1",
|
|
33
|
+
"on-finished": "^2.4.1",
|
|
32
34
|
"semver": "^7.6.0"
|
|
33
|
-
},
|
|
34
|
-
"optionalDependencies": {
|
|
35
|
-
"async-hook-domain": "^3.0.2"
|
|
36
35
|
}
|
|
37
36
|
}
|