@contrast/protect 1.50.0 → 1.51.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 process = require('process');
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
- Object.assign(errorHandlers, initSupportedDomainPackage());
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, errorHandlers, initDomain;
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(errorHandlers.AsyncHookDomain).to.have.been.calledWith(errorHandlers.commonHandler);
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: () => void | Domain;
117
+ initDomain: () => Domain;
118
118
  fastify3ErrorHandler: {
119
119
  _userHandler: null | ((...args: any[]) => any),
120
120
  defaultErrorHandler: (error: Error, request: IncomingMessage, reply: ServerResponse) => void,
@@ -51,15 +51,8 @@ module.exports = function (core) {
51
51
 
52
52
  function callNext() {
53
53
  setImmediate(() => {
54
- const domain = initDomain(req, res);
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
- }
54
+ initDomain();
55
+ next.call(data.obj, ...data.args);
63
56
  });
64
57
  }
65
58
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/protect",
3
- "version": "1.50.0",
3
+ "version": "1.51.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,18 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@contrast/agent-lib": "^7.0.1",
21
- "@contrast/common": "1.27.0",
22
- "@contrast/config": "1.37.0",
23
- "@contrast/core": "1.42.0",
24
- "@contrast/dep-hooks": "1.11.0",
25
- "@contrast/esm-hooks": "2.16.0",
26
- "@contrast/instrumentation": "1.21.0",
27
- "@contrast/logger": "1.15.0",
28
- "@contrast/patcher": "1.14.0",
29
- "@contrast/rewriter": "1.18.0",
30
- "@contrast/scopes": "1.12.0",
21
+ "@contrast/common": "1.28.0",
22
+ "@contrast/config": "1.38.0",
23
+ "@contrast/core": "1.43.0",
24
+ "@contrast/dep-hooks": "1.12.0",
25
+ "@contrast/esm-hooks": "2.17.0",
26
+ "@contrast/instrumentation": "1.22.0",
27
+ "@contrast/logger": "1.16.0",
28
+ "@contrast/patcher": "1.15.0",
29
+ "@contrast/rewriter": "1.19.0",
30
+ "@contrast/scopes": "1.13.0",
31
+ "async-hook-domain": "^4.0.1",
31
32
  "ipaddr.js": "^2.0.1",
32
33
  "semver": "^7.6.0"
33
- },
34
- "optionalDependencies": {
35
- "async-hook-domain": "^3.0.2"
36
34
  }
37
35
  }