@eggjs/security 5.0.0-beta.15 → 5.0.0-beta.17
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 +5 -9
- 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
|
|
@@ -741,24 +737,24 @@ declare const SecurityHelperConfig: z.ZodObject<{
|
|
|
741
737
|
*/
|
|
742
738
|
onTagAttr: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodString, z.ZodString, z.ZodString, z.ZodBoolean], z.ZodUnknown>, z.ZodUnion<[z.ZodString, z.ZodVoid]>>>;
|
|
743
739
|
}, "strip", z.ZodTypeAny, {
|
|
744
|
-
domainWhiteList?: string[] | undefined;
|
|
745
740
|
whiteList?: Record<string, string[]> | undefined;
|
|
741
|
+
domainWhiteList?: string[] | undefined;
|
|
746
742
|
onTagAttr?: ((args_0: string, args_1: string, args_2: string, args_3: boolean, ...args: unknown[]) => string | void) | undefined;
|
|
747
743
|
}, {
|
|
748
|
-
domainWhiteList?: string[] | undefined;
|
|
749
744
|
whiteList?: Record<string, string[]> | undefined;
|
|
745
|
+
domainWhiteList?: string[] | undefined;
|
|
750
746
|
onTagAttr?: ((args_0: string, args_1: string, args_2: string, args_3: boolean, ...args: unknown[]) => string | void) | undefined;
|
|
751
747
|
}>>;
|
|
752
748
|
}, "strip", z.ZodTypeAny, {
|
|
753
749
|
shtml: {
|
|
754
|
-
domainWhiteList?: string[] | undefined;
|
|
755
750
|
whiteList?: Record<string, string[]> | undefined;
|
|
751
|
+
domainWhiteList?: string[] | undefined;
|
|
756
752
|
onTagAttr?: ((args_0: string, args_1: string, args_2: string, args_3: boolean, ...args: unknown[]) => string | void) | undefined;
|
|
757
753
|
};
|
|
758
754
|
}, {
|
|
759
755
|
shtml?: {
|
|
760
|
-
domainWhiteList?: string[] | undefined;
|
|
761
756
|
whiteList?: Record<string, string[]> | undefined;
|
|
757
|
+
domainWhiteList?: string[] | undefined;
|
|
762
758
|
onTagAttr?: ((args_0: string, args_1: string, args_2: string, args_3: boolean, ...args: unknown[]) => string | void) | undefined;
|
|
763
759
|
} | undefined;
|
|
764
760
|
}>;
|
|
@@ -864,8 +860,8 @@ declare const _default: {
|
|
|
864
860
|
};
|
|
865
861
|
helper: {
|
|
866
862
|
shtml: {
|
|
867
|
-
domainWhiteList?: string[] | undefined;
|
|
868
863
|
whiteList?: Record<string, string[]> | undefined;
|
|
864
|
+
domainWhiteList?: string[] | undefined;
|
|
869
865
|
onTagAttr?: ((args_0: string, args_1: string, args_2: string, args_3: boolean, ...args: unknown[]) => string | void) | undefined;
|
|
870
866
|
};
|
|
871
867
|
};
|
|
@@ -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.17",
|
|
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.17"
|
|
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/supertest": "9.0.0-beta.
|
|
104
|
-
"@eggjs/
|
|
105
|
-
"@eggjs/
|
|
103
|
+
"@eggjs/supertest": "9.0.0-beta.17",
|
|
104
|
+
"@eggjs/mock": "7.0.0-beta.17",
|
|
105
|
+
"@eggjs/tsconfig": "3.1.0-beta.17"
|
|
106
106
|
},
|
|
107
107
|
"files": [
|
|
108
108
|
"dist"
|