@eggjs/security 5.0.0-beta.15 → 5.0.0-beta.18
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/app/extend/agent.d.ts +0 -5
- package/dist/app/extend/application.d.ts +0 -8
- package/dist/app/extend/context.d.ts +2 -15
- package/dist/app/extend/response.d.ts +0 -6
- package/dist/app/middleware/securities.d.ts +2 -2
- package/dist/config/config.default.d.ts +6 -10
- package/dist/config/config.default.js +0 -4
- package/dist/index.js +3 -1
- package/dist/lib/extend/safe_curl.d.ts +2 -2
- package/dist/lib/middlewares/index.d.ts +11 -11
- package/dist/types.d.ts +31 -5
- package/dist/types.js +0 -4
- package/package.json +6 -6
|
@@ -5,10 +5,5 @@ import { Agent } from "egg";
|
|
|
5
5
|
declare class SecurityAgent extends Agent {
|
|
6
6
|
safeCurl<T = any>(url: HttpClientRequestURL, options?: HttpClientOptions): Promise<HttpClientResponse<T>>;
|
|
7
7
|
}
|
|
8
|
-
declare module 'egg' {
|
|
9
|
-
interface Agent {
|
|
10
|
-
safeCurl<T = any>(url: HttpClientRequestURL, options?: HttpClientOptions): Promise<HttpClientResponse<T>>;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
8
|
//#endregion
|
|
14
9
|
export { SecurityAgent as default };
|
|
@@ -8,13 +8,5 @@ declare class SecurityApplication extends Application {
|
|
|
8
8
|
injectHijackingDefense(html: string): string;
|
|
9
9
|
safeCurl<T = any>(url: HttpClientRequestURL, options?: HttpClientOptions): Promise<HttpClientResponse<T>>;
|
|
10
10
|
}
|
|
11
|
-
declare module 'egg' {
|
|
12
|
-
interface Application {
|
|
13
|
-
injectCsrf(html: string): string;
|
|
14
|
-
injectNonce(html: string): string;
|
|
15
|
-
injectHijackingDefense(html: string): string;
|
|
16
|
-
safeCurl<T = any>(url: HttpClientRequestURL, options?: HttpClientOptions): Promise<HttpClientResponse<T>>;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
11
|
//#endregion
|
|
20
12
|
export { SecurityApplication as default };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { SecurityConfig, SecurityHelperConfig } from "../../config/config.default.js";
|
|
1
|
+
import { SecurityConfig } from "../../config/config.default.js";
|
|
3
2
|
import { HttpClientOptions, HttpClientRequestURL, HttpClientResponse } from "../../lib/extend/safe_curl.js";
|
|
3
|
+
import SecurityResponse from "./response.js";
|
|
4
4
|
import { Context } from "egg";
|
|
5
5
|
|
|
6
6
|
//#region src/app/extend/context.d.ts
|
|
@@ -57,18 +57,5 @@ declare class SecurityContext extends Context {
|
|
|
57
57
|
safeCurl<T = any>(url: HttpClientRequestURL, options?: HttpClientOptions): Promise<HttpClientResponse<T>>;
|
|
58
58
|
unsafeRedirect(url: string, alt?: string): void;
|
|
59
59
|
}
|
|
60
|
-
declare module 'egg' {
|
|
61
|
-
interface Context {
|
|
62
|
-
get securityOptions(): Partial<SecurityConfig & SecurityHelperConfig>;
|
|
63
|
-
isSafeDomain(domain: string, customWhiteList?: string[]): boolean;
|
|
64
|
-
get nonce(): string;
|
|
65
|
-
get csrf(): string;
|
|
66
|
-
ensureCsrfSecret(rotate?: boolean): void;
|
|
67
|
-
rotateCsrfSecret(): void;
|
|
68
|
-
assertCsrf(): void;
|
|
69
|
-
safeCurl<T = any>(url: HttpClientRequestURL, options?: HttpClientOptions): Promise<HttpClientResponse<T>>;
|
|
70
|
-
unsafeRedirect(url: string, alt?: string): void;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
60
|
//#endregion
|
|
74
61
|
export { SecurityContext as default };
|
|
@@ -35,11 +35,5 @@ declare class SecurityResponse extends Response {
|
|
|
35
35
|
*/
|
|
36
36
|
redirect(url: string, alt?: string): void;
|
|
37
37
|
}
|
|
38
|
-
declare module 'egg' {
|
|
39
|
-
interface Response {
|
|
40
|
-
unsafeRedirect(url: string, alt?: string): void;
|
|
41
|
-
redirect(url: string, alt?: string): void;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
38
|
//#endregion
|
|
45
39
|
export { SecurityResponse as default };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as egg0 from "egg";
|
|
2
2
|
import { Application } from "egg";
|
|
3
3
|
import compose from "koa-compose";
|
|
4
4
|
|
|
5
5
|
//#region src/app/middleware/securities.d.ts
|
|
6
|
-
declare const _default: (_: unknown, app: Application) => compose.ComposedMiddleware<
|
|
6
|
+
declare const _default: (_: unknown, app: Application) => compose.ComposedMiddleware<egg0.Context>;
|
|
7
7
|
//#endregion
|
|
8
8
|
export { _default as default };
|
|
@@ -59,10 +59,6 @@ declare const IgnoreOrMatch: z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTyp
|
|
|
59
59
|
type IgnoreOrMatch = z.infer<typeof IgnoreOrMatch>;
|
|
60
60
|
declare const IgnoreOrMatchOption: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>, z.ZodFunction<z.ZodTuple<[z.ZodType<Context, z.ZodTypeDef, Context>], z.ZodUnknown>, z.ZodBoolean>]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>, z.ZodFunction<z.ZodTuple<[z.ZodType<Context, z.ZodTypeDef, Context>], z.ZodUnknown>, z.ZodBoolean>]>, "many">]>>;
|
|
61
61
|
type IgnoreOrMatchOption = z.infer<typeof IgnoreOrMatchOption>;
|
|
62
|
-
/**
|
|
63
|
-
* security options
|
|
64
|
-
* @member Config#security
|
|
65
|
-
*/
|
|
66
62
|
declare const SecurityConfig: z.ZodObject<{
|
|
67
63
|
/**
|
|
68
64
|
* domain white list
|
|
@@ -549,8 +545,6 @@ declare const SecurityConfig: z.ZodObject<{
|
|
|
549
545
|
ignore: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>, z.ZodFunction<z.ZodTuple<[z.ZodType<Context, z.ZodTypeDef, Context>], z.ZodUnknown>, z.ZodBoolean>]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>, z.ZodFunction<z.ZodTuple<[z.ZodType<Context, z.ZodTypeDef, Context>], z.ZodUnknown>, z.ZodBoolean>]>, "many">]>>;
|
|
550
546
|
__protocolWhiteListSet: z.ZodReadonly<z.ZodOptional<z.ZodSet<z.ZodString>>>;
|
|
551
547
|
}, "strip", z.ZodTypeAny, {
|
|
552
|
-
domainWhiteList: string[];
|
|
553
|
-
protocolWhiteList: string[];
|
|
554
548
|
csrf: {
|
|
555
549
|
type: "ctoken" | "referer" | "all" | "any";
|
|
556
550
|
enable: boolean;
|
|
@@ -623,6 +617,8 @@ declare const SecurityConfig: z.ZodObject<{
|
|
|
623
617
|
match?: string | RegExp | ((args_0: Context, ...args: unknown[]) => boolean) | (string | RegExp | ((args_0: Context, ...args: unknown[]) => boolean))[] | undefined;
|
|
624
618
|
ignore?: string | RegExp | ((args_0: Context, ...args: unknown[]) => boolean) | (string | RegExp | ((args_0: Context, ...args: unknown[]) => boolean))[] | undefined;
|
|
625
619
|
};
|
|
620
|
+
domainWhiteList: string[];
|
|
621
|
+
protocolWhiteList: string[];
|
|
626
622
|
defaultMiddleware: string | ("csrf" | "hsts" | "methodnoallow" | "noopen" | "nosniff" | "csp" | "xssProtection" | "xframe" | "dta")[];
|
|
627
623
|
referrerPolicy: {
|
|
628
624
|
value: string;
|
|
@@ -646,8 +642,6 @@ declare const SecurityConfig: z.ZodObject<{
|
|
|
646
642
|
ignore?: string | RegExp | ((args_0: Context, ...args: unknown[]) => boolean) | (string | RegExp | ((args_0: Context, ...args: unknown[]) => boolean))[] | undefined;
|
|
647
643
|
__protocolWhiteListSet?: ReadonlySet<string> | undefined;
|
|
648
644
|
}, {
|
|
649
|
-
domainWhiteList?: string[] | undefined;
|
|
650
|
-
protocolWhiteList?: string[] | undefined;
|
|
651
645
|
csrf?: unknown;
|
|
652
646
|
hsts?: {
|
|
653
647
|
match?: string | RegExp | ((args_0: Context, ...args: unknown[]) => boolean) | (string | RegExp | ((args_0: Context, ...args: unknown[]) => boolean))[] | undefined;
|
|
@@ -696,6 +690,8 @@ declare const SecurityConfig: z.ZodObject<{
|
|
|
696
690
|
ignore?: string | RegExp | ((args_0: Context, ...args: unknown[]) => boolean) | (string | RegExp | ((args_0: Context, ...args: unknown[]) => boolean))[] | undefined;
|
|
697
691
|
enable?: boolean | undefined;
|
|
698
692
|
} | undefined;
|
|
693
|
+
domainWhiteList?: string[] | undefined;
|
|
694
|
+
protocolWhiteList?: string[] | undefined;
|
|
699
695
|
defaultMiddleware?: string | ("csrf" | "hsts" | "methodnoallow" | "noopen" | "nosniff" | "csp" | "xssProtection" | "xframe" | "dta")[] | undefined;
|
|
700
696
|
match?: string | RegExp | ((args_0: Context, ...args: unknown[]) => boolean) | (string | RegExp | ((args_0: Context, ...args: unknown[]) => boolean))[] | undefined;
|
|
701
697
|
ignore?: string | RegExp | ((args_0: Context, ...args: unknown[]) => boolean) | (string | RegExp | ((args_0: Context, ...args: unknown[]) => boolean))[] | undefined;
|
|
@@ -765,8 +761,6 @@ declare const SecurityHelperConfig: z.ZodObject<{
|
|
|
765
761
|
type SecurityHelperConfig = z.infer<typeof SecurityHelperConfig>;
|
|
766
762
|
declare const _default: {
|
|
767
763
|
security: {
|
|
768
|
-
domainWhiteList: string[];
|
|
769
|
-
protocolWhiteList: string[];
|
|
770
764
|
csrf: {
|
|
771
765
|
type: "ctoken" | "referer" | "all" | "any";
|
|
772
766
|
enable: boolean;
|
|
@@ -839,6 +833,8 @@ declare const _default: {
|
|
|
839
833
|
match?: string | RegExp | ((args_0: Context, ...args: unknown[]) => boolean) | (string | RegExp | ((args_0: Context, ...args: unknown[]) => boolean))[] | undefined;
|
|
840
834
|
ignore?: string | RegExp | ((args_0: Context, ...args: unknown[]) => boolean) | (string | RegExp | ((args_0: Context, ...args: unknown[]) => boolean))[] | undefined;
|
|
841
835
|
};
|
|
836
|
+
domainWhiteList: string[];
|
|
837
|
+
protocolWhiteList: string[];
|
|
842
838
|
defaultMiddleware: string | ("csrf" | "hsts" | "methodnoallow" | "noopen" | "nosniff" | "csp" | "xssProtection" | "xframe" | "dta")[];
|
|
843
839
|
referrerPolicy: {
|
|
844
840
|
value: string;
|
|
@@ -37,10 +37,6 @@ const IgnoreOrMatch = z.union([
|
|
|
37
37
|
IgnoreOrMatchHandler
|
|
38
38
|
]);
|
|
39
39
|
const IgnoreOrMatchOption = z.union([IgnoreOrMatch, IgnoreOrMatch.array()]).optional();
|
|
40
|
-
/**
|
|
41
|
-
* security options
|
|
42
|
-
* @member Config#security
|
|
43
|
-
*/
|
|
44
40
|
const SecurityConfig = z.object({
|
|
45
41
|
domainWhiteList: z.array(z.string()).default([]),
|
|
46
42
|
protocolWhiteList: z.array(z.string()).default([]),
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SSRFCheckAddressFunction } from "../../config/config.default.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as egg0 from "egg";
|
|
3
3
|
import { EggApplicationCore } from "egg";
|
|
4
4
|
|
|
5
5
|
//#region src/lib/extend/safe_curl.d.ts
|
|
@@ -15,6 +15,6 @@ type HttpClientResponse<T = any> = Awaited<ReturnType<HttpClient['prototype']['r
|
|
|
15
15
|
/**
|
|
16
16
|
* safe curl with ssrf protection
|
|
17
17
|
*/
|
|
18
|
-
declare function safeCurlForApplication<T = any>(app: EggApplicationCore, url: HttpClientRequestURL, options?: HttpClientOptions): Promise<
|
|
18
|
+
declare function safeCurlForApplication<T = any>(app: EggApplicationCore, url: HttpClientRequestURL, options?: HttpClientOptions): Promise<egg0.HttpClientResponse<T>>;
|
|
19
19
|
//#endregion
|
|
20
20
|
export { HttpClientOptions, HttpClientRequestURL, HttpClientResponse, safeCurlForApplication };
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { SecurityConfig } from "../../config/config.default.js";
|
|
2
|
-
import * as
|
|
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 };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SecurityConfig, SecurityHelperConfig } from "./config/config.default.js";
|
|
2
|
+
import { HttpClientOptions, HttpClientRequestURL, HttpClientResponse } from "./lib/extend/safe_curl.js";
|
|
2
3
|
|
|
3
4
|
//#region src/types.d.ts
|
|
4
|
-
|
|
5
5
|
declare module 'egg' {
|
|
6
6
|
interface EggAppConfig {
|
|
7
|
+
/**
|
|
8
|
+
* security options
|
|
9
|
+
* @member Config#security
|
|
10
|
+
*/
|
|
7
11
|
security: SecurityConfig;
|
|
8
12
|
helper: SecurityHelperConfig;
|
|
9
13
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
interface Agent {
|
|
15
|
+
safeCurl<T = any>(url: HttpClientRequestURL, options?: HttpClientOptions): Promise<HttpClientResponse<T>>;
|
|
16
|
+
}
|
|
17
|
+
interface Application {
|
|
18
|
+
injectCsrf(html: string): string;
|
|
19
|
+
injectNonce(html: string): string;
|
|
20
|
+
injectHijackingDefense(html: string): string;
|
|
21
|
+
safeCurl<T = any>(url: HttpClientRequestURL, options?: HttpClientOptions): Promise<HttpClientResponse<T>>;
|
|
22
|
+
}
|
|
23
|
+
interface Context {
|
|
24
|
+
get securityOptions(): Partial<SecurityConfig & SecurityHelperConfig>;
|
|
25
|
+
isSafeDomain(domain: string, customWhiteList?: string[]): boolean;
|
|
26
|
+
get nonce(): string;
|
|
27
|
+
get csrf(): string;
|
|
28
|
+
ensureCsrfSecret(rotate?: boolean): void;
|
|
29
|
+
rotateCsrfSecret(): void;
|
|
30
|
+
assertCsrf(): void;
|
|
31
|
+
safeCurl<T = any>(url: HttpClientRequestURL, options?: HttpClientOptions): Promise<HttpClientResponse<T>>;
|
|
32
|
+
unsafeRedirect(url: string, alt?: string): void;
|
|
33
|
+
}
|
|
34
|
+
interface Response {
|
|
35
|
+
unsafeRedirect(url: string, alt?: string): void;
|
|
36
|
+
redirect(url: string, alt?: string): void;
|
|
37
|
+
}
|
|
38
|
+
}
|
package/dist/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/security",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -78,13 +78,13 @@
|
|
|
78
78
|
"extend": "^3.0.2",
|
|
79
79
|
"koa-compose": "^4.1.0",
|
|
80
80
|
"matcher": "^4.0.0",
|
|
81
|
-
"nanoid": "^
|
|
81
|
+
"nanoid": "^5.0.0",
|
|
82
82
|
"type-is": "^2.0.0",
|
|
83
83
|
"xss": "^1.0.15",
|
|
84
84
|
"zod": "^3.24.1"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
|
-
"egg": "4.1.0-beta.
|
|
87
|
+
"egg": "4.1.0-beta.18"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@types/escape-html": "^1.0.4",
|
|
@@ -100,9 +100,9 @@
|
|
|
100
100
|
"tsdown": "^0.15.4",
|
|
101
101
|
"typescript": "5.9.2",
|
|
102
102
|
"vitest": "4.0.0-beta.13",
|
|
103
|
-
"@eggjs/
|
|
104
|
-
"@eggjs/
|
|
105
|
-
"@eggjs/
|
|
103
|
+
"@eggjs/mock": "7.0.0-beta.18",
|
|
104
|
+
"@eggjs/supertest": "9.0.0-beta.18",
|
|
105
|
+
"@eggjs/tsconfig": "3.1.0-beta.18"
|
|
106
106
|
},
|
|
107
107
|
"files": [
|
|
108
108
|
"dist"
|