@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
package/dist/agent.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Agent, ILifecycleBoot } from "egg";
|
|
2
|
+
|
|
3
|
+
//#region src/agent.d.ts
|
|
4
|
+
declare class AgentBoot implements ILifecycleBoot {
|
|
5
|
+
private readonly agent;
|
|
6
|
+
constructor(agent: Agent);
|
|
7
|
+
configWillLoad(): Promise<void>;
|
|
6
8
|
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { AgentBoot as default };
|
package/dist/agent.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { preprocessConfig } from "./lib/utils.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
|
|
3
|
+
//#region src/agent.ts
|
|
4
|
+
var AgentBoot = class {
|
|
5
|
+
agent;
|
|
6
|
+
constructor(agent) {
|
|
7
|
+
this.agent = agent;
|
|
8
|
+
}
|
|
9
|
+
async configWillLoad() {
|
|
10
|
+
preprocessConfig(this.agent.config.security);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { AgentBoot as default };
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { HttpClientOptions, HttpClientRequestURL, HttpClientResponse } from "../../lib/extend/safe_curl.js";
|
|
2
|
+
import { Agent } from "egg";
|
|
3
|
+
|
|
4
|
+
//#region src/app/extend/agent.d.ts
|
|
5
|
+
declare class SecurityAgent extends Agent {
|
|
6
|
+
safeCurl<T = any>(url: HttpClientRequestURL, options?: HttpClientOptions): Promise<HttpClientResponse<T>>;
|
|
5
7
|
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { SecurityAgent as default };
|
package/dist/app/extend/agent.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { safeCurlForApplication } from "../../lib/extend/safe_curl.js";
|
|
2
|
+
import { Agent } from "egg";
|
|
3
|
+
|
|
4
|
+
//#region src/app/extend/agent.ts
|
|
5
|
+
var SecurityAgent = class extends Agent {
|
|
6
|
+
async safeCurl(url, options) {
|
|
7
|
+
return await safeCurlForApplication(this, url, options);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { SecurityAgent as default };
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { HttpClientOptions, HttpClientRequestURL, HttpClientResponse } from "../../lib/extend/safe_curl.js";
|
|
2
|
+
import { Application } from "egg";
|
|
3
|
+
|
|
4
|
+
//#region src/app/extend/application.d.ts
|
|
5
|
+
declare class SecurityApplication extends Application {
|
|
6
|
+
injectCsrf(html: string): string;
|
|
7
|
+
injectNonce(html: string): string;
|
|
8
|
+
injectHijackingDefense(html: string): string;
|
|
9
|
+
safeCurl<T = any>(url: HttpClientRequestURL, options?: HttpClientOptions): Promise<HttpClientResponse<T>>;
|
|
8
10
|
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { SecurityApplication as default };
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
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
|
-
|
|
1
|
+
import { safeCurlForApplication } from "../../lib/extend/safe_curl.js";
|
|
2
|
+
import { Application } from "egg";
|
|
3
|
+
|
|
4
|
+
//#region src/app/extend/application.ts
|
|
5
|
+
const INPUT_CSRF = "\r\n<input type=\"hidden\" name=\"_csrf\" value=\"{{ctx.csrf}}\" /></form>";
|
|
6
|
+
const INJECTION_DEFENSE = "<!--for injection--><!--</html>--><!--for injection-->";
|
|
7
|
+
var SecurityApplication = class extends Application {
|
|
8
|
+
injectCsrf(html) {
|
|
9
|
+
html = html.replace(/(<form.*?>)([\s\S]*?)<\/form>/gi, (_, $1, $2) => {
|
|
10
|
+
const match = $2;
|
|
11
|
+
if (match.indexOf("name=\"_csrf\"") !== -1 || match.indexOf("name='_csrf'") !== -1) return $1 + match + "</form>";
|
|
12
|
+
return $1 + match + INPUT_CSRF;
|
|
13
|
+
});
|
|
14
|
+
return html;
|
|
15
|
+
}
|
|
16
|
+
injectNonce(html) {
|
|
17
|
+
html = html.replace(/<script(.*?)>([\s\S]*?)<\/script[^>]*?>/gi, (_, $1, $2) => {
|
|
18
|
+
if (!$1.includes("nonce=")) $1 += " nonce=\"{{ctx.nonce}}\"";
|
|
19
|
+
return "<script" + $1 + ">" + $2 + "<\/script>";
|
|
20
|
+
});
|
|
21
|
+
return html;
|
|
22
|
+
}
|
|
23
|
+
injectHijackingDefense(html) {
|
|
24
|
+
return INJECTION_DEFENSE + html + INJECTION_DEFENSE;
|
|
25
|
+
}
|
|
26
|
+
async safeCurl(url, options) {
|
|
27
|
+
return await safeCurlForApplication(this, url, options);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { SecurityApplication as default };
|
|
@@ -1,52 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
import { SecurityConfig } from "../../config/config.default.js";
|
|
2
|
+
import { HttpClientOptions, HttpClientRequestURL, HttpClientResponse } from "../../lib/extend/safe_curl.js";
|
|
3
|
+
import SecurityResponse from "./response.js";
|
|
4
|
+
import { Context } from "egg";
|
|
5
|
+
|
|
6
|
+
//#region src/app/extend/context.d.ts
|
|
7
|
+
declare class SecurityContext extends Context {
|
|
8
|
+
response: SecurityResponse;
|
|
9
|
+
get securityOptions(): Partial<SecurityConfig>;
|
|
10
|
+
/**
|
|
11
|
+
* Check whether the specific `domain` is in / matches the whiteList or not.
|
|
12
|
+
* @param {string} domain The assigned domain.
|
|
13
|
+
* @param {Array<string>} [customWhiteList] The custom white list for domain.
|
|
14
|
+
* @return {boolean} If the domain is in / matches the whiteList, return true;
|
|
15
|
+
* otherwise false.
|
|
16
|
+
*/
|
|
17
|
+
isSafeDomain(domain: string, customWhiteList?: string[]): boolean;
|
|
18
|
+
get nonce(): string;
|
|
19
|
+
/**
|
|
20
|
+
* get csrf token, general use in template
|
|
21
|
+
* @return {String} csrf token
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
get csrf(): string;
|
|
25
|
+
/**
|
|
26
|
+
* get csrf secret from session or cookie
|
|
27
|
+
* @return {String} csrf secret
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
private getCsrfSecret;
|
|
31
|
+
/**
|
|
32
|
+
* ensure csrf secret exists in session or cookie.
|
|
33
|
+
* @param {Boolean} [rotate] reset secret even if the secret exists
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
ensureCsrfSecret(rotate?: boolean): void;
|
|
37
|
+
private getInputToken;
|
|
38
|
+
/**
|
|
39
|
+
* rotate csrf secret exists in session or cookie.
|
|
40
|
+
* must rotate the secret when user login
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
rotateCsrfSecret(): void;
|
|
44
|
+
/**
|
|
45
|
+
* assert csrf token/referer is present
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
assertCsrf(): void;
|
|
49
|
+
private csrfCtokenCheck;
|
|
50
|
+
private csrfRefererCheck;
|
|
51
|
+
private logCsrfNotice;
|
|
52
|
+
safeCurl<T = any>(url: HttpClientRequestURL, options?: HttpClientOptions): Promise<HttpClientResponse<T>>;
|
|
53
|
+
unsafeRedirect(url: string, alt?: string): void;
|
|
52
54
|
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { SecurityContext as default };
|