@eggjs/security 5.0.0-beta.35 → 5.0.0-beta.36
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.d.ts +9 -5
- package/dist/agent.js +14 -10
- package/dist/app/extend/agent.d.ts +8 -4
- package/dist/app/extend/agent.js +12 -8
- package/dist/app/extend/application.d.ts +11 -7
- package/dist/app/extend/application.js +32 -32
- package/dist/app/extend/context.d.ts +55 -51
- package/dist/app/extend/context.js +185 -240
- package/dist/app/extend/helper.d.ts +5 -2
- package/dist/app/extend/helper.js +8 -6
- package/dist/app/extend/response.d.ts +38 -34
- package/dist/app/extend/response.js +69 -82
- package/dist/app/middleware/securities.d.ts +5 -2
- package/dist/app/middleware/securities.js +38 -52
- package/dist/app.d.ts +9 -5
- package/dist/app.js +23 -25
- package/dist/config/config.default.d.ts +34 -45
- package/dist/config/config.default.js +158 -362
- package/dist/config/config.local.d.ts +6 -3
- package/dist/config/config.local.js +6 -8
- package/dist/index.d.ts +20 -16
- package/dist/index.js +24 -21
- package/dist/lib/extend/safe_curl.d.ts +16 -13
- package/dist/lib/extend/safe_curl.js +17 -23
- package/dist/lib/helper/cliFilter.d.ts +4 -4
- package/dist/lib/helper/cliFilter.js +16 -15
- package/dist/lib/helper/escape.d.ts +2 -2
- package/dist/lib/helper/escape.js +7 -3
- package/dist/lib/helper/escapeShellArg.d.ts +4 -1
- package/dist/lib/helper/escapeShellArg.js +6 -4
- package/dist/lib/helper/escapeShellCmd.d.ts +4 -1
- package/dist/lib/helper/escapeShellCmd.js +14 -13
- package/dist/lib/helper/index.d.ts +22 -19
- package/dist/lib/helper/index.js +19 -15
- package/dist/lib/helper/shtml.d.ts +6 -2
- package/dist/lib/helper/shtml.js +52 -68
- package/dist/lib/helper/sjs.d.ts +4 -4
- package/dist/lib/helper/sjs.js +31 -44
- package/dist/lib/helper/sjson.d.ts +4 -1
- package/dist/lib/helper/sjson.js +28 -35
- package/dist/lib/helper/spath.d.ts +7 -5
- package/dist/lib/helper/spath.js +15 -24
- package/dist/lib/helper/surl.d.ts +6 -2
- package/dist/lib/helper/surl.js +22 -27
- package/dist/lib/middlewares/csp.d.ts +6 -3
- package/dist/lib/middlewares/csp.js +43 -54
- package/dist/lib/middlewares/csrf.d.ts +6 -3
- package/dist/lib/middlewares/csrf.js +31 -35
- package/dist/lib/middlewares/dta.d.ts +5 -2
- package/dist/lib/middlewares/dta.js +11 -10
- package/dist/lib/middlewares/hsts.d.ts +6 -3
- package/dist/lib/middlewares/hsts.js +17 -19
- package/dist/lib/middlewares/index.d.ts +24 -21
- package/dist/lib/middlewares/index.js +26 -22
- package/dist/lib/middlewares/methodnoallow.d.ts +5 -2
- package/dist/lib/middlewares/methodnoallow.js +13 -18
- package/dist/lib/middlewares/noopen.d.ts +6 -3
- package/dist/lib/middlewares/noopen.js +14 -13
- package/dist/lib/middlewares/nosniff.d.ts +6 -3
- package/dist/lib/middlewares/nosniff.js +22 -24
- package/dist/lib/middlewares/referrerPolicy.d.ts +6 -3
- package/dist/lib/middlewares/referrerPolicy.js +27 -30
- package/dist/lib/middlewares/xframe.d.ts +6 -3
- package/dist/lib/middlewares/xframe.js +16 -15
- package/dist/lib/middlewares/xssProtection.d.ts +6 -3
- package/dist/lib/middlewares/xssProtection.js +15 -12
- package/dist/lib/utils.d.ts +22 -17
- package/dist/lib/utils.js +112 -177
- package/dist/types.d.ts +38 -36
- package/dist/types.js +1 -2
- package/package.json +31 -37
package/dist/lib/helper/spath.js
CHANGED
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
14
|
-
// Not a PROD env, logging with a warning.
|
|
15
|
-
this.ctx.coreLogger.warn('[@eggjs/security/lib/helper/spath] : decode file path %j failed.', path);
|
|
16
|
-
}
|
|
17
|
-
break;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
if (path.indexOf('..') !== -1 || path[0] === '/') {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
return pathSource;
|
|
1
|
+
//#region src/lib/helper/spath.ts
|
|
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;
|
|
24
13
|
}
|
|
25
|
-
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { pathFilter as default };
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { BaseContextClass } from "egg";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/helper/surl.d.ts
|
|
4
|
+
declare function surl(this: BaseContextClass, val: string): string;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { surl as default };
|
package/dist/lib/helper/surl.js
CHANGED
|
@@ -1,30 +1,25 @@
|
|
|
1
|
+
//#region src/lib/helper/surl.ts
|
|
1
2
|
const escapeMap = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
"\"": """,
|
|
4
|
+
"<": "<",
|
|
5
|
+
">": ">",
|
|
6
|
+
"'": "'"
|
|
6
7
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
'protocol is empty or not in white list, convert to empty string', val, protocol);
|
|
22
|
-
}
|
|
23
|
-
return '';
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return val.replace(/["'<>]/g, (ch) => {
|
|
27
|
-
return escapeMap[ch];
|
|
28
|
-
});
|
|
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
|
+
});
|
|
29
22
|
}
|
|
30
|
-
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { surl as default };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { SecurityConfig } from "../../config/config.default.js";
|
|
2
|
+
import { MiddlewareFunc } from "egg";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/middlewares/csp.d.ts
|
|
3
5
|
declare const _default: (options: SecurityConfig["csp"]) => MiddlewareFunc;
|
|
4
|
-
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _default as default };
|
|
@@ -1,57 +1,46 @@
|
|
|
1
|
-
import extend from 'extend';
|
|
2
1
|
import { checkIfIgnore } from "../utils.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import extend from "extend";
|
|
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"];
|
|
6
7
|
const MSIE_REGEXP = / MSIE /i;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
values = values.map(function (d) {
|
|
44
|
-
if (d.startsWith('.')) {
|
|
45
|
-
d = '*' + d;
|
|
46
|
-
}
|
|
47
|
-
return d;
|
|
48
|
-
});
|
|
49
|
-
bufArray.push(key + ' ' + values.join(' '));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
const headerString = bufArray.join(';');
|
|
53
|
-
ctx.set(finalHeader, headerString);
|
|
54
|
-
ctx.set('x-csp-nonce', ctx.nonce);
|
|
55
|
-
};
|
|
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
|
+
};
|
|
56
43
|
};
|
|
57
|
-
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { csp_default as default };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { SecurityConfig } from "../../config/config.default.js";
|
|
2
|
+
import { MiddlewareFunc } from "egg";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/middlewares/csrf.d.ts
|
|
3
5
|
declare const _default: (options: SecurityConfig["csrf"]) => MiddlewareFunc;
|
|
4
|
-
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _default as default };
|
|
@@ -1,37 +1,33 @@
|
|
|
1
|
-
import { debuglog } from 'node:util';
|
|
2
|
-
import typeis from 'type-is';
|
|
3
1
|
import { checkIfIgnore } from "../utils.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
debug('%s %s, got %j', ctx.method, ctx.url, body);
|
|
33
|
-
ctx.assertCsrf();
|
|
34
|
-
return next();
|
|
35
|
-
};
|
|
2
|
+
import { debuglog } from "node:util";
|
|
3
|
+
import typeis from "type-is";
|
|
4
|
+
|
|
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
|
+
};
|
|
36
30
|
};
|
|
37
|
-
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { csrf_default as default };
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { isSafePath } from "../utils.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
2
|
+
|
|
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
|
+
};
|
|
11
10
|
};
|
|
12
|
-
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { dta_default as default };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { SecurityConfig } from "../../config/config.default.js";
|
|
2
|
+
import { MiddlewareFunc } from "egg";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/middlewares/hsts.d.ts
|
|
3
5
|
declare const _default: (options: SecurityConfig["hsts"]) => MiddlewareFunc;
|
|
4
|
-
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _default as default };
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { checkIfIgnore } from "../utils.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
val = `${val}; includeSubdomains`;
|
|
17
|
-
}
|
|
18
|
-
ctx.set('strict-transport-security', val);
|
|
19
|
-
};
|
|
2
|
+
|
|
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
|
+
};
|
|
20
16
|
};
|
|
21
|
-
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { hsts_default as default };
|
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
1
|
+
import _default from "./csp.js";
|
|
2
|
+
import _default$1 from "./csrf.js";
|
|
3
|
+
import _default$2 from "./dta.js";
|
|
4
|
+
import _default$3 from "./hsts.js";
|
|
5
|
+
import _default$4 from "./methodnoallow.js";
|
|
6
|
+
import _default$5 from "./noopen.js";
|
|
7
|
+
import _default$6 from "./nosniff.js";
|
|
8
|
+
import _default$7 from "./referrerPolicy.js";
|
|
9
|
+
import _default$8 from "./xframe.js";
|
|
10
|
+
import _default$9 from "./xssProtection.js";
|
|
11
|
+
|
|
12
|
+
//#region src/lib/middlewares/index.d.ts
|
|
11
13
|
declare const middlewares: {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
csp: typeof _default;
|
|
15
|
+
csrf: typeof _default$1;
|
|
16
|
+
dta: typeof _default$2;
|
|
17
|
+
hsts: typeof _default$3;
|
|
18
|
+
methodnoallow: typeof _default$4;
|
|
19
|
+
noopen: typeof _default$5;
|
|
20
|
+
nosniff: typeof _default$6;
|
|
21
|
+
referrerPolicy: typeof _default$7;
|
|
22
|
+
xframe: typeof _default$8;
|
|
23
|
+
xssProtection: typeof _default$9;
|
|
22
24
|
};
|
|
23
|
-
|
|
25
|
+
//#endregion
|
|
26
|
+
export { middlewares as default };
|
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
1
|
+
import csp_default from "./csp.js";
|
|
2
|
+
import csrf_default from "./csrf.js";
|
|
3
|
+
import dta_default from "./dta.js";
|
|
4
|
+
import hsts_default from "./hsts.js";
|
|
5
|
+
import methodnoallow_default from "./methodnoallow.js";
|
|
6
|
+
import noopen_default from "./noopen.js";
|
|
7
|
+
import nosniff_default from "./nosniff.js";
|
|
8
|
+
import referrerPolicy_default from "./referrerPolicy.js";
|
|
9
|
+
import xframe_default from "./xframe.js";
|
|
10
|
+
import xssProtection_default from "./xssProtection.js";
|
|
11
|
+
|
|
12
|
+
//#region src/lib/middlewares/index.ts
|
|
11
13
|
const middlewares = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
22
24
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
var middlewares_default = middlewares;
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { middlewares_default as default };
|
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import { METHODS } from
|
|
2
|
-
|
|
1
|
+
import { METHODS } from "node:http";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/middlewares/methodnoallow.ts
|
|
4
|
+
const METHODS_NOT_ALLOWED = ["TRACE", "TRACK"];
|
|
3
5
|
const safeHttpMethodsMap = {};
|
|
4
|
-
for (const method of METHODS)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// http://jsperf.com/find-by-map-with-find-by-array
|
|
11
|
-
export default () => {
|
|
12
|
-
return function notAllow(ctx, next) {
|
|
13
|
-
// ctx.method is upper case
|
|
14
|
-
if (!safeHttpMethodsMap[ctx.method]) {
|
|
15
|
-
ctx.throw(405);
|
|
16
|
-
}
|
|
17
|
-
return next();
|
|
18
|
-
};
|
|
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
|
+
};
|
|
19
12
|
};
|
|
20
|
-
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { methodnoallow_default as default };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { SecurityConfig } from "../../config/config.default.js";
|
|
2
|
+
import { MiddlewareFunc } from "egg";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/middlewares/noopen.d.ts
|
|
3
5
|
declare const _default: (options: SecurityConfig["noopen"]) => MiddlewareFunc;
|
|
4
|
-
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _default as default };
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { checkIfIgnore } from "../utils.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
2
|
+
|
|
3
|
+
//#region src/lib/middlewares/noopen.ts
|
|
4
|
+
var noopen_default = (options) => {
|
|
5
|
+
return async function noopen(ctx, next) {
|
|
6
|
+
await next();
|
|
7
|
+
if (checkIfIgnore({
|
|
8
|
+
...options,
|
|
9
|
+
...ctx.securityOptions.noopen
|
|
10
|
+
}, ctx)) return;
|
|
11
|
+
ctx.set("x-download-options", "noopen");
|
|
12
|
+
};
|
|
14
13
|
};
|
|
15
|
-
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { noopen_default as default };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { SecurityConfig } from "../../config/config.default.js";
|
|
2
|
+
import { MiddlewareFunc } from "egg";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/middlewares/nosniff.d.ts
|
|
3
5
|
declare const _default: (options: SecurityConfig["nosniff"]) => MiddlewareFunc;
|
|
4
|
-
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _default as default };
|