@eggjs/security 5.0.0-beta.19 → 5.0.0-beta.20
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/dist/agent.js +1 -1
- package/dist/app/extend/agent.d.ts +2 -1
- package/dist/app/extend/agent.js +1 -1
- package/dist/app/extend/application.d.ts +3 -11
- package/dist/app/extend/application.js +2 -30
- package/dist/app/extend/context.d.ts +3 -60
- package/dist/app/extend/context.js +2 -189
- package/dist/app/extend/helper.d.ts +8 -8
- package/dist/app/extend/helper.js +11 -1
- package/dist/app/extend/response.d.ts +3 -38
- package/dist/app/extend/response.js +3 -68
- package/dist/app/middleware/securities.js +12 -1
- package/dist/app.js +2 -2
- package/dist/application-COC0mYEe.js +32 -0
- package/dist/application-n5bk2L_z.d.ts +12 -0
- package/dist/cliFilter-7BSD8Nc_.js +18 -0
- package/dist/cliFilter-DKZxCxSe.d.ts +7 -0
- package/dist/config/config.default.d.ts +1 -869
- package/dist/config/config.default.js +1 -164
- package/dist/config.default-AcwQOAG0.js +166 -0
- package/dist/config.default-D8v08Vox.d.ts +870 -0
- package/dist/context-C-N1IY85.d.ts +95 -0
- package/dist/context-e-QJTKfq.js +191 -0
- package/dist/csp-BW5AJd_f.js +46 -0
- package/dist/csrf-9aSLHiby.js +33 -0
- package/dist/dta-DVAKEpJ3.js +13 -0
- package/dist/escape-Dex_Pk9e.d.ts +2 -0
- package/dist/escape-p8-cW8c_.js +7 -0
- package/dist/escapeShellArg-BnzDicAC.d.ts +4 -0
- package/dist/escapeShellArg-C0v1ZeCl.js +7 -0
- package/dist/escapeShellCmd-CkAdyhtO.js +15 -0
- package/dist/escapeShellCmd-DQZZIHde.d.ts +4 -0
- package/dist/helper-DylzfQ_5.js +25 -0
- package/dist/hsts-CWMKNTEh.js +19 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +6 -3
- package/dist/lib/extend/safe_curl.d.ts +2 -19
- package/dist/lib/extend/safe_curl.js +1 -17
- package/dist/lib/helper/cliFilter.d.ts +1 -6
- package/dist/lib/helper/cliFilter.js +1 -16
- package/dist/lib/helper/escape.d.ts +1 -1
- package/dist/lib/helper/escape.js +1 -5
- package/dist/lib/helper/escapeShellArg.d.ts +1 -3
- package/dist/lib/helper/escapeShellArg.js +1 -5
- package/dist/lib/helper/escapeShellCmd.d.ts +1 -3
- package/dist/lib/helper/escapeShellCmd.js +1 -13
- package/dist/lib/helper/index.d.ts +9 -9
- package/dist/lib/helper/index.js +11 -23
- package/dist/lib/helper/shtml.d.ts +1 -5
- package/dist/lib/helper/shtml.js +2 -51
- package/dist/lib/helper/sjs.d.ts +1 -6
- package/dist/lib/helper/sjs.js +1 -34
- package/dist/lib/helper/sjson.d.ts +1 -3
- package/dist/lib/helper/sjson.js +2 -30
- package/dist/lib/helper/spath.d.ts +1 -6
- package/dist/lib/helper/spath.js +1 -14
- package/dist/lib/helper/surl.d.ts +1 -5
- package/dist/lib/helper/surl.js +1 -23
- package/dist/lib/middlewares/csp.d.ts +1 -1
- package/dist/lib/middlewares/csp.js +2 -44
- package/dist/lib/middlewares/csrf.d.ts +1 -1
- package/dist/lib/middlewares/csrf.js +2 -31
- package/dist/lib/middlewares/dta.js +2 -11
- package/dist/lib/middlewares/hsts.d.ts +1 -1
- package/dist/lib/middlewares/hsts.js +2 -17
- package/dist/lib/middlewares/index.d.ts +12 -12
- package/dist/lib/middlewares/index.js +12 -25
- package/dist/lib/middlewares/methodnoallow.js +1 -13
- package/dist/lib/middlewares/noopen.d.ts +1 -1
- package/dist/lib/middlewares/noopen.js +2 -15
- package/dist/lib/middlewares/nosniff.d.ts +1 -1
- package/dist/lib/middlewares/nosniff.js +2 -25
- package/dist/lib/middlewares/referrerPolicy.d.ts +1 -1
- package/dist/lib/middlewares/referrerPolicy.js +2 -29
- package/dist/lib/middlewares/xframe.d.ts +1 -1
- package/dist/lib/middlewares/xframe.js +2 -16
- package/dist/lib/middlewares/xssProtection.d.ts +1 -1
- package/dist/lib/middlewares/xssProtection.js +2 -15
- package/dist/lib/utils.d.ts +1 -1
- package/dist/lib/utils.js +1 -125
- package/dist/methodnoallow-BAZONArS.js +15 -0
- package/dist/middlewares-CkQjv8t0.js +27 -0
- package/dist/noopen-C3jUBwoH.js +17 -0
- package/dist/nosniff-CcLkhX2I.js +27 -0
- package/dist/referrerPolicy-D4Uafq6c.js +31 -0
- package/dist/response-BFnHAJrV.js +69 -0
- package/dist/safe_curl-UlViaxoF.js +19 -0
- package/dist/safe_curl-mqZZv_YQ.d.ts +20 -0
- package/dist/shtml-CAquTzgV.d.ts +6 -0
- package/dist/shtml-CgF4kOx-.js +53 -0
- package/dist/sjs-Cbmkk5xS.js +36 -0
- package/dist/sjs-QZIJYS71.d.ts +7 -0
- package/dist/sjson-BetFnVR6.js +32 -0
- package/dist/sjson-O-vKJPws.d.ts +4 -0
- package/dist/spath-Bu9sy6Kz.js +16 -0
- package/dist/spath-DseDPHxf.d.ts +7 -0
- package/dist/surl-ClleTea7.js +25 -0
- package/dist/surl-JV70X_RZ.d.ts +6 -0
- package/dist/types-BZR2U30p.d.ts +38 -0
- package/dist/types-DnJpiSJb.js +1 -0
- package/dist/types.d.ts +3 -38
- package/dist/types.js +2 -0
- package/dist/utils-Cajs5P8M.js +127 -0
- package/dist/xframe-q9fEZkVI.js +18 -0
- package/dist/xssProtection-D5QsHX-e.js +17 -0
- package/package.json +5 -5
package/dist/lib/helper/index.js
CHANGED
|
@@ -1,25 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
1
|
+
import "../../utils-Cajs5P8M.js";
|
|
2
|
+
import "../../cliFilter-7BSD8Nc_.js";
|
|
3
|
+
import "../../escape-p8-cW8c_.js";
|
|
4
|
+
import "../../escapeShellArg-C0v1ZeCl.js";
|
|
5
|
+
import "../../escapeShellCmd-CkAdyhtO.js";
|
|
6
|
+
import "../../shtml-CgF4kOx-.js";
|
|
7
|
+
import "../../sjs-Cbmkk5xS.js";
|
|
8
|
+
import "../../sjson-BetFnVR6.js";
|
|
9
|
+
import "../../spath-Bu9sy6Kz.js";
|
|
10
|
+
import "../../surl-ClleTea7.js";
|
|
11
|
+
import { helper_default } from "../../helper-DylzfQ_5.js";
|
|
10
12
|
|
|
11
|
-
//#region src/lib/helper/index.ts
|
|
12
|
-
var helper_default = {
|
|
13
|
-
cliFilter,
|
|
14
|
-
escape: escape_default,
|
|
15
|
-
escapeShellArg,
|
|
16
|
-
escapeShellCmd,
|
|
17
|
-
shtml,
|
|
18
|
-
sjs: escapeJavaScript,
|
|
19
|
-
sjson: jsonEscape,
|
|
20
|
-
spath: pathFilter,
|
|
21
|
-
surl
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
13
|
export { helper_default as default };
|
package/dist/lib/helper/shtml.js
CHANGED
|
@@ -1,53 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import "../../utils-Cajs5P8M.js";
|
|
2
|
+
import { shtml } from "../../shtml-CgF4kOx-.js";
|
|
3
3
|
|
|
4
|
-
//#region src/lib/helper/shtml.ts
|
|
5
|
-
const BUILD_IN_ON_TAG_ATTR = Symbol("buildInOnTagAttr");
|
|
6
|
-
function shtml(val) {
|
|
7
|
-
if (typeof val !== "string") return val;
|
|
8
|
-
const securityOptions = this.ctx.securityOptions;
|
|
9
|
-
const shtmlConfig = {
|
|
10
|
-
...this.app.config.helper.shtml,
|
|
11
|
-
...securityOptions.shtml,
|
|
12
|
-
[BUILD_IN_ON_TAG_ATTR]: void 0
|
|
13
|
-
};
|
|
14
|
-
const domainWhiteList = this.app.config.security.domainWhiteList;
|
|
15
|
-
const app = this.app;
|
|
16
|
-
if (!shtmlConfig[BUILD_IN_ON_TAG_ATTR]) {
|
|
17
|
-
shtmlConfig[BUILD_IN_ON_TAG_ATTR] = (_tag, name, value, isWhiteAttr) => {
|
|
18
|
-
if (isWhiteAttr && (name === "href" || name === "src")) {
|
|
19
|
-
if (!value) return;
|
|
20
|
-
value = String(value);
|
|
21
|
-
if (value[0] === "/" || value[0] === "#") return;
|
|
22
|
-
const hostname = getFromUrl(value, "hostname");
|
|
23
|
-
if (!hostname) return;
|
|
24
|
-
if (!isSafeDomain(hostname, domainWhiteList)) if (shtmlConfig.domainWhiteList && shtmlConfig.domainWhiteList.length > 0) {
|
|
25
|
-
app.deprecate("[@eggjs/security/lib/helper/shtml] `config.helper.shtml.domainWhiteList` has been deprecate. Please use `config.security.domainWhiteList` instead.");
|
|
26
|
-
if (!isSafeDomain(hostname, shtmlConfig.domainWhiteList)) return "";
|
|
27
|
-
} else return "";
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
if (shtmlConfig.onTagAttr) {
|
|
31
|
-
const customOnTagAttrHandler = shtmlConfig.onTagAttr;
|
|
32
|
-
shtmlConfig.onTagAttr = function(tag, name, value, isWhiteAttr) {
|
|
33
|
-
const result = customOnTagAttrHandler.apply(this, [
|
|
34
|
-
tag,
|
|
35
|
-
name,
|
|
36
|
-
value,
|
|
37
|
-
isWhiteAttr
|
|
38
|
-
]);
|
|
39
|
-
if (result !== void 0) return result;
|
|
40
|
-
return shtmlConfig[BUILD_IN_ON_TAG_ATTR].apply(this, [
|
|
41
|
-
tag,
|
|
42
|
-
name,
|
|
43
|
-
value,
|
|
44
|
-
isWhiteAttr
|
|
45
|
-
]);
|
|
46
|
-
};
|
|
47
|
-
} else shtmlConfig.onTagAttr = shtmlConfig[BUILD_IN_ON_TAG_ATTR];
|
|
48
|
-
}
|
|
49
|
-
return xss(val, shtmlConfig);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
//#endregion
|
|
53
4
|
export { shtml as default };
|
package/dist/lib/helper/sjs.d.ts
CHANGED
package/dist/lib/helper/sjs.js
CHANGED
|
@@ -1,36 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Escape JavaScript to \xHH format
|
|
4
|
-
*/
|
|
5
|
-
const MATCH_VULNERABLE_REGEXP = /[\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]/;
|
|
6
|
-
const BASIC_ALPHABETS = new Set("abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""));
|
|
7
|
-
const map = {
|
|
8
|
-
" ": "\\t",
|
|
9
|
-
"\n": "\\n",
|
|
10
|
-
"\r": "\\r"
|
|
11
|
-
};
|
|
12
|
-
function escapeJavaScript(text) {
|
|
13
|
-
const str = "" + text;
|
|
14
|
-
const match = MATCH_VULNERABLE_REGEXP.exec(str);
|
|
15
|
-
if (!match) return str;
|
|
16
|
-
let res = "";
|
|
17
|
-
let index = 0;
|
|
18
|
-
let lastIndex = 0;
|
|
19
|
-
let ascii;
|
|
20
|
-
for (index = match.index; index < str.length; index++) {
|
|
21
|
-
ascii = str[index];
|
|
22
|
-
if (BASIC_ALPHABETS.has(ascii)) continue;
|
|
23
|
-
else if (map[ascii] === void 0) {
|
|
24
|
-
const code = ascii.charCodeAt(0);
|
|
25
|
-
if (code > 127) continue;
|
|
26
|
-
else map[ascii] = "\\x" + code.toString(16);
|
|
27
|
-
}
|
|
28
|
-
if (lastIndex !== index) res += str.substring(lastIndex, index);
|
|
29
|
-
lastIndex = index + 1;
|
|
30
|
-
res += map[ascii];
|
|
31
|
-
}
|
|
32
|
-
return lastIndex !== index ? res + str.substring(lastIndex, index) : res;
|
|
33
|
-
}
|
|
1
|
+
import { escapeJavaScript } from "../../sjs-Cbmkk5xS.js";
|
|
34
2
|
|
|
35
|
-
//#endregion
|
|
36
3
|
export { escapeJavaScript as default };
|
package/dist/lib/helper/sjson.js
CHANGED
|
@@ -1,32 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../../sjs-Cbmkk5xS.js";
|
|
2
|
+
import { jsonEscape } from "../../sjson-BetFnVR6.js";
|
|
2
3
|
|
|
3
|
-
//#region src/lib/helper/sjson.ts
|
|
4
|
-
/**
|
|
5
|
-
* escape json
|
|
6
|
-
* for output json in script
|
|
7
|
-
*/
|
|
8
|
-
function sanitizeKey(obj) {
|
|
9
|
-
if (typeof obj !== "object") return obj;
|
|
10
|
-
if (Array.isArray(obj)) return obj;
|
|
11
|
-
if (obj === null) return null;
|
|
12
|
-
if (typeof obj === "boolean") return obj;
|
|
13
|
-
if (typeof obj === "number") return obj;
|
|
14
|
-
if (Buffer.isBuffer(obj)) return obj.toString();
|
|
15
|
-
for (const k in obj) {
|
|
16
|
-
const escapedK = escapeJavaScript(k);
|
|
17
|
-
if (escapedK !== k) {
|
|
18
|
-
obj[escapedK] = sanitizeKey(obj[k]);
|
|
19
|
-
obj[k] = void 0;
|
|
20
|
-
} else obj[k] = sanitizeKey(obj[k]);
|
|
21
|
-
}
|
|
22
|
-
return obj;
|
|
23
|
-
}
|
|
24
|
-
function jsonEscape(obj) {
|
|
25
|
-
return JSON.stringify(sanitizeKey(obj), (_k, v) => {
|
|
26
|
-
if (typeof v === "string") return escapeJavaScript(v);
|
|
27
|
-
return v;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
//#endregion
|
|
32
4
|
export { jsonEscape as default };
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/lib/helper/spath.d.ts
|
|
4
|
-
|
|
5
|
-
declare function pathFilter(this: BaseContextClass, path: string): string | null;
|
|
6
|
-
//#endregion
|
|
1
|
+
import { pathFilter } from "../../spath-DseDPHxf.js";
|
|
7
2
|
export { pathFilter as default };
|
package/dist/lib/helper/spath.js
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
function pathFilter(path) {
|
|
3
|
-
if (typeof path !== "string") return path;
|
|
4
|
-
const pathSource = path;
|
|
5
|
-
while (path.indexOf("%") !== -1) try {
|
|
6
|
-
path = decodeURIComponent(path);
|
|
7
|
-
} catch {
|
|
8
|
-
if (process.env.NODE_ENV !== "production") this.ctx.coreLogger.warn("[@eggjs/security/lib/helper/spath] : decode file path %j failed.", path);
|
|
9
|
-
break;
|
|
10
|
-
}
|
|
11
|
-
if (path.indexOf("..") !== -1 || path[0] === "/") return null;
|
|
12
|
-
return pathSource;
|
|
13
|
-
}
|
|
1
|
+
import { pathFilter } from "../../spath-Bu9sy6Kz.js";
|
|
14
2
|
|
|
15
|
-
//#endregion
|
|
16
3
|
export { pathFilter as default };
|
package/dist/lib/helper/surl.js
CHANGED
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
const escapeMap = {
|
|
3
|
-
"\"": """,
|
|
4
|
-
"<": "<",
|
|
5
|
-
">": ">",
|
|
6
|
-
"'": "'"
|
|
7
|
-
};
|
|
8
|
-
function surl(val) {
|
|
9
|
-
const protocolWhiteListSet = this.app.config.security.__protocolWhiteListSet;
|
|
10
|
-
if (typeof val !== "string") return val;
|
|
11
|
-
if (val[0] !== "/") {
|
|
12
|
-
const arr = val.split("://", 2);
|
|
13
|
-
const protocol = arr.length > 1 ? arr[0].toLowerCase() : "";
|
|
14
|
-
if (protocol === "" || !protocolWhiteListSet.has(protocol)) {
|
|
15
|
-
if (this.app.config.env === "local") this.ctx.coreLogger.warn("[@eggjs/security/surl] url: %j, protocol: %j, protocol is empty or not in white list, convert to empty string", val, protocol);
|
|
16
|
-
return "";
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return val.replace(/["'<>]/g, (ch) => {
|
|
20
|
-
return escapeMap[ch];
|
|
21
|
-
});
|
|
22
|
-
}
|
|
1
|
+
import { surl } from "../../surl-ClleTea7.js";
|
|
23
2
|
|
|
24
|
-
//#endregion
|
|
25
3
|
export { surl as default };
|
|
@@ -1,46 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import "../../utils-Cajs5P8M.js";
|
|
2
|
+
import { csp_default } from "../../csp-BW5AJd_f.js";
|
|
3
3
|
|
|
4
|
-
//#region src/lib/middlewares/csp.ts
|
|
5
|
-
const HEADER = ["x-content-security-policy", "content-security-policy"];
|
|
6
|
-
const REPORT_ONLY_HEADER = ["x-content-security-policy-report-only", "content-security-policy-report-only"];
|
|
7
|
-
const MSIE_REGEXP = / MSIE /i;
|
|
8
|
-
var csp_default = (options) => {
|
|
9
|
-
return async function csp(ctx, next) {
|
|
10
|
-
await next();
|
|
11
|
-
const opts = {
|
|
12
|
-
...options,
|
|
13
|
-
...ctx.securityOptions.csp
|
|
14
|
-
};
|
|
15
|
-
if (checkIfIgnore(opts, ctx)) return;
|
|
16
|
-
let finalHeader;
|
|
17
|
-
const matchedOption = extend(true, {}, opts.policy);
|
|
18
|
-
const bufArray = [];
|
|
19
|
-
const headers = opts.reportOnly ? REPORT_ONLY_HEADER : HEADER;
|
|
20
|
-
if (opts.supportIE && MSIE_REGEXP.test(ctx.get("user-agent"))) finalHeader = headers[0];
|
|
21
|
-
else finalHeader = headers[1];
|
|
22
|
-
for (const key in matchedOption) {
|
|
23
|
-
const value = matchedOption[key];
|
|
24
|
-
if (key === "sandbox" && value === true) bufArray.push(key);
|
|
25
|
-
else {
|
|
26
|
-
let values = Array.isArray(value) ? value : [value];
|
|
27
|
-
if (key === "script-src") {
|
|
28
|
-
if (!values.some(function(val) {
|
|
29
|
-
return val.indexOf("nonce-") !== -1;
|
|
30
|
-
})) values.push("'nonce-" + ctx.nonce + "'");
|
|
31
|
-
}
|
|
32
|
-
values = values.map(function(d) {
|
|
33
|
-
if (d.startsWith(".")) d = "*" + d;
|
|
34
|
-
return d;
|
|
35
|
-
});
|
|
36
|
-
bufArray.push(key + " " + values.join(" "));
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
const headerString = bufArray.join(";");
|
|
40
|
-
ctx.set(finalHeader, headerString);
|
|
41
|
-
ctx.set("x-csp-nonce", ctx.nonce);
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
//#endregion
|
|
46
4
|
export { csp_default as default };
|
|
@@ -1,33 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import typeis from "type-is";
|
|
1
|
+
import "../../utils-Cajs5P8M.js";
|
|
2
|
+
import { csrf_default } from "../../csrf-9aSLHiby.js";
|
|
4
3
|
|
|
5
|
-
//#region src/lib/middlewares/csrf.ts
|
|
6
|
-
const debug = debuglog("egg/security/lib/middlewares/csrf");
|
|
7
|
-
var csrf_default = (options) => {
|
|
8
|
-
return function csrf(ctx, next) {
|
|
9
|
-
if (checkIfIgnore(options, ctx)) return next();
|
|
10
|
-
if ([
|
|
11
|
-
"any",
|
|
12
|
-
"all",
|
|
13
|
-
"ctoken"
|
|
14
|
-
].includes(options.type)) ctx.ensureCsrfSecret();
|
|
15
|
-
const method = ctx.method;
|
|
16
|
-
let isSupported = false;
|
|
17
|
-
for (const eachRule of options.supportedRequests) if (eachRule.path.test(ctx.path)) {
|
|
18
|
-
if (eachRule.methods.includes(method)) {
|
|
19
|
-
isSupported = true;
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (!isSupported) return next();
|
|
24
|
-
if (options.ignoreJSON && typeis.is(ctx.get("content-type"), "json")) return next();
|
|
25
|
-
const body = ctx.request.body;
|
|
26
|
-
debug("%s %s, got %j", ctx.method, ctx.url, body);
|
|
27
|
-
ctx.assertCsrf();
|
|
28
|
-
return next();
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
//#endregion
|
|
33
4
|
export { csrf_default as default };
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../../utils-Cajs5P8M.js";
|
|
2
|
+
import { dta_default } from "../../dta-DVAKEpJ3.js";
|
|
2
3
|
|
|
3
|
-
//#region src/lib/middlewares/dta.ts
|
|
4
|
-
var dta_default = () => {
|
|
5
|
-
return function dta(ctx, next) {
|
|
6
|
-
const path = ctx.path;
|
|
7
|
-
if (!isSafePath(path, ctx)) ctx.throw(400);
|
|
8
|
-
return next();
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
//#endregion
|
|
13
4
|
export { dta_default as default };
|
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../../utils-Cajs5P8M.js";
|
|
2
|
+
import { hsts_default } from "../../hsts-CWMKNTEh.js";
|
|
2
3
|
|
|
3
|
-
//#region src/lib/middlewares/hsts.ts
|
|
4
|
-
var hsts_default = (options) => {
|
|
5
|
-
return async function hsts(ctx, next) {
|
|
6
|
-
await next();
|
|
7
|
-
const opts = {
|
|
8
|
-
...options,
|
|
9
|
-
...ctx.securityOptions.hsts
|
|
10
|
-
};
|
|
11
|
-
if (checkIfIgnore(opts, ctx)) return;
|
|
12
|
-
let val = `max-age=${opts.maxAge}`;
|
|
13
|
-
if (opts.includeSubdomains) val = `${val}; includeSubdomains`;
|
|
14
|
-
ctx.set("strict-transport-security", val);
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
4
|
export { hsts_default as default };
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { SecurityConfig } from "../../config
|
|
2
|
-
import * as
|
|
1
|
+
import { SecurityConfig } from "../../config.default-D8v08Vox.js";
|
|
2
|
+
import * as egg1 from "egg";
|
|
3
3
|
|
|
4
4
|
//#region src/lib/middlewares/index.d.ts
|
|
5
5
|
declare const _default: {
|
|
6
|
-
csp: (options: SecurityConfig["csp"]) =>
|
|
7
|
-
csrf: (options: SecurityConfig["csrf"]) =>
|
|
8
|
-
dta: () =>
|
|
9
|
-
hsts: (options: SecurityConfig["hsts"]) =>
|
|
10
|
-
methodnoallow: () =>
|
|
11
|
-
noopen: (options: SecurityConfig["noopen"]) =>
|
|
12
|
-
nosniff: (options: SecurityConfig["nosniff"]) =>
|
|
13
|
-
referrerPolicy: (options: SecurityConfig["referrerPolicy"]) =>
|
|
14
|
-
xframe: (options: SecurityConfig["xframe"]) =>
|
|
15
|
-
xssProtection: (options: SecurityConfig["xssProtection"]) =>
|
|
6
|
+
csp: (options: SecurityConfig["csp"]) => egg1.MiddlewareFunc;
|
|
7
|
+
csrf: (options: SecurityConfig["csrf"]) => egg1.MiddlewareFunc;
|
|
8
|
+
dta: () => egg1.MiddlewareFunc;
|
|
9
|
+
hsts: (options: SecurityConfig["hsts"]) => egg1.MiddlewareFunc;
|
|
10
|
+
methodnoallow: () => egg1.MiddlewareFunc;
|
|
11
|
+
noopen: (options: SecurityConfig["noopen"]) => egg1.MiddlewareFunc;
|
|
12
|
+
nosniff: (options: SecurityConfig["nosniff"]) => egg1.MiddlewareFunc;
|
|
13
|
+
referrerPolicy: (options: SecurityConfig["referrerPolicy"]) => egg1.MiddlewareFunc;
|
|
14
|
+
xframe: (options: SecurityConfig["xframe"]) => egg1.MiddlewareFunc;
|
|
15
|
+
xssProtection: (options: SecurityConfig["xssProtection"]) => egg1.MiddlewareFunc;
|
|
16
16
|
};
|
|
17
17
|
//#endregion
|
|
18
18
|
export { _default as default };
|
|
@@ -1,27 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
1
|
+
import "../../utils-Cajs5P8M.js";
|
|
2
|
+
import "../../csp-BW5AJd_f.js";
|
|
3
|
+
import "../../csrf-9aSLHiby.js";
|
|
4
|
+
import "../../dta-DVAKEpJ3.js";
|
|
5
|
+
import "../../hsts-CWMKNTEh.js";
|
|
6
|
+
import "../../methodnoallow-BAZONArS.js";
|
|
7
|
+
import "../../noopen-C3jUBwoH.js";
|
|
8
|
+
import "../../nosniff-CcLkhX2I.js";
|
|
9
|
+
import "../../referrerPolicy-D4Uafq6c.js";
|
|
10
|
+
import "../../xframe-q9fEZkVI.js";
|
|
11
|
+
import "../../xssProtection-D5QsHX-e.js";
|
|
12
|
+
import { middlewares_default } from "../../middlewares-CkQjv8t0.js";
|
|
11
13
|
|
|
12
|
-
//#region src/lib/middlewares/index.ts
|
|
13
|
-
var middlewares_default = {
|
|
14
|
-
csp: csp_default,
|
|
15
|
-
csrf: csrf_default,
|
|
16
|
-
dta: dta_default,
|
|
17
|
-
hsts: hsts_default,
|
|
18
|
-
methodnoallow: methodnoallow_default,
|
|
19
|
-
noopen: noopen_default,
|
|
20
|
-
nosniff: nosniff_default,
|
|
21
|
-
referrerPolicy: referrerPolicy_default,
|
|
22
|
-
xframe: xframe_default,
|
|
23
|
-
xssProtection: xssProtection_default
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
14
|
export { middlewares_default as default };
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { methodnoallow_default } from "../../methodnoallow-BAZONArS.js";
|
|
2
2
|
|
|
3
|
-
//#region src/lib/middlewares/methodnoallow.ts
|
|
4
|
-
const METHODS_NOT_ALLOWED = ["TRACE", "TRACK"];
|
|
5
|
-
const safeHttpMethodsMap = {};
|
|
6
|
-
for (const method of METHODS) if (!METHODS_NOT_ALLOWED.includes(method)) safeHttpMethodsMap[method.toUpperCase()] = true;
|
|
7
|
-
var methodnoallow_default = () => {
|
|
8
|
-
return function notAllow(ctx, next) {
|
|
9
|
-
if (!safeHttpMethodsMap[ctx.method]) ctx.throw(405);
|
|
10
|
-
return next();
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
//#endregion
|
|
15
3
|
export { methodnoallow_default as default };
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../../utils-Cajs5P8M.js";
|
|
2
|
+
import { noopen_default } from "../../noopen-C3jUBwoH.js";
|
|
2
3
|
|
|
3
|
-
//#region src/lib/middlewares/noopen.ts
|
|
4
|
-
var noopen_default = (options) => {
|
|
5
|
-
return async function noopen(ctx, next) {
|
|
6
|
-
await next();
|
|
7
|
-
const opts = {
|
|
8
|
-
...options,
|
|
9
|
-
...ctx.securityOptions.noopen
|
|
10
|
-
};
|
|
11
|
-
if (checkIfIgnore(opts, ctx)) return;
|
|
12
|
-
ctx.set("x-download-options", "noopen");
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
4
|
export { noopen_default as default };
|
|
@@ -1,27 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../../utils-Cajs5P8M.js";
|
|
2
|
+
import { nosniff_default } from "../../nosniff-CcLkhX2I.js";
|
|
2
3
|
|
|
3
|
-
//#region src/lib/middlewares/nosniff.ts
|
|
4
|
-
const RedirectStatus = {
|
|
5
|
-
300: true,
|
|
6
|
-
301: true,
|
|
7
|
-
302: true,
|
|
8
|
-
303: true,
|
|
9
|
-
305: true,
|
|
10
|
-
307: true,
|
|
11
|
-
308: true
|
|
12
|
-
};
|
|
13
|
-
var nosniff_default = (options) => {
|
|
14
|
-
return async function nosniff(ctx, next) {
|
|
15
|
-
await next();
|
|
16
|
-
if (RedirectStatus[ctx.status]) return;
|
|
17
|
-
const opts = {
|
|
18
|
-
...options,
|
|
19
|
-
...ctx.securityOptions.nosniff
|
|
20
|
-
};
|
|
21
|
-
if (checkIfIgnore(opts, ctx)) return;
|
|
22
|
-
ctx.set("x-content-type-options", "nosniff");
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
4
|
export { nosniff_default as default };
|
|
@@ -1,31 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../../utils-Cajs5P8M.js";
|
|
2
|
+
import { referrerPolicy_default } from "../../referrerPolicy-D4Uafq6c.js";
|
|
2
3
|
|
|
3
|
-
//#region src/lib/middlewares/referrerPolicy.ts
|
|
4
|
-
const ALLOWED_POLICIES_ENUM = [
|
|
5
|
-
"no-referrer",
|
|
6
|
-
"no-referrer-when-downgrade",
|
|
7
|
-
"origin",
|
|
8
|
-
"origin-when-cross-origin",
|
|
9
|
-
"same-origin",
|
|
10
|
-
"strict-origin",
|
|
11
|
-
"strict-origin-when-cross-origin",
|
|
12
|
-
"unsafe-url",
|
|
13
|
-
""
|
|
14
|
-
];
|
|
15
|
-
var referrerPolicy_default = (options) => {
|
|
16
|
-
return async function referrerPolicy(ctx, next) {
|
|
17
|
-
await next();
|
|
18
|
-
const opts = {
|
|
19
|
-
...options,
|
|
20
|
-
...ctx.securityOptions.refererPolicy,
|
|
21
|
-
...ctx.securityOptions.referrerPolicy
|
|
22
|
-
};
|
|
23
|
-
if (checkIfIgnore(opts, ctx)) return;
|
|
24
|
-
const policy = opts.value;
|
|
25
|
-
if (!ALLOWED_POLICIES_ENUM.includes(policy)) throw new Error(`"${policy}" is not available.`);
|
|
26
|
-
ctx.set("referrer-policy", policy);
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
//#endregion
|
|
31
4
|
export { referrerPolicy_default as default };
|
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../../utils-Cajs5P8M.js";
|
|
2
|
+
import { xframe_default } from "../../xframe-q9fEZkVI.js";
|
|
2
3
|
|
|
3
|
-
//#region src/lib/middlewares/xframe.ts
|
|
4
|
-
var xframe_default = (options) => {
|
|
5
|
-
return async function xframe(ctx, next) {
|
|
6
|
-
await next();
|
|
7
|
-
const opts = {
|
|
8
|
-
...options,
|
|
9
|
-
...ctx.securityOptions.xframe
|
|
10
|
-
};
|
|
11
|
-
if (checkIfIgnore(opts, ctx)) return;
|
|
12
|
-
const value = opts.value || "SAMEORIGIN";
|
|
13
|
-
ctx.set("x-frame-options", value);
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
4
|
export { xframe_default as default };
|