@eggjs/security 5.0.0-beta.19 → 5.0.0-beta.21
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 +5 -9
- package/dist/agent.js +10 -14
- package/dist/app/extend/agent.d.ts +4 -8
- package/dist/app/extend/agent.js +8 -12
- package/dist/app/extend/application.d.ts +7 -11
- package/dist/app/extend/application.js +32 -32
- package/dist/app/extend/context.d.ts +52 -55
- package/dist/app/extend/context.js +241 -188
- package/dist/app/extend/helper.d.ts +10 -22
- package/dist/app/extend/helper.js +5 -7
- package/dist/app/extend/response.d.ts +34 -38
- package/dist/app/extend/response.js +82 -69
- package/dist/app/middleware/securities.d.ts +4 -8
- package/dist/app/middleware/securities.js +52 -38
- package/dist/app.d.ts +5 -9
- package/dist/app.js +24 -22
- package/dist/config/config.default.d.ts +784 -787
- package/dist/config/config.default.js +356 -156
- package/dist/config/config.local.d.ts +2 -5
- package/dist/config/config.local.js +8 -5
- package/dist/index.d.ts +4 -1
- package/dist/index.js +2 -2
- package/dist/lib/extend/safe_curl.d.ts +9 -13
- package/dist/lib/extend/safe_curl.js +23 -17
- package/dist/lib/helper/cliFilter.d.ts +1 -4
- package/dist/lib/helper/cliFilter.js +15 -16
- package/dist/lib/helper/escape.d.ts +2 -2
- package/dist/lib/helper/escape.js +3 -7
- package/dist/lib/helper/escapeShellArg.d.ts +1 -4
- package/dist/lib/helper/escapeShellArg.js +4 -6
- package/dist/lib/helper/escapeShellCmd.d.ts +1 -4
- package/dist/lib/helper/escapeShellCmd.js +13 -14
- package/dist/lib/helper/index.d.ts +19 -22
- package/dist/lib/helper/index.js +15 -19
- package/dist/lib/helper/shtml.d.ts +2 -6
- package/dist/lib/helper/shtml.js +68 -52
- package/dist/lib/helper/sjs.d.ts +1 -4
- package/dist/lib/helper/sjs.js +44 -31
- package/dist/lib/helper/sjson.d.ts +1 -4
- package/dist/lib/helper/sjson.js +35 -28
- package/dist/lib/helper/spath.d.ts +5 -7
- package/dist/lib/helper/spath.js +24 -15
- package/dist/lib/helper/surl.d.ts +2 -6
- package/dist/lib/helper/surl.js +27 -22
- package/dist/lib/middlewares/csp.d.ts +3 -6
- package/dist/lib/middlewares/csp.js +54 -43
- package/dist/lib/middlewares/csrf.d.ts +3 -6
- package/dist/lib/middlewares/csrf.js +35 -31
- package/dist/lib/middlewares/dta.d.ts +2 -5
- package/dist/lib/middlewares/dta.js +10 -11
- package/dist/lib/middlewares/hsts.d.ts +3 -6
- package/dist/lib/middlewares/hsts.js +19 -17
- package/dist/lib/middlewares/index.d.ts +11 -16
- package/dist/lib/middlewares/index.js +22 -26
- package/dist/lib/middlewares/methodnoallow.d.ts +2 -5
- package/dist/lib/middlewares/methodnoallow.js +18 -13
- package/dist/lib/middlewares/noopen.d.ts +3 -6
- package/dist/lib/middlewares/noopen.js +13 -15
- package/dist/lib/middlewares/nosniff.d.ts +3 -6
- package/dist/lib/middlewares/nosniff.js +24 -23
- package/dist/lib/middlewares/referrerPolicy.d.ts +3 -6
- package/dist/lib/middlewares/referrerPolicy.js +31 -27
- package/dist/lib/middlewares/xframe.d.ts +3 -6
- package/dist/lib/middlewares/xframe.js +15 -16
- package/dist/lib/middlewares/xssProtection.d.ts +3 -6
- package/dist/lib/middlewares/xssProtection.js +12 -15
- package/dist/lib/utils.d.ts +12 -17
- package/dist/lib/utils.js +177 -112
- package/dist/types.d.ts +35 -37
- package/dist/types.js +2 -1
- package/package.json +6 -6
package/dist/agent.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
constructor(agent: Agent);
|
|
7
|
-
configWillLoad(): Promise<void>;
|
|
1
|
+
import type { ILifecycleBoot, Agent } from 'egg';
|
|
2
|
+
export default class AgentBoot implements ILifecycleBoot {
|
|
3
|
+
private readonly agent;
|
|
4
|
+
constructor(agent: Agent);
|
|
5
|
+
configWillLoad(): Promise<void>;
|
|
8
6
|
}
|
|
9
|
-
//#endregion
|
|
10
|
-
export { AgentBoot as default };
|
package/dist/agent.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import { preprocessConfig } from "./lib/utils.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
//#endregion
|
|
15
|
-
export { AgentBoot as default };
|
|
2
|
+
export default class AgentBoot {
|
|
3
|
+
agent;
|
|
4
|
+
constructor(agent) {
|
|
5
|
+
this.agent = agent;
|
|
6
|
+
}
|
|
7
|
+
async configWillLoad() {
|
|
8
|
+
preprocessConfig(this.agent.config.security);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWdlbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvYWdlbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsT0FBTyxFQUFFLGdCQUFnQixFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFFbEQsTUFBTSxDQUFDLE9BQU8sT0FBTyxTQUFTO0lBQ1gsS0FBSyxDQUFDO0lBRXZCLFlBQVksS0FBWTtRQUN0QixJQUFJLENBQUMsS0FBSyxHQUFHLEtBQUssQ0FBQztJQUNyQixDQUFDO0lBRUQsS0FBSyxDQUFDLGNBQWM7UUFDbEIsZ0JBQWdCLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxNQUFNLENBQUMsUUFBUSxDQUFDLENBQUM7SUFDL0MsQ0FBQztDQUNGIn0=
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare class SecurityAgent extends Agent {
|
|
6
|
-
safeCurl<T = any>(url: HttpClientRequestURL, options?: HttpClientOptions): Promise<HttpClientResponse<T>>;
|
|
1
|
+
import { Agent } from 'egg';
|
|
2
|
+
import { type HttpClientRequestURL, type HttpClientOptions, type HttpClientResponse } from '../../lib/extend/safe_curl.ts';
|
|
3
|
+
export default class SecurityAgent extends Agent {
|
|
4
|
+
safeCurl<T = any>(url: HttpClientRequestURL, options?: HttpClientOptions): Promise<HttpClientResponse<T>>;
|
|
7
5
|
}
|
|
8
|
-
//#endregion
|
|
9
|
-
export { SecurityAgent as default };
|
package/dist/app/extend/agent.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
export { SecurityAgent as default };
|
|
1
|
+
import { Agent } from 'egg';
|
|
2
|
+
import { safeCurlForApplication, } from "../../lib/extend/safe_curl.js";
|
|
3
|
+
export default class SecurityAgent extends Agent {
|
|
4
|
+
async safeCurl(url, options) {
|
|
5
|
+
return await safeCurlForApplication(this, url, options);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWdlbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXBwL2V4dGVuZC9hZ2VudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsS0FBSyxFQUFFLE1BQU0sS0FBSyxDQUFDO0FBRTVCLE9BQU8sRUFDTCxzQkFBc0IsR0FJdkIsTUFBTSwrQkFBK0IsQ0FBQztBQUV2QyxNQUFNLENBQUMsT0FBTyxPQUFPLGFBQWMsU0FBUSxLQUFLO0lBQzlDLEtBQUssQ0FBQyxRQUFRLENBQVUsR0FBeUIsRUFBRSxPQUEyQjtRQUM1RSxPQUFPLE1BQU0sc0JBQXNCLENBQUksSUFBSSxFQUFFLEdBQUcsRUFBRSxPQUFPLENBQUMsQ0FBQztJQUM3RCxDQUFDO0NBQ0YifQ==
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
injectHijackingDefense(html: string): string;
|
|
9
|
-
safeCurl<T = any>(url: HttpClientRequestURL, options?: HttpClientOptions): Promise<HttpClientResponse<T>>;
|
|
1
|
+
import { Application } from 'egg';
|
|
2
|
+
import { type HttpClientRequestURL, type HttpClientOptions, type HttpClientResponse } from '../../lib/extend/safe_curl.ts';
|
|
3
|
+
export default class SecurityApplication extends Application {
|
|
4
|
+
injectCsrf(html: string): string;
|
|
5
|
+
injectNonce(html: string): string;
|
|
6
|
+
injectHijackingDefense(html: string): string;
|
|
7
|
+
safeCurl<T = any>(url: HttpClientRequestURL, options?: HttpClientOptions): Promise<HttpClientResponse<T>>;
|
|
10
8
|
}
|
|
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 { Application } from 'egg';
|
|
2
|
+
import { safeCurlForApplication, } from "../../lib/extend/safe_curl.js";
|
|
3
|
+
const INPUT_CSRF = '\r\n<input type="hidden" name="_csrf" value="{{ctx.csrf}}" /></form>';
|
|
4
|
+
const INJECTION_DEFENSE = '<!--for injection--><!--</html>--><!--for injection-->';
|
|
5
|
+
export default class SecurityApplication extends Application {
|
|
6
|
+
injectCsrf(html) {
|
|
7
|
+
html = html.replace(/(<form.*?>)([\s\S]*?)<\/form>/gi, (_, $1, $2) => {
|
|
8
|
+
const match = $2;
|
|
9
|
+
if (match.indexOf('name="_csrf"') !== -1 || match.indexOf("name='_csrf'") !== -1) {
|
|
10
|
+
return $1 + match + '</form>';
|
|
11
|
+
}
|
|
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=')) {
|
|
19
|
+
$1 += ' nonce="{{ctx.nonce}}"';
|
|
20
|
+
}
|
|
21
|
+
return '<script' + $1 + '>' + $2 + '</script>';
|
|
22
|
+
});
|
|
23
|
+
return html;
|
|
24
|
+
}
|
|
25
|
+
injectHijackingDefense(html) {
|
|
26
|
+
return INJECTION_DEFENSE + html + INJECTION_DEFENSE;
|
|
27
|
+
}
|
|
28
|
+
async safeCurl(url, options) {
|
|
29
|
+
return await safeCurlForApplication(this, url, options);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwbGljYXRpb24uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXBwL2V4dGVuZC9hcHBsaWNhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsV0FBVyxFQUFFLE1BQU0sS0FB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QVMsR0FBRyxFQUFFLEdBQUcsR0FBRyxHQUFHLEVBQUUsR0FBRyxXQUFXLENBQUM7UUFDakQsQ0FBQyxDQUFDLENBQUM7UUFDSCxPQUFPLElBQUksQ0FBQztJQUNkLENBQUM7SUFFRCxzQkFBc0IsQ0FBQyxJQUFZO1FBQ2pDLE9BQU8saUJBQWlCLEdBQUcsSUFBSSxHQUFHLGlCQUFpQixDQUFDO0lBQ3RELENBQUM7SUFFRCxLQUFLLENBQUMsUUFBUSxDQUFVLEdBQXlCLEVBQUUsT0FBMkI7UUFDNUUsT0FBTyxNQUFNLHNCQUFzQixDQUFJLElBQUksRUFBRSxHQUFHLEVBQUUsT0FBTyxDQUFDLENBQUM7SUFDN0QsQ0FBQztDQUNGIn0=
|
|
@@ -1,61 +1,58 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
//#region src/app/extend/context.d.ts
|
|
1
|
+
import { Context } from 'egg';
|
|
2
|
+
import type { HttpClientRequestURL, HttpClientOptions, HttpClientResponse } from '../../lib/extend/safe_curl.ts';
|
|
3
|
+
import type { SecurityConfig } from '../../config/config.default.ts';
|
|
4
|
+
import type SecurityResponse from './response.ts';
|
|
7
5
|
declare const CSRF_SECRET: unique symbol;
|
|
8
6
|
declare const LOG_CSRF_NOTICE: unique symbol;
|
|
9
7
|
declare const INPUT_TOKEN: unique symbol;
|
|
10
8
|
declare const CSRF_REFERER_CHECK: unique symbol;
|
|
11
9
|
declare const CSRF_CTOKEN_CHECK: unique symbol;
|
|
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
|
-
|
|
10
|
+
export default class SecurityContext extends Context {
|
|
11
|
+
response: SecurityResponse;
|
|
12
|
+
get securityOptions(): Partial<SecurityConfig>;
|
|
13
|
+
/**
|
|
14
|
+
* Check whether the specific `domain` is in / matches the whiteList or not.
|
|
15
|
+
* @param {string} domain The assigned domain.
|
|
16
|
+
* @param {Array<string>} [customWhiteList] The custom white list for domain.
|
|
17
|
+
* @return {boolean} If the domain is in / matches the whiteList, return true;
|
|
18
|
+
* otherwise false.
|
|
19
|
+
*/
|
|
20
|
+
isSafeDomain(domain: string, customWhiteList?: string[]): boolean;
|
|
21
|
+
get nonce(): string;
|
|
22
|
+
/**
|
|
23
|
+
* get csrf token, general use in template
|
|
24
|
+
* @return {String} csrf token
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
get csrf(): string;
|
|
28
|
+
/**
|
|
29
|
+
* get csrf secret from session or cookie
|
|
30
|
+
* @return {String} csrf secret
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
get [CSRF_SECRET](): string;
|
|
34
|
+
/**
|
|
35
|
+
* ensure csrf secret exists in session or cookie.
|
|
36
|
+
* @param {Boolean} [rotate] reset secret even if the secret exists
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
ensureCsrfSecret(rotate?: boolean): void;
|
|
40
|
+
get [INPUT_TOKEN](): string;
|
|
41
|
+
/**
|
|
42
|
+
* rotate csrf secret exists in session or cookie.
|
|
43
|
+
* must rotate the secret when user login
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
rotateCsrfSecret(): void;
|
|
47
|
+
/**
|
|
48
|
+
* assert csrf token/referer is present
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
assertCsrf(): void;
|
|
52
|
+
[CSRF_CTOKEN_CHECK](): "missing csrf token" | "invalid csrf token" | undefined;
|
|
53
|
+
[CSRF_REFERER_CHECK](): "missing csrf referer or origin" | "invalid csrf referer or origin" | undefined;
|
|
54
|
+
[LOG_CSRF_NOTICE](msg: string): void;
|
|
55
|
+
safeCurl<T = any>(url: HttpClientRequestURL, options?: HttpClientOptions): Promise<HttpClientResponse<T>>;
|
|
56
|
+
unsafeRedirect(url: string, alt?: string): void;
|
|
59
57
|
}
|
|
60
|
-
|
|
61
|
-
export { SecurityContext as default };
|
|
58
|
+
export {};
|