@opengis/fastify-table 1.1.149 → 1.1.151
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/config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengis/fastify-table",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.151",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "core-plugins",
|
|
6
6
|
"keywords": [
|
|
@@ -27,16 +27,16 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@fastify/sensible": "^5.0.0",
|
|
30
|
-
"@fastify/url-data": "
|
|
31
|
-
"@opengis/fastify-hb": "
|
|
30
|
+
"@fastify/url-data": "5.4.0",
|
|
31
|
+
"@opengis/fastify-hb": "1.4.8",
|
|
32
32
|
"fastify": "^4.26.1",
|
|
33
33
|
"fastify-plugin": "^4.0.0",
|
|
34
|
-
"ioredis": "
|
|
35
|
-
"js-yaml": "
|
|
36
|
-
"pg": "
|
|
37
|
-
"pino": "
|
|
38
|
-
"pino-abstract-transport": "
|
|
39
|
-
"uglify-js": "
|
|
34
|
+
"ioredis": "5.3.2",
|
|
35
|
+
"js-yaml": "4.1.0",
|
|
36
|
+
"pg": "8.11.3",
|
|
37
|
+
"pino": "9.5.0",
|
|
38
|
+
"pino-abstract-transport": "2.0.0",
|
|
39
|
+
"uglify-js": "3.19.3"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@panzoom/panzoom": "^4.5.1",
|
|
@@ -21,6 +21,8 @@ ALTER TABLE admin.users add column if not exists last_activity_date timestamp wi
|
|
|
21
21
|
ALTER TABLE admin.users add column if not exists user_type text DEFAULT 'regular'::text;
|
|
22
22
|
ALTER TABLE admin.users add column if not exists user_rnokpp text;
|
|
23
23
|
ALTER TABLE admin.users alter column user_rnokpp drop not null;
|
|
24
|
+
ALTER TABLE admin.users add column if not exists social_auth_id text;
|
|
25
|
+
ALTER TABLE admin.users add column if not exists social_auth_type text;
|
|
24
26
|
ALTER TABLE admin.users add column if not exists salt text;
|
|
25
27
|
ALTER TABLE admin.users add column if not exists cdate timestamp without time zone DEFAULT date_trunc('seconds'::text, now());
|
|
26
28
|
ALTER TABLE admin.users add column if not exists editor_id text;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { config, logger } from '../../../../utils.js';
|
|
2
2
|
import block from '../sqlInjection.js';
|
|
3
3
|
|
|
4
|
+
const { prefix = '/api', skipCheckPolicyRoutes = [] } = config;
|
|
4
5
|
/**
|
|
5
6
|
* Middleware func
|
|
6
7
|
*
|
|
@@ -11,7 +12,7 @@ import block from '../sqlInjection.js';
|
|
|
11
12
|
* @returns {object|null} Returns object
|
|
12
13
|
*/
|
|
13
14
|
|
|
14
|
-
export default function checkPolicy(req) {
|
|
15
|
+
export default function checkPolicy(req, reply) {
|
|
15
16
|
const {
|
|
16
17
|
originalUrl: path, hostname, query, params, headers, method, session, routeOptions, unittest,
|
|
17
18
|
} = req;
|
|
@@ -27,10 +28,10 @@ export default function checkPolicy(req) {
|
|
|
27
28
|
|
|
28
29
|
/*= == 0.Check superadmin access === */
|
|
29
30
|
if (policy.includes('superadmin') && user?.user_type !== 'superadmin') {
|
|
30
|
-
logger.file('access', {
|
|
31
|
+
logger.file('policy/access', {
|
|
31
32
|
path, method, params, query, body, message: 'access restricted: not superadmin', uid: user?.uid,
|
|
32
33
|
});
|
|
33
|
-
return
|
|
34
|
+
return reply.status(403).send('access restricted: 0');
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
/*= == 1.File injection === */
|
|
@@ -38,7 +39,7 @@ export default function checkPolicy(req) {
|
|
|
38
39
|
logger.file('injection/file', {
|
|
39
40
|
path, method, params, query, body, message: 'access restricted: 1', uid: user?.uid,
|
|
40
41
|
});
|
|
41
|
-
return
|
|
42
|
+
return reply.status(403).send('access restricted: 1');
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
/* === 1.1 File === */
|
|
@@ -54,11 +55,11 @@ export default function checkPolicy(req) {
|
|
|
54
55
|
logger.file('injection/sql', {
|
|
55
56
|
path, method, params, query, body, stopWords, message: 'access restricted: 2', uid: user?.uid,
|
|
56
57
|
});
|
|
57
|
-
return
|
|
58
|
+
return reply.status(403).send('access restricted: 2');
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
/* policy: skip if not API */
|
|
61
|
-
const isApi = ['/files/', '/api/
|
|
62
|
+
const isApi = ['/files/', '/api/', '/api-user/', '/logger', '/file/'].filter((el) => path.includes(el)).length;
|
|
62
63
|
if (!isApi) {
|
|
63
64
|
return null;
|
|
64
65
|
}
|
|
@@ -68,12 +69,23 @@ export default function checkPolicy(req) {
|
|
|
68
69
|
return null;
|
|
69
70
|
}
|
|
70
71
|
|
|
72
|
+
/* === 0. policy: unauthorized access from admin URL === */
|
|
73
|
+
if (!user?.uid && !config.auth?.disable && isAdmin && !policy.includes('public') && !skipCheckPolicyRoutes.filter((el) => el).find(el => req.url.includes(el))) {
|
|
74
|
+
if (!req.url.startsWith(prefix) && req.url.startsWith('/api')) {
|
|
75
|
+
return reply.redirect(config?.auth?.redirect || '/login');
|
|
76
|
+
}
|
|
77
|
+
logger.file('policy/unauthorized', {
|
|
78
|
+
path, method, params, query, body, message: 'unauthorized',
|
|
79
|
+
});
|
|
80
|
+
return reply.status(401).send('unauthorized');
|
|
81
|
+
}
|
|
82
|
+
|
|
71
83
|
/* === 3. policy: user === */
|
|
72
|
-
if (!user && policy.includes('user')
|
|
84
|
+
if (!user && policy.includes('user')) {
|
|
73
85
|
logger.file('policy/user', {
|
|
74
86
|
path, method, params, query, body, message: 'access restricted: 3',
|
|
75
87
|
});
|
|
76
|
-
return
|
|
88
|
+
return reply.status(403).send('access restricted: 3');
|
|
77
89
|
}
|
|
78
90
|
|
|
79
91
|
/* === 4. policy: referer === */
|
|
@@ -81,7 +93,7 @@ export default function checkPolicy(req) {
|
|
|
81
93
|
logger.file('policy/referer', {
|
|
82
94
|
path, method, params, query, body, message: 'access restricted: 4', uid: user?.uid,
|
|
83
95
|
});
|
|
84
|
-
return
|
|
96
|
+
return reply.status(403).send('access restricted: 4');
|
|
85
97
|
}
|
|
86
98
|
|
|
87
99
|
/* === 5. policy: site auth === */
|
|
@@ -90,7 +102,7 @@ export default function checkPolicy(req) {
|
|
|
90
102
|
logger.file('policy/site', {
|
|
91
103
|
path, method, params, query, body, message: 'access restricted: 5', uid: user?.uid,
|
|
92
104
|
});
|
|
93
|
-
return
|
|
105
|
+
return reply.status(403).send('access restricted: 5');
|
|
94
106
|
}
|
|
95
107
|
|
|
96
108
|
/* === 6. base policy: block api, except login === */
|
|
@@ -99,7 +111,7 @@ export default function checkPolicy(req) {
|
|
|
99
111
|
logger.file('policy/api', {
|
|
100
112
|
path, method, params, query, body, message: 'access restricted: 6', uid: user?.uid,
|
|
101
113
|
});
|
|
102
|
-
return
|
|
114
|
+
return reply.status(403).send('access restricted: 6');
|
|
103
115
|
}
|
|
104
116
|
|
|
105
117
|
return null;
|
|
@@ -2,9 +2,9 @@ import checkPolicy from './funcs/checkPolicy.js';
|
|
|
2
2
|
|
|
3
3
|
async function plugin(fastify) {
|
|
4
4
|
fastify.addHook('preParsing', async (request, reply) => {
|
|
5
|
-
const
|
|
6
|
-
if (
|
|
7
|
-
return
|
|
5
|
+
const resp = checkPolicy(request, reply);
|
|
6
|
+
if (resp) {
|
|
7
|
+
return resp;
|
|
8
8
|
}
|
|
9
9
|
});
|
|
10
10
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import config from '../../../../config.js';
|
|
1
2
|
import pgClients from '../../pg/pgClients.js';
|
|
2
3
|
import getTemplate from './getTemplate.js';
|
|
3
4
|
|
|
@@ -10,7 +11,7 @@ const sqls = {
|
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
export default async function getSelect(name, pg = pgClients.client) {
|
|
13
|
-
if (loadCls[name] &&
|
|
14
|
+
if (loadCls[name] && !config.local) return loadCls[name];
|
|
14
15
|
|
|
15
16
|
const clsDataGIT = await getTemplate(['cls', 'select'], name);
|
|
16
17
|
const { type } = !clsDataGIT && pg.pk?.['admin.user_cls'] ? await pg.query('select type from admin.user_cls where parent is null and name=$1 union all select type from admin.cls where parent is null and name=$1 limit 1', [name]).then(el => el.rows?.[0] || {}) : {};
|