@midwayjs/security 3.20.5 → 4.0.0-beta.1

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.
@@ -25,32 +25,32 @@ let SecurityConfiguration = class SecurityConfiguration {
25
25
  this.applicationManager
26
26
  .getApplications(['koa', 'faas', 'express', 'egg'])
27
27
  .forEach(app => {
28
- var _a, _b, _c, _d, _e, _f, _g;
29
28
  app.useMiddleware(helper_1.SecurityHelper);
30
- if ((_a = this.security.csrf) === null || _a === void 0 ? void 0 : _a.enable) {
29
+ if (this.security.csrf?.enable) {
31
30
  app.useMiddleware(csrf_middleware_1.CsrfMiddleware);
32
31
  }
33
- if ((_b = this.security.csp) === null || _b === void 0 ? void 0 : _b.enable) {
32
+ if (this.security.csp?.enable) {
34
33
  app.useMiddleware(csp_middleware_1.CSPMiddleware);
35
34
  }
36
- if ((_c = this.security.xframe) === null || _c === void 0 ? void 0 : _c.enable) {
35
+ if (this.security.xframe?.enable) {
37
36
  app.useMiddleware(xframe_middleware_1.XFrameMiddleware);
38
37
  }
39
- if ((_d = this.security.hsts) === null || _d === void 0 ? void 0 : _d.enable) {
38
+ if (this.security.hsts?.enable) {
40
39
  app.useMiddleware(hsts_middleware_1.HSTSMiddleware);
41
40
  }
42
- if ((_e = this.security.noopen) === null || _e === void 0 ? void 0 : _e.enable) {
41
+ if (this.security.noopen?.enable) {
43
42
  app.useMiddleware(noopen_middleware_1.NoOpenMiddleware);
44
43
  }
45
- if ((_f = this.security.nosniff) === null || _f === void 0 ? void 0 : _f.enable) {
44
+ if (this.security.nosniff?.enable) {
46
45
  app.useMiddleware(_1.NoSniffMiddleware);
47
46
  }
48
- if ((_g = this.security.xssProtection) === null || _g === void 0 ? void 0 : _g.enable) {
47
+ if (this.security.xssProtection?.enable) {
49
48
  app.useMiddleware(xssProtection_middleware_1.XSSProtectionMiddleware);
50
49
  }
51
50
  });
52
51
  }
53
52
  };
53
+ exports.SecurityConfiguration = SecurityConfiguration;
54
54
  __decorate([
55
55
  (0, core_1.Inject)(),
56
56
  __metadata("design:type", core_1.MidwayApplicationManager)
@@ -59,7 +59,7 @@ __decorate([
59
59
  (0, core_1.Config)('security'),
60
60
  __metadata("design:type", Object)
61
61
  ], SecurityConfiguration.prototype, "security", void 0);
62
- SecurityConfiguration = __decorate([
62
+ exports.SecurityConfiguration = SecurityConfiguration = __decorate([
63
63
  (0, core_1.Configuration)({
64
64
  namespace: 'security',
65
65
  importConfigs: [
@@ -69,5 +69,4 @@ SecurityConfiguration = __decorate([
69
69
  ],
70
70
  })
71
71
  ], SecurityConfiguration);
72
- exports.SecurityConfiguration = SecurityConfiguration;
73
72
  //# sourceMappingURL=configuration.js.map
@@ -13,17 +13,16 @@ exports.BaseMiddleware = void 0;
13
13
  const core_1 = require("@midwayjs/core");
14
14
  class BaseMiddleware {
15
15
  async init() {
16
- var _a, _b, _c, _d;
17
16
  // 动态合并一些规则
18
- if ((_b = (_a = this.security) === null || _a === void 0 ? void 0 : _a[this.securityName()]) === null || _b === void 0 ? void 0 : _b.match) {
17
+ if (this.security?.[this.securityName()]?.match) {
19
18
  this.match = this.security[this.securityName()].match;
20
19
  }
21
- else if ((_d = (_c = this.security) === null || _c === void 0 ? void 0 : _c[this.securityName()]) === null || _d === void 0 ? void 0 : _d.ignore) {
20
+ else if (this.security?.[this.securityName()]?.ignore) {
22
21
  this.ignore = this.security[this.securityName()].ignore;
23
22
  }
24
23
  }
25
24
  resolve(app) {
26
- if (app.getFrameworkType() === core_1.MidwayFrameworkType.WEB_EXPRESS) {
25
+ if ('express' === app.getNamespace()) {
27
26
  return async (req, res, next) => {
28
27
  return this.compatibleMiddleware(req, req, res, next);
29
28
  };
@@ -35,6 +34,7 @@ class BaseMiddleware {
35
34
  }
36
35
  }
37
36
  }
37
+ exports.BaseMiddleware = BaseMiddleware;
38
38
  __decorate([
39
39
  (0, core_1.Config)('security'),
40
40
  __metadata("design:type", Object)
@@ -45,5 +45,4 @@ __decorate([
45
45
  __metadata("design:paramtypes", []),
46
46
  __metadata("design:returntype", Promise)
47
47
  ], BaseMiddleware.prototype, "init", null);
48
- exports.BaseMiddleware = BaseMiddleware;
49
48
  //# sourceMappingURL=base.js.map
@@ -77,8 +77,8 @@ let CSPMiddleware = class CSPMiddleware extends base_1.BaseMiddleware {
77
77
  return 'csp';
78
78
  }
79
79
  };
80
- CSPMiddleware = __decorate([
80
+ exports.CSPMiddleware = CSPMiddleware;
81
+ exports.CSPMiddleware = CSPMiddleware = __decorate([
81
82
  (0, core_1.Middleware)()
82
83
  ], CSPMiddleware);
83
- exports.CSPMiddleware = CSPMiddleware;
84
84
  //# sourceMappingURL=csp.middleware.js.map
@@ -63,7 +63,6 @@ let CsrfMiddleware = class CsrfMiddleware extends base_1.BaseMiddleware {
63
63
  }
64
64
  }
65
65
  getCSRFSecret(context) {
66
- var _a, _b;
67
66
  if (context[_CSRF_SECRET]) {
68
67
  return context[_CSRF_SECRET];
69
68
  }
@@ -80,7 +79,7 @@ let CsrfMiddleware = class CsrfMiddleware extends base_1.BaseMiddleware {
80
79
  }
81
80
  for (const name of cookieName) {
82
81
  context[_CSRF_SECRET] =
83
- ((_b = (_a = context.cookies).get) === null || _b === void 0 ? void 0 : _b.call(_a, name, { signed: false })) ||
82
+ context.cookies.get?.(name, { signed: false }) ||
84
83
  context.cookies[name] ||
85
84
  '';
86
85
  if (context[_CSRF_SECRET]) {
@@ -91,10 +90,9 @@ let CsrfMiddleware = class CsrfMiddleware extends base_1.BaseMiddleware {
91
90
  return context[_CSRF_SECRET];
92
91
  }
93
92
  getInputToken(context, request) {
94
- var _a, _b;
95
93
  const { headerName, bodyName, queryName } = this.security.csrf;
96
- return (((_a = context.query) === null || _a === void 0 ? void 0 : _a[queryName]) ||
97
- ((_b = request.body) === null || _b === void 0 ? void 0 : _b[bodyName]) ||
94
+ return (context.query?.[queryName] ||
95
+ request.body?.[bodyName] ||
98
96
  (headerName && context.get(headerName)));
99
97
  }
100
98
  checkCSRFToken(context, request) {
@@ -120,7 +118,6 @@ let CsrfMiddleware = class CsrfMiddleware extends base_1.BaseMiddleware {
120
118
  }
121
119
  }
122
120
  ensureCsrfSecret(context, request, response, rotate) {
123
- var _a;
124
121
  const tokenSecret = this.getCSRFSecret(context);
125
122
  if (tokenSecret && !rotate) {
126
123
  return;
@@ -144,7 +141,7 @@ let CsrfMiddleware = class CsrfMiddleware extends base_1.BaseMiddleware {
144
141
  cookieName = [cookieName];
145
142
  }
146
143
  for (const name of cookieName) {
147
- if ((_a = response.cookies) === null || _a === void 0 ? void 0 : _a.set) {
144
+ if (response.cookies?.set) {
148
145
  response.cookies.set(name, secret, cookieOpts);
149
146
  }
150
147
  else {
@@ -157,8 +154,8 @@ let CsrfMiddleware = class CsrfMiddleware extends base_1.BaseMiddleware {
157
154
  return 'csrf';
158
155
  }
159
156
  };
160
- CsrfMiddleware = __decorate([
157
+ exports.CsrfMiddleware = CsrfMiddleware;
158
+ exports.CsrfMiddleware = CsrfMiddleware = __decorate([
161
159
  (0, core_1.Middleware)()
162
160
  ], CsrfMiddleware);
163
- exports.CsrfMiddleware = CsrfMiddleware;
164
161
  //# sourceMappingURL=csrf.middleware.js.map
@@ -12,7 +12,7 @@ const escape = require("escape-html");
12
12
  const xss_1 = require("xss");
13
13
  let SecurityHelper = class SecurityHelper {
14
14
  resolve(app) {
15
- if (app.getFrameworkType() === core_1.MidwayFrameworkType.WEB_EXPRESS) {
15
+ if ('express' === app.getNamespace()) {
16
16
  return async (req, res, next) => {
17
17
  return this.compatibleMiddleware(req, req, res, next);
18
18
  };
@@ -33,10 +33,10 @@ let SecurityHelper = class SecurityHelper {
33
33
  return next();
34
34
  }
35
35
  };
36
- SecurityHelper = __decorate([
36
+ exports.SecurityHelper = SecurityHelper;
37
+ exports.SecurityHelper = SecurityHelper = __decorate([
37
38
  (0, core_1.Middleware)()
38
39
  ], SecurityHelper);
39
- exports.SecurityHelper = SecurityHelper;
40
40
  const MATCH_VULNERABLE_REGEXP = /[\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]/;
41
41
  const BASIC_ALPHABETS = new Set('abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''));
42
42
  const map = {
@@ -23,8 +23,8 @@ let HSTSMiddleware = class HSTSMiddleware extends base_1.BaseMiddleware {
23
23
  return 'hsts';
24
24
  }
25
25
  };
26
- HSTSMiddleware = __decorate([
26
+ exports.HSTSMiddleware = HSTSMiddleware;
27
+ exports.HSTSMiddleware = HSTSMiddleware = __decorate([
27
28
  (0, core_1.Middleware)()
28
29
  ], HSTSMiddleware);
29
- exports.HSTSMiddleware = HSTSMiddleware;
30
30
  //# sourceMappingURL=hsts.middleware.js.map
@@ -19,8 +19,8 @@ let NoOpenMiddleware = class NoOpenMiddleware extends base_1.BaseMiddleware {
19
19
  return 'noopen';
20
20
  }
21
21
  };
22
- NoOpenMiddleware = __decorate([
22
+ exports.NoOpenMiddleware = NoOpenMiddleware;
23
+ exports.NoOpenMiddleware = NoOpenMiddleware = __decorate([
23
24
  (0, core_1.Middleware)()
24
25
  ], NoOpenMiddleware);
25
- exports.NoOpenMiddleware = NoOpenMiddleware;
26
26
  //# sourceMappingURL=noopen.middleware.js.map
@@ -22,8 +22,8 @@ let NoSniffMiddleware = class NoSniffMiddleware extends base_1.BaseMiddleware {
22
22
  return 'nosniff';
23
23
  }
24
24
  };
25
- NoSniffMiddleware = __decorate([
25
+ exports.NoSniffMiddleware = NoSniffMiddleware;
26
+ exports.NoSniffMiddleware = NoSniffMiddleware = __decorate([
26
27
  (0, core_1.Middleware)()
27
28
  ], NoSniffMiddleware);
28
- exports.NoSniffMiddleware = NoSniffMiddleware;
29
29
  //# sourceMappingURL=nosniff.middleware.js.map
@@ -11,9 +11,8 @@ const core_1 = require("@midwayjs/core");
11
11
  const base_1 = require("./base");
12
12
  let XFrameMiddleware = class XFrameMiddleware extends base_1.BaseMiddleware {
13
13
  async compatibleMiddleware(context, req, res, next) {
14
- var _a;
15
14
  const result = await next();
16
- const value = ((_a = this.security.xframe) === null || _a === void 0 ? void 0 : _a.value) || 'SAMEORIGIN';
15
+ const value = this.security.xframe?.value || 'SAMEORIGIN';
17
16
  res.set('x-frame-options', value);
18
17
  return result;
19
18
  }
@@ -21,8 +20,8 @@ let XFrameMiddleware = class XFrameMiddleware extends base_1.BaseMiddleware {
21
20
  return 'xframe';
22
21
  }
23
22
  };
24
- XFrameMiddleware = __decorate([
23
+ exports.XFrameMiddleware = XFrameMiddleware;
24
+ exports.XFrameMiddleware = XFrameMiddleware = __decorate([
25
25
  (0, core_1.Middleware)()
26
26
  ], XFrameMiddleware);
27
- exports.XFrameMiddleware = XFrameMiddleware;
28
27
  //# sourceMappingURL=xframe.middleware.js.map
@@ -19,8 +19,8 @@ let XSSProtectionMiddleware = class XSSProtectionMiddleware extends base_1.BaseM
19
19
  return 'xssProtection';
20
20
  }
21
21
  };
22
- XSSProtectionMiddleware = __decorate([
22
+ exports.XSSProtectionMiddleware = XSSProtectionMiddleware;
23
+ exports.XSSProtectionMiddleware = XSSProtectionMiddleware = __decorate([
23
24
  (0, core_1.Middleware)()
24
25
  ], XSSProtectionMiddleware);
25
- exports.XSSProtectionMiddleware = XSSProtectionMiddleware;
26
26
  //# sourceMappingURL=xssProtection.middleware.js.map
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@midwayjs/security",
3
- "version": "3.20.5",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "Midway Security Component",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
- "test": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand",
10
- "cov": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand --coverage --forceExit",
9
+ "test": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand",
10
+ "cov": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand --coverage --forceExit",
11
11
  "ci": "npm run test"
12
12
  },
13
13
  "keywords": [],
@@ -30,13 +30,12 @@
30
30
  "xss": "1.0.15"
31
31
  },
32
32
  "devDependencies": {
33
- "@midwayjs/core": "^3.20.4",
34
- "@midwayjs/express": "^3.20.4",
35
- "@midwayjs/faas": "^3.20.4",
36
- "@midwayjs/koa": "^3.20.5",
37
- "@midwayjs/mock": "^3.20.4",
38
- "@midwayjs/serverless-app": "^3.20.4",
39
- "@midwayjs/web": "^3.20.4"
33
+ "@midwayjs/core": "^4.0.0-beta.1",
34
+ "@midwayjs/express": "^4.0.0-beta.1",
35
+ "@midwayjs/faas": "^4.0.0-beta.1",
36
+ "@midwayjs/koa": "^4.0.0-beta.1",
37
+ "@midwayjs/mock": "^4.0.0-beta.1",
38
+ "@midwayjs/web": "^4.0.0-beta.1"
40
39
  },
41
- "gitHead": "7ce57281bd3ef5d18dc50b47ff9bffb8a27c071e"
40
+ "gitHead": "832961ec3aff123c033197d8c00cb2bc9bad7ff8"
42
41
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2013 - Now midwayjs
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.