@things-factory/shell 10.1.44 → 10.1.47
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-server/middlewares/domain-middleware.d.ts +12 -0
- package/dist-server/middlewares/domain-middleware.js +19 -4
- package/dist-server/middlewares/domain-middleware.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/tests/domain-middleware-refusal.test.ts +44 -0
- package/tests/generator-list-page-template.test.ts +24 -0
- package/tests/undefined-custom-properties.test.ts +4 -13
- package/translations/en.json +17 -1
- package/translations/ja.json +17 -1
- package/translations/ko.json +20 -4
- package/translations/ms.json +17 -1
- package/translations/zh.json +17 -1
|
@@ -1 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reason an address was refused, as a header the client can read.
|
|
3
|
+
*
|
|
4
|
+
* The domain's IP lists answer 403, and so does "no domain chosen" (domain-authenticate-middleware).
|
|
5
|
+
* The client sent both to check-in; for a refused address check-in sends the person straight back,
|
|
6
|
+
* so the screen stopped with nothing said (ADR README, plan 3). With this header the client can tell
|
|
7
|
+
* the two apart and say what happened - the address is not let in, and check-in cannot change that.
|
|
8
|
+
*
|
|
9
|
+
* A header, not a body: it reaches the client whatever the request was (GraphQL, HTML, a file).
|
|
10
|
+
*/
|
|
11
|
+
export declare const REFUSAL_HEADER = "x-refusal";
|
|
12
|
+
export declare const REFUSED_ADDRESS = "address-not-allowed";
|
|
1
13
|
export declare function domainMiddleware(context: any, next: any): Promise<any>;
|
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REFUSED_ADDRESS = exports.REFUSAL_HEADER = void 0;
|
|
3
4
|
exports.domainMiddleware = domainMiddleware;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
5
6
|
const request_ip_1 = tslib_1.__importDefault(require("request-ip"));
|
|
6
7
|
const get_domain_js_1 = require("../utils/get-domain.js");
|
|
8
|
+
/**
|
|
9
|
+
* The reason an address was refused, as a header the client can read.
|
|
10
|
+
*
|
|
11
|
+
* The domain's IP lists answer 403, and so does "no domain chosen" (domain-authenticate-middleware).
|
|
12
|
+
* The client sent both to check-in; for a refused address check-in sends the person straight back,
|
|
13
|
+
* so the screen stopped with nothing said (ADR README, plan 3). With this header the client can tell
|
|
14
|
+
* the two apart and say what happened - the address is not let in, and check-in cannot change that.
|
|
15
|
+
*
|
|
16
|
+
* A header, not a body: it reaches the client whatever the request was (GraphQL, HTML, a file).
|
|
17
|
+
*/
|
|
18
|
+
exports.REFUSAL_HEADER = 'x-refusal';
|
|
19
|
+
exports.REFUSED_ADDRESS = 'address-not-allowed';
|
|
20
|
+
function refuseByAddress(context) {
|
|
21
|
+
context.status = 403;
|
|
22
|
+
context.set(exports.REFUSAL_HEADER, exports.REFUSED_ADDRESS);
|
|
23
|
+
}
|
|
7
24
|
async function domainMiddleware(context, next) {
|
|
8
25
|
var { domain } = context.state;
|
|
9
26
|
if (!domain) {
|
|
@@ -24,8 +41,7 @@ async function domainMiddleware(context, next) {
|
|
|
24
41
|
return new RegExp(item).test(ip);
|
|
25
42
|
});
|
|
26
43
|
if (!whitelisted) {
|
|
27
|
-
context
|
|
28
|
-
return;
|
|
44
|
+
return refuseByAddress(context);
|
|
29
45
|
}
|
|
30
46
|
}
|
|
31
47
|
else {
|
|
@@ -34,8 +50,7 @@ async function domainMiddleware(context, next) {
|
|
|
34
50
|
return new RegExp(item).test(ip);
|
|
35
51
|
});
|
|
36
52
|
if (blacklisted) {
|
|
37
|
-
context
|
|
38
|
-
return;
|
|
53
|
+
return refuseByAddress(context);
|
|
39
54
|
}
|
|
40
55
|
}
|
|
41
56
|
if (Array.isArray(protectedlist) && protectedlist.length > 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain-middleware.js","sourceRoot":"","sources":["../../server/middlewares/domain-middleware.ts"],"names":[],"mappings":"
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AAW,EAAE,CAAC;gBACjB,OAAO,eAAe,CAAC,OAAO,CAAC,CAAA;YACjC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,WAAW,GACf,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;gBACxB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;oBACpB,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;gBAClC,CAAC,CAAC,CAAA;YAEJ,IAAI,WAAW,EAAE,CAAC;gBAChB,OAAO,eAAe,CAAC,OAAO,CAAC,CAAA;YACjC,CAAC;QACH,CAAC;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7D,MAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;gBACrC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YAClC,CAAC,CAAC,CAAA;YAEF,OAAO,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAA;YAE9B,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,OAAO,CAAC,KAAK,CAAC,oBAAoB,GAAG,UAAU,CAAA;YACjD,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAA;IAE7B,OAAO,IAAI,EAAE,CAAA;AACf,CAAC","sourcesContent":["import requestIp from 'request-ip'\nimport { getDomainFromURL } from '../utils/get-domain.js'\n\n/**\n * The reason an address was refused, as a header the client can read.\n *\n * The domain's IP lists answer 403, and so does \"no domain chosen\" (domain-authenticate-middleware).\n * The client sent both to check-in; for a refused address check-in sends the person straight back,\n * so the screen stopped with nothing said (ADR README, plan 3). With this header the client can tell\n * the two apart and say what happened - the address is not let in, and check-in cannot change that.\n *\n * A header, not a body: it reaches the client whatever the request was (GraphQL, HTML, a file).\n */\nexport const REFUSAL_HEADER = 'x-refusal'\nexport const REFUSED_ADDRESS = 'address-not-allowed'\n\nfunction refuseByAddress(context: any) {\n context.status = 403\n context.set(REFUSAL_HEADER, REFUSED_ADDRESS)\n}\n\nexport async function domainMiddleware(context: any, next: any) {\n var { domain } = context.state\n if (!domain) {\n /*\n * The domainTypes should be checked only when signin and checkin.\n * For purposes such as API calls, the target domainTypes may be different from the system domainTypes.\n * So, we don't check domainTypes here.\n */\n domain = await getDomainFromURL(context)\n }\n\n if (domain) {\n const ip = requestIp.getClientIp(context.req)\n const { whitelist = [], blacklist = [], protectedlist = [], privileges = [] } = domain.iplist || {}\n\n if (Array.isArray(whitelist) && whitelist.length > 0) {\n /* whitelist 우선 */\n const whitelisted =\n Array.isArray(whitelist) &&\n whitelist.some(item => {\n return new RegExp(item).test(ip)\n })\n\n if (!whitelisted) {\n return refuseByAddress(context)\n }\n } else {\n const blacklisted =\n Array.isArray(blacklist) &&\n blacklist.some(item => {\n return new RegExp(item).test(ip)\n })\n\n if (blacklisted) {\n return refuseByAddress(context)\n }\n }\n\n if (Array.isArray(protectedlist) && protectedlist.length > 0) {\n const safe = protectedlist.some(item => {\n return new RegExp(item).test(ip)\n })\n\n context.state.unsafeIP = !safe\n\n if (!safe) {\n context.state.prohibitedPrivileges = privileges\n }\n }\n }\n\n context.state.domain = domain\n\n return next()\n}\n"]}
|