yakuza0 2.20.14-beta.0 → 2.20.15-beta.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.
- package/nuxt/head.js +28 -1
- package/nuxt/render/csp.js +30 -16
- package/package.json +1 -1
- package/server/proxy/csrf.js +77 -41
- package/utils/csp.js +38 -0
- package/utils/inclusive.js +1 -0
package/nuxt/head.js
CHANGED
|
@@ -34,6 +34,8 @@ var _syncRequest2 = _interopRequireDefault(_syncRequest);
|
|
|
34
34
|
|
|
35
35
|
var _crypto = require("crypto");
|
|
36
36
|
|
|
37
|
+
var _csp = require("../utils/csp");
|
|
38
|
+
|
|
37
39
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
38
40
|
|
|
39
41
|
exports.default = function (config) {
|
|
@@ -79,7 +81,7 @@ exports.default = function (config) {
|
|
|
79
81
|
try {
|
|
80
82
|
if (!gv.integrity) {
|
|
81
83
|
var res = (0, _syncRequest2.default)('GET', iUrl, {
|
|
82
|
-
timeout: 5000,
|
|
84
|
+
timeout: parseInt(_config2.default.server.sriTimeout, 10) || 5000,
|
|
83
85
|
headers: {
|
|
84
86
|
"Host": (0, _yakuza.jsUrl)('hostname', iUrl),
|
|
85
87
|
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36"
|
|
@@ -103,6 +105,31 @@ exports.default = function (config) {
|
|
|
103
105
|
head[key] = v;
|
|
104
106
|
});
|
|
105
107
|
|
|
108
|
+
if (_config2.default.server.cspSwitch && _config2.default.security.isStupid) {
|
|
109
|
+
var cspStr = '';
|
|
110
|
+
|
|
111
|
+
if (_config2.default.server.cspStrict) {
|
|
112
|
+
cspStr = "default-src 'self'";
|
|
113
|
+
} else {
|
|
114
|
+
var cspObj = (0, _csp.directives)();
|
|
115
|
+
_yakuza._.forEach(cspObj, function (v, key) {
|
|
116
|
+
cspStr += key + " " + v.join(' ') + '; ';
|
|
117
|
+
});
|
|
118
|
+
cspStr = cspStr.substring(0, cspStr.length - 2);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
var metaObj = {
|
|
122
|
+
'http-equiv': 'Content-Security-Policy',
|
|
123
|
+
content: cspStr
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
if ((0, _typeof3.default)(head['meta']) === 'object') {
|
|
127
|
+
head['meta'].push(metaObj);
|
|
128
|
+
} else {
|
|
129
|
+
head['meta'] = [metaObj];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
106
133
|
return head;
|
|
107
134
|
};
|
|
108
135
|
|
package/nuxt/render/csp.js
CHANGED
|
@@ -10,29 +10,43 @@ var _config2 = _interopRequireDefault(_config);
|
|
|
10
10
|
|
|
11
11
|
var _yakuza = require('yakuza1');
|
|
12
12
|
|
|
13
|
+
var _csp = require('../../utils/csp');
|
|
14
|
+
|
|
13
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
16
|
|
|
15
17
|
exports.default = function (config) {
|
|
16
|
-
var csp = _config2.default.server.csp;
|
|
17
18
|
var cspSwitch = _config2.default.server.cspSwitch;
|
|
19
|
+
var cspObj = (0, _csp.directives)();
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
cspObj[_yakuza._.kebabCase(key)] = _yakuza._.compact(v.map(function (k) {
|
|
22
|
-
if (_config2.default.server.cspStrict) {
|
|
23
|
-
if (k === "*" || k === "data:" || k === "'unsafe-eval'" || k === "'unsafe-inline'") {
|
|
24
|
-
return '';
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return k;
|
|
29
|
-
}));
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
if (!_config2.default.security.stupid) {
|
|
33
|
-
cspObj = _yakuza._.omit(cspObj, ['require-sri-for']);
|
|
21
|
+
if (_config2.default.security.stupid) {
|
|
22
|
+
cspSwitch = false;
|
|
34
23
|
}
|
|
35
24
|
|
|
25
|
+
// const csp = yConf.server.csp;
|
|
26
|
+
//
|
|
27
|
+
// let cspObj = {};
|
|
28
|
+
// _.forEach(csp, (v, key) => {
|
|
29
|
+
// cspObj[_.kebabCase(key)] = _.compact(v.map(k => {
|
|
30
|
+
// if (yConf.server.cspStrict) {
|
|
31
|
+
// if (
|
|
32
|
+
// k === "*"
|
|
33
|
+
// || k.indexOf('*') !== -1
|
|
34
|
+
// || k === "data:"
|
|
35
|
+
// || k === "'unsafe-eval'"
|
|
36
|
+
// || k === "'unsafe-inline'"
|
|
37
|
+
// ) {
|
|
38
|
+
// return '';
|
|
39
|
+
// }
|
|
40
|
+
// }
|
|
41
|
+
//
|
|
42
|
+
// return k
|
|
43
|
+
// }))
|
|
44
|
+
// })
|
|
45
|
+
//
|
|
46
|
+
// if (!yConf.security.stupid) {
|
|
47
|
+
// cspObj = _.omit(cspObj, ['require-sri-for'])
|
|
48
|
+
// }
|
|
49
|
+
|
|
36
50
|
return cspSwitch ? {
|
|
37
51
|
enabled: true,
|
|
38
52
|
policies: cspObj,
|
package/package.json
CHANGED
package/server/proxy/csrf.js
CHANGED
|
@@ -92,15 +92,16 @@ var _httpProxy = require('http-proxy');
|
|
|
92
92
|
|
|
93
93
|
var _httpProxy2 = _interopRequireDefault(_httpProxy);
|
|
94
94
|
|
|
95
|
+
var _csp = require('../../utils/csp');
|
|
96
|
+
|
|
95
97
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
|
96
98
|
|
|
97
99
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
98
100
|
|
|
99
|
-
// import {
|
|
100
|
-
|
|
101
|
-
// import
|
|
102
|
-
|
|
103
|
-
// import nocache from 'nocache';
|
|
101
|
+
// import {getCache, keys} from "../cache/conf";
|
|
102
|
+
// import csrfPri from "./csrfPri";
|
|
103
|
+
// import csrfPub from "yakuza1/lib/cert/csrfPub";
|
|
104
|
+
// import koaJwt from 'koa-jwt';
|
|
104
105
|
var codeMessage = {
|
|
105
106
|
200: '服务器成功返回请求的数据。',
|
|
106
107
|
201: '新建或修改数据成功。',
|
|
@@ -118,10 +119,13 @@ var codeMessage = {
|
|
|
118
119
|
503: '服务不可用,服务器暂时过载或维护。',
|
|
119
120
|
504: '网关超时。'
|
|
120
121
|
};
|
|
121
|
-
// import
|
|
122
|
-
|
|
123
|
-
// import
|
|
124
|
-
|
|
122
|
+
// import helmet from 'helmet';
|
|
123
|
+
|
|
124
|
+
// import {symmetry as gs, asymmetric as as} from 'yakuza1/lib/encrypt/general';
|
|
125
|
+
|
|
126
|
+
// import paths from '../../config/paths';
|
|
127
|
+
|
|
128
|
+
// import nocache from 'nocache';
|
|
125
129
|
|
|
126
130
|
|
|
127
131
|
var apiErr = function apiErr(options, ctx) {
|
|
@@ -165,13 +169,13 @@ var ssrReqAllow = function ssrReqAllow(ctx) {
|
|
|
165
169
|
var ddos = {};
|
|
166
170
|
|
|
167
171
|
exports.default = function () {
|
|
168
|
-
var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function
|
|
172
|
+
var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee12(_ref2) {
|
|
169
173
|
var app = _ref2.app,
|
|
170
174
|
config = _ref2.config;
|
|
171
|
-
var cspConnectSrcVerify, appCp, appCpApiV1, jwtVerC, omConf, cm;
|
|
172
|
-
return _regenerator2.default.wrap(function
|
|
175
|
+
var cspConnectSrcVerify, appCp, appCpApiV1, jwtVerC, omConf, cm, cspObj;
|
|
176
|
+
return _regenerator2.default.wrap(function _callee12$(_context12) {
|
|
173
177
|
while (1) {
|
|
174
|
-
switch (
|
|
178
|
+
switch (_context12.prev = _context12.next) {
|
|
175
179
|
case 0:
|
|
176
180
|
// if (yConf.security.isTire) {
|
|
177
181
|
// const proxy = httpProxy.createServer({
|
|
@@ -712,12 +716,44 @@ exports.default = function () {
|
|
|
712
716
|
app.use((0, _koaHelmet2.default)());
|
|
713
717
|
|
|
714
718
|
if (_config2.default.security.stupid) {
|
|
719
|
+
cspObj = (0, _csp.directives)();
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
if (_config2.default.server.cspStrict) {
|
|
723
|
+
app.use(function () {
|
|
724
|
+
var _ref11 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8(ctx, next) {
|
|
725
|
+
return _regenerator2.default.wrap(function _callee8$(_context8) {
|
|
726
|
+
while (1) {
|
|
727
|
+
switch (_context8.prev = _context8.next) {
|
|
728
|
+
case 0:
|
|
729
|
+
ctx.set('Content-Security-Policy', "default-src 'self'");
|
|
730
|
+
ctx.set('X-Content-Security-Policy', "default-src 'self'");
|
|
731
|
+
_context8.next = 4;
|
|
732
|
+
return next();
|
|
733
|
+
|
|
734
|
+
case 4:
|
|
735
|
+
case 'end':
|
|
736
|
+
return _context8.stop();
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}, _callee8, undefined);
|
|
740
|
+
}));
|
|
741
|
+
|
|
742
|
+
return function (_x17, _x18) {
|
|
743
|
+
return _ref11.apply(this, arguments);
|
|
744
|
+
};
|
|
745
|
+
}());
|
|
746
|
+
} else {
|
|
747
|
+
app.use(_koaHelmet2.default.contentSecurityPolicy({
|
|
748
|
+
directives: cspObj
|
|
749
|
+
}));
|
|
750
|
+
}
|
|
715
751
|
appCpApiV1(function () {
|
|
716
|
-
var
|
|
752
|
+
var _ref12 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9(ctx, next) {
|
|
717
753
|
var isNext, rHost, rOrigin, rReferer;
|
|
718
|
-
return _regenerator2.default.wrap(function
|
|
754
|
+
return _regenerator2.default.wrap(function _callee9$(_context9) {
|
|
719
755
|
while (1) {
|
|
720
|
-
switch (
|
|
756
|
+
switch (_context9.prev = _context9.next) {
|
|
721
757
|
case 0:
|
|
722
758
|
isNext = true;
|
|
723
759
|
rHost = (0, _server.jsUrl)('hostname', ctx.get('host'));
|
|
@@ -729,15 +765,15 @@ exports.default = function () {
|
|
|
729
765
|
}
|
|
730
766
|
|
|
731
767
|
if (!isNext) {
|
|
732
|
-
|
|
768
|
+
_context9.next = 10;
|
|
733
769
|
break;
|
|
734
770
|
}
|
|
735
771
|
|
|
736
|
-
|
|
772
|
+
_context9.next = 8;
|
|
737
773
|
return next();
|
|
738
774
|
|
|
739
775
|
case 8:
|
|
740
|
-
|
|
776
|
+
_context9.next = 11;
|
|
741
777
|
break;
|
|
742
778
|
|
|
743
779
|
case 10:
|
|
@@ -748,14 +784,14 @@ exports.default = function () {
|
|
|
748
784
|
|
|
749
785
|
case 11:
|
|
750
786
|
case 'end':
|
|
751
|
-
return
|
|
787
|
+
return _context9.stop();
|
|
752
788
|
}
|
|
753
789
|
}
|
|
754
|
-
},
|
|
790
|
+
}, _callee9, undefined);
|
|
755
791
|
}));
|
|
756
792
|
|
|
757
|
-
return function (
|
|
758
|
-
return
|
|
793
|
+
return function (_x19, _x20) {
|
|
794
|
+
return _ref12.apply(this, arguments);
|
|
759
795
|
};
|
|
760
796
|
}()
|
|
761
797
|
// if (ctx.method === 'GET' || ctx.method === 'POST' || jwtVerC(ctx.path)) {
|
|
@@ -769,29 +805,29 @@ exports.default = function () {
|
|
|
769
805
|
);
|
|
770
806
|
|
|
771
807
|
app.use(function () {
|
|
772
|
-
var
|
|
773
|
-
return _regenerator2.default.wrap(function
|
|
808
|
+
var _ref13 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10(ctx, next) {
|
|
809
|
+
return _regenerator2.default.wrap(function _callee10$(_context10) {
|
|
774
810
|
while (1) {
|
|
775
|
-
switch (
|
|
811
|
+
switch (_context10.prev = _context10.next) {
|
|
776
812
|
case 0:
|
|
777
813
|
// ctx.set('Surrogate-Control', 'no-store');
|
|
778
814
|
// ctx.set('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
|
|
779
815
|
// ctx.set('Pragma', 'no-cache');
|
|
780
816
|
// ctx.set('Expires', '0');
|
|
781
817
|
(0, _control.noCache)(ctx);
|
|
782
|
-
|
|
818
|
+
_context10.next = 3;
|
|
783
819
|
return next();
|
|
784
820
|
|
|
785
821
|
case 3:
|
|
786
822
|
case 'end':
|
|
787
|
-
return
|
|
823
|
+
return _context10.stop();
|
|
788
824
|
}
|
|
789
825
|
}
|
|
790
|
-
},
|
|
826
|
+
}, _callee10, undefined);
|
|
791
827
|
}));
|
|
792
828
|
|
|
793
|
-
return function (
|
|
794
|
-
return
|
|
829
|
+
return function (_x21, _x22) {
|
|
830
|
+
return _ref13.apply(this, arguments);
|
|
795
831
|
};
|
|
796
832
|
}());
|
|
797
833
|
}
|
|
@@ -805,10 +841,10 @@ exports.default = function () {
|
|
|
805
841
|
}
|
|
806
842
|
|
|
807
843
|
app.use(function () {
|
|
808
|
-
var
|
|
809
|
-
return _regenerator2.default.wrap(function
|
|
844
|
+
var _ref14 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee11(ctx, next) {
|
|
845
|
+
return _regenerator2.default.wrap(function _callee11$(_context11) {
|
|
810
846
|
while (1) {
|
|
811
|
-
switch (
|
|
847
|
+
switch (_context11.prev = _context11.next) {
|
|
812
848
|
case 0:
|
|
813
849
|
// const csrfCookie = ctx.cookies.get(variable.csrfCookie, {signed: false});
|
|
814
850
|
// console.log(ctx.path, ctx.req.headers.cookie, 111);
|
|
@@ -824,28 +860,28 @@ exports.default = function () {
|
|
|
824
860
|
cookieDomain: config.appConf.cookieDomain || _server.Cookies.getDefCookieDomain(ctx.hostname)
|
|
825
861
|
}, ctx.req.crossParams);
|
|
826
862
|
|
|
827
|
-
|
|
863
|
+
_context11.next = 3;
|
|
828
864
|
return next();
|
|
829
865
|
|
|
830
866
|
case 3:
|
|
831
867
|
case 'end':
|
|
832
|
-
return
|
|
868
|
+
return _context11.stop();
|
|
833
869
|
}
|
|
834
870
|
}
|
|
835
|
-
},
|
|
871
|
+
}, _callee11, undefined);
|
|
836
872
|
}));
|
|
837
873
|
|
|
838
|
-
return function (
|
|
839
|
-
return
|
|
874
|
+
return function (_x23, _x24) {
|
|
875
|
+
return _ref14.apply(this, arguments);
|
|
840
876
|
};
|
|
841
877
|
}());
|
|
842
878
|
|
|
843
879
|
case 16:
|
|
844
880
|
case 'end':
|
|
845
|
-
return
|
|
881
|
+
return _context12.stop();
|
|
846
882
|
}
|
|
847
883
|
}
|
|
848
|
-
},
|
|
884
|
+
}, _callee12, undefined);
|
|
849
885
|
}));
|
|
850
886
|
|
|
851
887
|
return function (_x) {
|
package/utils/csp.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.directives = undefined;
|
|
7
|
+
|
|
8
|
+
var _yakuza = require("yakuza1");
|
|
9
|
+
|
|
10
|
+
var _config = require("../config");
|
|
11
|
+
|
|
12
|
+
var _config2 = _interopRequireDefault(_config);
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
var directives = exports.directives = function directives() {
|
|
17
|
+
var csp = _config2.default.server.csp;
|
|
18
|
+
// const cspSwitch = yConf.server.cspSwitch;
|
|
19
|
+
|
|
20
|
+
var cspObj = {};
|
|
21
|
+
_yakuza._.forEach(csp, function (v, key) {
|
|
22
|
+
cspObj[_yakuza._.kebabCase(key)] = _yakuza._.compact(v.map(function (k) {
|
|
23
|
+
if (_config2.default.server.cspStrict) {
|
|
24
|
+
if (k === "*" || k.indexOf('*') !== -1 || k === "data:" || k === "'unsafe-eval'" || k === "'unsafe-inline'") {
|
|
25
|
+
return '';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return k;
|
|
30
|
+
}));
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (!_config2.default.security.stupid) {
|
|
34
|
+
cspObj = _yakuza._.omit(cspObj, ['require-sri-for']);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return cspObj;
|
|
38
|
+
};
|