@eggjs/security 5.0.0-beta.34 → 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 +22 -24
- 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
|
@@ -1,83 +1,70 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import "./context.js";
|
|
2
|
+
import { Response } from "egg";
|
|
3
|
+
|
|
4
|
+
//#region src/app/extend/response.ts
|
|
3
5
|
const unsafeRedirect = Response.prototype.redirect;
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (process.env.NODE_ENV === 'production') {
|
|
70
|
-
this.app.coreLogger.warn('[@eggjs/security/response/redirect] %s', message);
|
|
71
|
-
url = '/';
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
// Exception will be thrown out in a non-PROD env.
|
|
75
|
-
return this.ctx.throw(500, message);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
this.unsafeRedirect(url);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVzcG9uc2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXBwL2V4dGVuZC9yZXNwb25zZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsUUFBUSxFQUFFLE1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csQ0FBQyxLQUFLLENBQUMsR0FBRyxFQUFFLE9BQU8sQ0FBQyxDQUFDO29CQUN0QyxDQUFDO2dCQUNILENBQUM7WUFDSCxDQUFDO1FBQ0gsQ0FBQztRQUNELElBQUksQ0FBQyxjQUFjLENBQUMsR0FBRyxDQUFDLENBQUM7SUFDM0IsQ0FBQztDQUNGIn0=
|
|
6
|
+
var SecurityResponse = class extends Response {
|
|
7
|
+
/**
|
|
8
|
+
* This is an unsafe redirection, and we WON'T check if the
|
|
9
|
+
* destination url is safe or not.
|
|
10
|
+
* Please DO NOT use this method unless in some very special cases,
|
|
11
|
+
* otherwise there may be security vulnerabilities.
|
|
12
|
+
*
|
|
13
|
+
* @function Response#unsafeRedirect
|
|
14
|
+
* @param {String} url URL to forward
|
|
15
|
+
* @example
|
|
16
|
+
* ```js
|
|
17
|
+
* ctx.response.unsafeRedirect('http://www.domain.com');
|
|
18
|
+
* ctx.unsafeRedirect('http://www.domain.com');
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
unsafeRedirect(url, alt) {
|
|
22
|
+
unsafeRedirect.call(this, url, alt);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A safe redirection, and we'll check if the URL is in
|
|
26
|
+
* a safe domain or not.
|
|
27
|
+
* We've overridden the default Koa's implementation by adding a
|
|
28
|
+
* white list as the filter for that.
|
|
29
|
+
*
|
|
30
|
+
* @function Response#redirect
|
|
31
|
+
* @param {String} url URL to forward
|
|
32
|
+
* @example
|
|
33
|
+
* ```js
|
|
34
|
+
* ctx.response.redirect('/login');
|
|
35
|
+
* ctx.redirect('/login');
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
redirect(url, alt) {
|
|
39
|
+
url = (url || "/").trim();
|
|
40
|
+
if (url[0] === "/" && url[1] === "/") url = "/";
|
|
41
|
+
if (url[0] === "/" && url[1] !== "\\") {
|
|
42
|
+
this.unsafeRedirect(url, alt);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
let urlObject;
|
|
46
|
+
try {
|
|
47
|
+
urlObject = new URL(url);
|
|
48
|
+
} catch {
|
|
49
|
+
url = "/";
|
|
50
|
+
this.unsafeRedirect(url);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const domainWhiteList = this.app.config.security.domainWhiteList;
|
|
54
|
+
if (urlObject.protocol !== "http:" && urlObject.protocol !== "https:") url = "/";
|
|
55
|
+
else if (!urlObject.hostname) url = "/";
|
|
56
|
+
else if (domainWhiteList && domainWhiteList.length !== 0) {
|
|
57
|
+
if (!this.ctx.isSafeDomain(urlObject.hostname)) {
|
|
58
|
+
const message = `a security problem has been detected for url "${url}", redirection is prohibited.`;
|
|
59
|
+
if (process.env.NODE_ENV === "production") {
|
|
60
|
+
this.app.coreLogger.warn("[@eggjs/security/response/redirect] %s", message);
|
|
61
|
+
url = "/";
|
|
62
|
+
} else return this.ctx.throw(500, message);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
this.unsafeRedirect(url);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
export { SecurityResponse as default };
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Application, MiddlewareFunc } from "egg";
|
|
2
|
+
|
|
3
|
+
//#region src/app/middleware/securities.d.ts
|
|
2
4
|
declare const _default: (_: unknown, app: Application) => MiddlewareFunc;
|
|
3
|
-
|
|
5
|
+
//#endregion
|
|
6
|
+
export { _default as default };
|
|
@@ -1,53 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { pathMatching } from
|
|
4
|
-
import
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
app.coreLogger.warn('[@eggjs/security/middleware/securities] `options.match` and `options.ignore` are both set, using `options.match`');
|
|
37
|
-
opt.ignore = undefined;
|
|
38
|
-
}
|
|
39
|
-
if (!opt.ignore && opt.blackUrls) {
|
|
40
|
-
app.deprecate('[@eggjs/security/middleware/securities] Please use `config.security.xframe.ignore` instead, `config.security.xframe.blackUrls` will be removed very soon');
|
|
41
|
-
opt.ignore = opt.blackUrls;
|
|
42
|
-
}
|
|
43
|
-
// set matching function to security middleware options
|
|
44
|
-
opt.matching = pathMatching(opt);
|
|
45
|
-
const createMiddleware = securityMiddlewares[middlewareName];
|
|
46
|
-
const fn = createMiddleware(opt);
|
|
47
|
-
middlewares.push(fn);
|
|
48
|
-
app.coreLogger.info('[@eggjs/security/middleware/securities] use %s middleware', middlewareName);
|
|
49
|
-
});
|
|
50
|
-
app.coreLogger.info('[@eggjs/security/middleware/securities] compose %d middlewares into one security middleware', middlewares.length);
|
|
51
|
-
return compose(middlewares);
|
|
1
|
+
import middlewares_default from "../../lib/middlewares/index.js";
|
|
2
|
+
import assert from "node:assert";
|
|
3
|
+
import { pathMatching } from "@eggjs/path-matching";
|
|
4
|
+
import compose from "koa-compose";
|
|
5
|
+
|
|
6
|
+
//#region src/app/middleware/securities.ts
|
|
7
|
+
var securities_default = (_, app) => {
|
|
8
|
+
const options = app.config.security;
|
|
9
|
+
const middlewares = [];
|
|
10
|
+
const defaultMiddlewares = typeof options.defaultMiddleware === "string" ? options.defaultMiddleware.split(",").map((m) => m.trim()).filter((m) => !!m) : options.defaultMiddleware;
|
|
11
|
+
if (options.match || options.ignore) app.coreLogger.warn("[@eggjs/security/middleware/securities] Please set `match` or `ignore` on sub config");
|
|
12
|
+
const originalCookieDomain = options.csrf.cookieDomain;
|
|
13
|
+
if (originalCookieDomain && typeof originalCookieDomain !== "function") options.csrf.cookieDomain = () => originalCookieDomain;
|
|
14
|
+
defaultMiddlewares.forEach((middlewareName) => {
|
|
15
|
+
const opt = Reflect.get(options, middlewareName);
|
|
16
|
+
if (opt === false) app.coreLogger.warn("[egg-security] Please use `config.security.%s = { enable: false }` instead of `config.security.%s = false`", middlewareName, middlewareName);
|
|
17
|
+
assert(opt === false || typeof opt === "object", `config.security.${middlewareName} must be an object, or false(if you turn it off)`);
|
|
18
|
+
if (opt === false || opt && opt.enable === false) return;
|
|
19
|
+
if (middlewareName === "csrf" && opt.useSession && !app.plugins.session) throw new Error("csrf.useSession enabled, but session plugin is disabled");
|
|
20
|
+
if (opt.match && opt.ignore) {
|
|
21
|
+
app.coreLogger.warn("[@eggjs/security/middleware/securities] `options.match` and `options.ignore` are both set, using `options.match`");
|
|
22
|
+
opt.ignore = void 0;
|
|
23
|
+
}
|
|
24
|
+
if (!opt.ignore && opt.blackUrls) {
|
|
25
|
+
app.deprecate("[@eggjs/security/middleware/securities] Please use `config.security.xframe.ignore` instead, `config.security.xframe.blackUrls` will be removed very soon");
|
|
26
|
+
opt.ignore = opt.blackUrls;
|
|
27
|
+
}
|
|
28
|
+
opt.matching = pathMatching(opt);
|
|
29
|
+
const createMiddleware = middlewares_default[middlewareName];
|
|
30
|
+
const fn = createMiddleware(opt);
|
|
31
|
+
middlewares.push(fn);
|
|
32
|
+
app.coreLogger.info("[@eggjs/security/middleware/securities] use %s middleware", middlewareName);
|
|
33
|
+
});
|
|
34
|
+
app.coreLogger.info("[@eggjs/security/middleware/securities] compose %d middlewares into one security middleware", middlewares.length);
|
|
35
|
+
return compose(middlewares);
|
|
52
36
|
};
|
|
53
|
-
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { securities_default as default };
|
package/dist/app.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Application, ILifecycleBoot } from "egg";
|
|
2
|
+
|
|
3
|
+
//#region src/app.d.ts
|
|
4
|
+
declare class AppBoot implements ILifecycleBoot {
|
|
5
|
+
private readonly app;
|
|
6
|
+
constructor(app: Application);
|
|
7
|
+
configWillLoad(): void;
|
|
6
8
|
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { AppBoot as default };
|
package/dist/app.js
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
import { preprocessConfig } from "./lib/utils.js";
|
|
2
2
|
import { SecurityConfig } from "./config/config.default.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2FwcC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxnQkFBZ0IsQ0FBQztBQUNsRCxPQUFPLEVBQUUsY0FBYyxFQUFFLE1BQU0sNEJBQTRCLENBQUM7QUFFNUQsTUFBTSxDQUFDLE9BQU8sT0FBTyxPQUFPO0lBQ1QsR0FBRyxDQUFDO0lBRXJCLFlBQVksR0FBZ0I7UUFDMUIsSUFBSSxDQUFDLEdBQUcsR0FBRyxHQUFHLENBQUM7SUFDakIsQ0FBQztJQUVELGNBQWM7UUFDWixNQUFNLEdBQUcsR0FBRyxJQUFJLENBQUMsR0FBRyxDQUFDO1FBQ3JCLEdBQUcsQ0FBQyxNQUFNLENBQUMsY0FBYyxDQUFDLElBQUksQ0FBQyxZQUFZLENBQUMsQ0FBQztRQUM3Qyw0Q0FBNEM7UUFDNUMsTUFBTSxNQUFNLEdBQUcsY0FBYyxDQUFDLEtBQUssQ0FBQyxHQUFHLENBQUMsTUFBTSxDQUFDLFFBQVEsQ0FBQyxDQUFDO1FBQ3pELElBQUksT0FBTyxHQUFHLENBQUMsTUFBTSxDQUFDLFFBQVEsQ0FBQyxJQUFJLEtBQUssU0FBUyxFQUFFLENBQUM7WUFDbEQscURBQXFEO1lBQ3JELEdBQUcsQ0FBQyxNQUFNLENBQUMsUUFBUSxDQUFDLElBQUksR0FBRyxNQUFNLENBQUMsSUFBSSxDQUFDO1FBQ3pDLENBQUM7UUFFRCxJQUFJLEdBQUcsQ0FBQyxNQUFNLENBQUMsUUFBUSxDQUFDLElBQUksQ0FBQyxNQUFNLEVBQUUsQ0FBQztZQUNwQyxNQUFNLEVBQUUsVUFBVSxFQUFFLEdBQUcsR0FBRyxDQUFDLE1BQU0sQ0FBQyxRQUFRLENBQUMsSUFBSSxDQUFDO1lBQ2hELElBQUksVUFBVSxFQUFFLENBQUM7Z0JBQ2YsR0FBRyxDQUFDLFNBQVMsQ0FBQyw2RkFBNkYsQ0FBQyxDQUFDO1lBQy9HLENBQUM7UUFDSCxDQUFDO1FBRUQsZ0JBQWdCLENBQUMsR0FBRyxDQUFDLE1BQU0sQ0FBQyxRQUFRLENBQUMsQ0FBQztJQUN4QyxDQUFDO0NBQ0YifQ==
|
|
3
|
+
|
|
4
|
+
//#region src/app.ts
|
|
5
|
+
var AppBoot = class {
|
|
6
|
+
app;
|
|
7
|
+
constructor(app) {
|
|
8
|
+
this.app = app;
|
|
9
|
+
}
|
|
10
|
+
configWillLoad() {
|
|
11
|
+
const app = this.app;
|
|
12
|
+
app.config.coreMiddleware.push("securities");
|
|
13
|
+
const parsed = SecurityConfig.parse(app.config.security);
|
|
14
|
+
if (typeof app.config.security.csrf === "boolean") app.config.security.csrf = parsed.csrf;
|
|
15
|
+
if (app.config.security.csrf.enable) {
|
|
16
|
+
const { ignoreJSON } = app.config.security.csrf;
|
|
17
|
+
if (ignoreJSON) app.deprecate("[@eggjs/security/app] `config.security.csrf.ignoreJSON` is not safe now, please disable it.");
|
|
18
|
+
}
|
|
19
|
+
preprocessConfig(app.config.security);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { AppBoot as default };
|
|
@@ -1,59 +1,48 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { Context } from "egg";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/config/config.default.d.ts
|
|
3
5
|
declare const CSRFSupportRequestItem: z.ZodObject<{
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
path: z.ZodType<RegExp>;
|
|
7
|
+
methods: z.ZodArray<z.ZodString>;
|
|
6
8
|
}>;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
type CSRFSupportRequestItem = z.infer<typeof CSRFSupportRequestItem>;
|
|
10
|
+
declare const LookupAddress: z.ZodObject<{
|
|
11
|
+
address: z.ZodString;
|
|
12
|
+
family: z.ZodNumber;
|
|
11
13
|
}>;
|
|
12
|
-
|
|
14
|
+
type LookupAddress = z.infer<typeof LookupAddress>;
|
|
13
15
|
declare const LookupAddressAndStringArray: z.ZodArray<z.ZodUnion<[z.ZodString, typeof LookupAddress]>>;
|
|
14
|
-
declare const SSRFCheckAddressFunction: z.ZodFunction<z.ZodTuple<[
|
|
15
|
-
z.ZodUnion<[z.ZodString, typeof LookupAddress, typeof LookupAddressAndStringArray]>,
|
|
16
|
-
z.ZodUnion<[z.ZodNumber, z.ZodString]>,
|
|
17
|
-
z.ZodString
|
|
18
|
-
], z.ZodUnknown>, z.ZodBoolean>;
|
|
16
|
+
declare const SSRFCheckAddressFunction: z.ZodFunction<z.ZodTuple<[z.ZodUnion<[z.ZodString, typeof LookupAddress, typeof LookupAddressAndStringArray]>, z.ZodUnion<[z.ZodNumber, z.ZodString]>, z.ZodString], z.ZodUnknown>, z.ZodBoolean>;
|
|
19
17
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
'hsts',
|
|
27
|
-
'methodnoallow',
|
|
28
|
-
'noopen',
|
|
29
|
-
'nosniff',
|
|
30
|
-
'csp',
|
|
31
|
-
'xssProtection',
|
|
32
|
-
'xframe',
|
|
33
|
-
'dta'
|
|
34
|
-
]>;
|
|
35
|
-
export type SecurityMiddlewareName = z.infer<typeof SecurityMiddlewareName>;
|
|
18
|
+
* SSRF check address function
|
|
19
|
+
* `(address, family, hostname) => boolean`
|
|
20
|
+
*/
|
|
21
|
+
type SSRFCheckAddressFunction = z.infer<typeof SSRFCheckAddressFunction>;
|
|
22
|
+
declare const SecurityMiddlewareName: z.ZodEnum<["csrf", "hsts", "methodnoallow", "noopen", "nosniff", "csp", "xssProtection", "xframe", "dta"]>;
|
|
23
|
+
type SecurityMiddlewareName = z.infer<typeof SecurityMiddlewareName>;
|
|
36
24
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
25
|
+
* (ctx) => boolean
|
|
26
|
+
*/
|
|
39
27
|
declare const IgnoreOrMatchHandler: z.ZodFunction<z.ZodTuple<[z.ZodType<Context>], z.ZodUnknown>, z.ZodBoolean>;
|
|
40
|
-
|
|
28
|
+
type IgnoreOrMatchHandler = z.infer<typeof IgnoreOrMatchHandler>;
|
|
41
29
|
declare const IgnoreOrMatch: z.ZodUnion<[z.ZodString, z.ZodType<RegExp>, typeof IgnoreOrMatchHandler]>;
|
|
42
|
-
|
|
30
|
+
type IgnoreOrMatch = z.infer<typeof IgnoreOrMatch>;
|
|
43
31
|
declare const IgnoreOrMatchOption: z.ZodOptional<z.ZodUnion<[typeof IgnoreOrMatch, z.ZodArray<typeof IgnoreOrMatch>]>>;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
32
|
+
type IgnoreOrMatchOption = z.infer<typeof IgnoreOrMatchOption>;
|
|
33
|
+
declare const SecurityConfig: z.ZodObject<any>;
|
|
34
|
+
type SecurityConfig = z.infer<typeof SecurityConfig>;
|
|
47
35
|
declare const SecurityHelperOnTagAttrHandler: z.ZodFunction<z.ZodTuple<[z.ZodString, z.ZodString, z.ZodString, z.ZodBoolean], z.ZodUnknown>, z.ZodUnion<[z.ZodString, z.ZodVoid]>>;
|
|
48
36
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
37
|
+
* (tag: string, name: string, value: string, isWhiteAttr: boolean) => string | void
|
|
38
|
+
*/
|
|
39
|
+
type SecurityHelperOnTagAttrHandler = z.infer<typeof SecurityHelperOnTagAttrHandler>;
|
|
40
|
+
declare const SecurityHelperConfig: z.ZodObject<any>;
|
|
41
|
+
type SecurityHelperConfig = z.infer<typeof SecurityHelperConfig>;
|
|
54
42
|
interface PluginConfig {
|
|
55
|
-
|
|
56
|
-
|
|
43
|
+
security: SecurityConfig;
|
|
44
|
+
helper: SecurityHelperConfig;
|
|
57
45
|
}
|
|
58
46
|
declare const config: PluginConfig;
|
|
59
|
-
|
|
47
|
+
//#endregion
|
|
48
|
+
export { CSRFSupportRequestItem, IgnoreOrMatch, IgnoreOrMatchHandler, IgnoreOrMatchOption, LookupAddress, SSRFCheckAddressFunction, SecurityConfig, SecurityHelperConfig, SecurityHelperOnTagAttrHandler, SecurityMiddlewareName, config as default };
|