@opengis/fastify-table 1.0.26 → 1.0.28
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/Changelog.md +8 -0
- package/crud/controllers/insert.js +29 -29
- package/crud/controllers/update.js +31 -31
- package/crud/funcs/dataInsert.js +1 -1
- package/crud/funcs/dataUpdate.js +7 -3
- package/crud/funcs/getOpt.js +10 -10
- package/crud/funcs/setOpt.js +16 -16
- package/crud/index.js +29 -29
- package/dblist/controllers/createItem.js +32 -17
- package/dblist/controllers/deleteItem.js +14 -12
- package/dblist/controllers/readItems.js +10 -8
- package/dblist/controllers/setItem.js +21 -0
- package/dblist/controllers/updateItem.js +25 -22
- package/dblist/controllers/utils/checkItem.js +24 -9
- package/dblist/controllers/utils/formatData.js +7 -0
- package/dblist/index.js +49 -40
- package/helper.js +28 -28
- package/index.js +41 -41
- package/notification/controllers/userNotifications.js +19 -19
- package/notification/funcs/addNotification.js +8 -8
- package/notification/index.js +19 -19
- package/package.json +1 -1
- package/pg/funcs/getPG.js +1 -1
- package/pg/pgClients.js +20 -20
- package/policy/funcs/checkPolicy.js +74 -74
- package/policy/funcs/sqlInjection.js +33 -33
- package/policy/index.js +14 -14
- package/redis/client.js +8 -8
- package/redis/funcs/getRedis.js +1 -1
- package/redis/funcs/redisClients.js +2 -2
- package/redis/index.js +19 -19
- package/server/migrations/crm.sql +57 -57
- package/server/migrations/log.sql +41 -41
- package/server/migrations/notifications.sql +14 -14
- package/server/templates/form/test.dataset.form.json +411 -411
- package/server/templates/select/test.storage.data.json +2 -2
- package/server/templates/table/test.dataset.table.json +24 -24
- package/table/controllers/data.js +57 -57
- package/table/controllers/filter.js +32 -32
- package/table/controllers/form.js +10 -10
- package/table/controllers/suggest.js +60 -60
- package/table/controllers/utils/getSelect.js +20 -20
- package/table/controllers/utils/getSelectMeta.js +66 -66
- package/table/controllers/utils/getTemplate.js +28 -28
- package/table/funcs/getFilterSQL/index.js +75 -75
- package/table/funcs/getFilterSQL/util/formatValue.js +142 -142
- package/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
- package/table/funcs/getFilterSQL/util/getFilterQuery.js +73 -73
- package/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
- package/table/funcs/metaFormat/getSelectVal.js +20 -20
- package/table/funcs/metaFormat/index.js +26 -26
- package/table/index.js +42 -42
- package/test/api/crud.test.js +56 -56
- package/test/api/crud.xss.test.js +71 -71
- package/test/api/dblist.test.js +47 -47
- package/test/api/notification.test.js +37 -37
- package/test/api/table.test.js +57 -57
- package/test/api/widget.test.js +39 -39
- package/test/funcs/notification.test.js +31 -31
- package/test/widget.test.js +39 -39
- package/widget/controllers/utils/historyFormat.js +76 -76
- package/widget/controllers/utils/obj2db.js +13 -13
- package/widget/controllers/widget.del.js +40 -40
- package/widget/controllers/widget.get.js +74 -74
- package/widget/controllers/widget.set.js +45 -45
- package/widget/index.js +29 -29
package/index.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
// import pg from 'pg';
|
|
2
|
-
import fp from 'fastify-plugin';
|
|
3
|
-
import config from './config.js';
|
|
4
|
-
// import rclient from './redis/client.js';
|
|
5
|
-
|
|
6
|
-
import redisPlugin from './redis/index.js';
|
|
7
|
-
import pgPlugin from './pg/index.js';
|
|
8
|
-
import tablePlugin from './table/index.js';
|
|
9
|
-
import notificationPlugin from './notification/index.js';
|
|
10
|
-
import widgetPlugin from './widget/index.js';
|
|
11
|
-
import crudPlugin from './crud/index.js';
|
|
12
|
-
import policyPlugin from './policy/index.js';
|
|
13
|
-
import dbListPlugin from './dblist/index.js';
|
|
14
|
-
|
|
15
|
-
async function plugin(fastify, opt) {
|
|
16
|
-
// console.log(opt);
|
|
17
|
-
config.pg = opt.pg;
|
|
18
|
-
config.redis = opt.redis;
|
|
19
|
-
|
|
20
|
-
// independent npm start / unit test
|
|
21
|
-
if (!fastify.config) {
|
|
22
|
-
fastify.decorate('config', config);
|
|
23
|
-
}
|
|
24
|
-
if (!fastify.funcs) {
|
|
25
|
-
fastify.addHook('onRequest', async (req) => {
|
|
26
|
-
req.funcs = fastify;
|
|
27
|
-
});
|
|
28
|
-
// fastify.decorateRequest('funcs', fastify);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
policyPlugin(fastify);
|
|
32
|
-
redisPlugin(fastify);
|
|
33
|
-
await pgPlugin(fastify, opt);
|
|
34
|
-
tablePlugin(fastify, opt);
|
|
35
|
-
crudPlugin(fastify, opt);
|
|
36
|
-
notificationPlugin(fastify, opt);
|
|
37
|
-
widgetPlugin(fastify, opt);
|
|
38
|
-
dbListPlugin(fastify, opt);
|
|
39
|
-
}
|
|
40
|
-
export default fp(plugin);
|
|
41
|
-
// export { rclient };
|
|
1
|
+
// import pg from 'pg';
|
|
2
|
+
import fp from 'fastify-plugin';
|
|
3
|
+
import config from './config.js';
|
|
4
|
+
// import rclient from './redis/client.js';
|
|
5
|
+
|
|
6
|
+
import redisPlugin from './redis/index.js';
|
|
7
|
+
import pgPlugin from './pg/index.js';
|
|
8
|
+
import tablePlugin from './table/index.js';
|
|
9
|
+
import notificationPlugin from './notification/index.js';
|
|
10
|
+
import widgetPlugin from './widget/index.js';
|
|
11
|
+
import crudPlugin from './crud/index.js';
|
|
12
|
+
import policyPlugin from './policy/index.js';
|
|
13
|
+
import dbListPlugin from './dblist/index.js';
|
|
14
|
+
|
|
15
|
+
async function plugin(fastify, opt) {
|
|
16
|
+
// console.log(opt);
|
|
17
|
+
config.pg = opt.pg;
|
|
18
|
+
config.redis = opt.redis;
|
|
19
|
+
|
|
20
|
+
// independent npm start / unit test
|
|
21
|
+
if (!fastify.config) {
|
|
22
|
+
fastify.decorate('config', config);
|
|
23
|
+
}
|
|
24
|
+
if (!fastify.funcs) {
|
|
25
|
+
fastify.addHook('onRequest', async (req) => {
|
|
26
|
+
req.funcs = fastify;
|
|
27
|
+
});
|
|
28
|
+
// fastify.decorateRequest('funcs', fastify);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
policyPlugin(fastify);
|
|
32
|
+
redisPlugin(fastify);
|
|
33
|
+
await pgPlugin(fastify, opt);
|
|
34
|
+
tablePlugin(fastify, opt);
|
|
35
|
+
crudPlugin(fastify, opt);
|
|
36
|
+
notificationPlugin(fastify, opt);
|
|
37
|
+
widgetPlugin(fastify, opt);
|
|
38
|
+
dbListPlugin(fastify, opt);
|
|
39
|
+
}
|
|
40
|
+
export default fp(plugin);
|
|
41
|
+
// export { rclient };
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export default async function userNotifications({
|
|
2
|
-
pg, session = {}, query = {},
|
|
3
|
-
}) {
|
|
4
|
-
const time = Date.now();
|
|
5
|
-
try {
|
|
6
|
-
const { uid } = session.passport?.user || {};
|
|
7
|
-
if (!uid) return { error: 'access restricted', status: 403 };
|
|
8
|
-
|
|
9
|
-
const queryFunc = query.nocache ? pg.query : pg.queryCache;
|
|
10
|
-
|
|
11
|
-
// queryCache not supports $1 params
|
|
12
|
-
const { rows } = await queryFunc(`select notification_id as id, notification_type as type,
|
|
13
|
-
notification_status as status, title, body, link, uid from crm.notification where uid='${uid}'`);
|
|
14
|
-
return { time: Date.now() - time, total: rows?.length, rows };
|
|
15
|
-
}
|
|
16
|
-
catch (err) {
|
|
17
|
-
return { error: err.toString(), status: 500 };
|
|
18
|
-
}
|
|
19
|
-
}
|
|
1
|
+
export default async function userNotifications({
|
|
2
|
+
pg, session = {}, query = {},
|
|
3
|
+
}) {
|
|
4
|
+
const time = Date.now();
|
|
5
|
+
try {
|
|
6
|
+
const { uid } = session.passport?.user || {};
|
|
7
|
+
if (!uid) return { error: 'access restricted', status: 403 };
|
|
8
|
+
|
|
9
|
+
const queryFunc = query.nocache ? pg.query : pg.queryCache;
|
|
10
|
+
|
|
11
|
+
// queryCache not supports $1 params
|
|
12
|
+
const { rows } = await queryFunc(`select notification_id as id, notification_type as type,
|
|
13
|
+
notification_status as status, title, body, link, uid from crm.notification where uid='${uid}'`);
|
|
14
|
+
return { time: Date.now() - time, total: rows?.length, rows };
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
return { error: err.toString(), status: 500 };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export default async function addNotification({
|
|
2
|
-
pg, session = {}, title, body, link, notificationType, uid: uid1,
|
|
3
|
-
}) {
|
|
4
|
-
const uid = uid1 || session.passport?.user?.uid || {};
|
|
5
|
-
const { id, status } = await pg.one(`insert into crm.notification(title, body, link, notification_type, uid)
|
|
6
|
-
values($1,$2,$3,$4,$5) returning notification_id as id, notification_status as status`, [title, body, link, notificationType, uid]);
|
|
7
|
-
return { id, status };
|
|
8
|
-
}
|
|
1
|
+
export default async function addNotification({
|
|
2
|
+
pg, session = {}, title, body, link, notificationType, uid: uid1,
|
|
3
|
+
}) {
|
|
4
|
+
const uid = uid1 || session.passport?.user?.uid || {};
|
|
5
|
+
const { id, status } = await pg.one(`insert into crm.notification(title, body, link, notification_type, uid)
|
|
6
|
+
values($1,$2,$3,$4,$5) returning notification_id as id, notification_status as status`, [title, body, link, notificationType, uid]);
|
|
7
|
+
return { id, status };
|
|
8
|
+
}
|
package/notification/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
// api
|
|
2
|
-
import userNotifications from './controllers/userNotifications.js';
|
|
3
|
-
// funcs
|
|
4
|
-
import addNotification from './funcs/addNotification.js';
|
|
5
|
-
|
|
6
|
-
async function plugin(fastify, config = {}) {
|
|
7
|
-
const prefix = config.prefix || '/api';
|
|
8
|
-
fastify.route({
|
|
9
|
-
method: 'GET',
|
|
10
|
-
url: `${prefix}/notification`,
|
|
11
|
-
config: {
|
|
12
|
-
policy: ['user'], // implement user auth check policy??
|
|
13
|
-
},
|
|
14
|
-
handler: userNotifications,
|
|
15
|
-
});
|
|
16
|
-
fastify.decorate('addNotification', addNotification);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default plugin;
|
|
1
|
+
// api
|
|
2
|
+
import userNotifications from './controllers/userNotifications.js';
|
|
3
|
+
// funcs
|
|
4
|
+
import addNotification from './funcs/addNotification.js';
|
|
5
|
+
|
|
6
|
+
async function plugin(fastify, config = {}) {
|
|
7
|
+
const prefix = config.prefix || '/api';
|
|
8
|
+
fastify.route({
|
|
9
|
+
method: 'GET',
|
|
10
|
+
url: `${prefix}/notification`,
|
|
11
|
+
config: {
|
|
12
|
+
policy: ['user'], // implement user auth check policy??
|
|
13
|
+
},
|
|
14
|
+
handler: userNotifications,
|
|
15
|
+
});
|
|
16
|
+
fastify.decorate('addNotification', addNotification);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default plugin;
|
package/package.json
CHANGED
package/pg/funcs/getPG.js
CHANGED
|
@@ -5,7 +5,7 @@ import init from './init.js';
|
|
|
5
5
|
|
|
6
6
|
function getPG({
|
|
7
7
|
user, password, host, port, db, database, name: origin, funcs,
|
|
8
|
-
}) {
|
|
8
|
+
} = { name: 'client' }) {
|
|
9
9
|
if (funcs?.config) Object.assign(config, { ...funcs.config }); // unit test
|
|
10
10
|
const name = origin || db || database;
|
|
11
11
|
if (pgClients[name]) return pgClients[name];
|
package/pg/pgClients.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import pg from 'pg';
|
|
2
|
-
import config from '../config.js';
|
|
3
|
-
import init from './funcs/init.js';
|
|
4
|
-
|
|
5
|
-
const pgClients = {};
|
|
6
|
-
if (config.pg) {
|
|
7
|
-
const client = new pg.Pool({
|
|
8
|
-
host: config.pg?.host || '127.0.0.1',
|
|
9
|
-
port: config.pg?.port || 5432,
|
|
10
|
-
database: config.pg?.database || 'postgres',
|
|
11
|
-
user: config.pg?.user || 'postgres',
|
|
12
|
-
password: config.pg?.password || 'postgres',
|
|
13
|
-
});
|
|
14
|
-
client.init = async () => {
|
|
15
|
-
await init(client);
|
|
16
|
-
};
|
|
17
|
-
client.init();
|
|
18
|
-
pgClients.client = client;
|
|
19
|
-
}
|
|
20
|
-
export default pgClients;
|
|
1
|
+
import pg from 'pg';
|
|
2
|
+
import config from '../config.js';
|
|
3
|
+
import init from './funcs/init.js';
|
|
4
|
+
|
|
5
|
+
const pgClients = {};
|
|
6
|
+
if (config.pg) {
|
|
7
|
+
const client = new pg.Pool({
|
|
8
|
+
host: config.pg?.host || '127.0.0.1',
|
|
9
|
+
port: config.pg?.port || 5432,
|
|
10
|
+
database: config.pg?.database || 'postgres',
|
|
11
|
+
user: config.pg?.user || 'postgres',
|
|
12
|
+
password: config.pg?.password || 'postgres',
|
|
13
|
+
});
|
|
14
|
+
client.init = async () => {
|
|
15
|
+
await init(client);
|
|
16
|
+
};
|
|
17
|
+
client.init();
|
|
18
|
+
pgClients.client = client;
|
|
19
|
+
}
|
|
20
|
+
export default pgClients;
|
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
import block from './sqlInjection.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Middleware func
|
|
5
|
-
*
|
|
6
|
-
* @type function
|
|
7
|
-
* @alias checkPolicy
|
|
8
|
-
* @summary Функція дозволяє налаштувати доступ до сайту або API для адмін. та публічної частини веб-ресурсу
|
|
9
|
-
* @param {String} path - назва апі
|
|
10
|
-
* @returns {object|null} Returns object
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
export default function checkPolicy(req) {
|
|
14
|
-
const {
|
|
15
|
-
originalUrl: path, hostname, query, params, headers: hs, log, sid = 35, funcs = {},
|
|
16
|
-
} = req;
|
|
17
|
-
const user = req.user || req.session?.passport?.user;
|
|
18
|
-
|
|
19
|
-
const { config } = funcs;
|
|
20
|
-
const isUser = config.debug || !!user;
|
|
21
|
-
|
|
22
|
-
const isServer = process.argv[2];
|
|
23
|
-
const { policy = [] } = req.routeOptions?.config || {};
|
|
24
|
-
|
|
25
|
-
/*= == 1.File injection === */
|
|
26
|
-
if (JSON.stringify(params || {})?.includes('../') || JSON.stringify(query || {})?.includes('../') || path?.includes('../')) {
|
|
27
|
-
log.warn({
|
|
28
|
-
name: 'injection/file', params, query, message: 'access restricted: 1',
|
|
29
|
-
});
|
|
30
|
-
return { message: 'access restricted: 1', status: 403 };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/*= == 1.1 File === */
|
|
34
|
-
const allowExtPublic = ['.png', '.jpg', '.svg'];
|
|
35
|
-
const ext = path.toLowerCase().substr(-4);
|
|
36
|
-
if (path.includes('files/') && allowExtPublic.includes(ext)) return null;
|
|
37
|
-
|
|
38
|
-
/*= == 2.SQL Injection policy: no-sql === */
|
|
39
|
-
if (!policy.includes('no-sql')) {
|
|
40
|
-
const stopWords = block.filter((el) => path.includes(el));
|
|
41
|
-
if (stopWords?.length) {
|
|
42
|
-
log.warn({ name: 'injection/sql', stopWords, message: 'access restricted: 2' });
|
|
43
|
-
return { message: 'access restricted: 2', status: 403 };
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/* Check is Not API */
|
|
47
|
-
const isApi = ['/files/', '/api/format/', '/api-user/', '/logger', '/file/'].filter((el) => path.includes(el)).length;
|
|
48
|
-
if (!isApi) return null;
|
|
49
|
-
|
|
50
|
-
/*= == 3. policy: referer === */
|
|
51
|
-
if (!hs?.referer?.includes?.(hostname) && policy.includes('referer') && !config.local && !config.debug) {
|
|
52
|
-
log.warn({ name: 'referer', message: 'access restricted: 3' });
|
|
53
|
-
return { message: 'access restricted: 3', status: 403 };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/*= == policy: public === */
|
|
57
|
-
if (policy.includes('public')) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/*= == 4. policy: site auth === */
|
|
62
|
-
if (!policy.includes('site') && sid === 1 && isUser && !config.local && !config.debug) {
|
|
63
|
-
log.warn({ name: 'site', message: 'access restricted: 4' });
|
|
64
|
-
return { message: 'access restricted: 4', status: 403 };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/*= == 5. base policy: block api === */
|
|
68
|
-
if (sid === 35 && !isUser && isServer && !config.local && !config.debug) {
|
|
69
|
-
log.warn({ name: 'api', message: 'access restricted: 5' });
|
|
70
|
-
return { message: 'access restricted: 5', status: 403 };
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
1
|
+
import block from './sqlInjection.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Middleware func
|
|
5
|
+
*
|
|
6
|
+
* @type function
|
|
7
|
+
* @alias checkPolicy
|
|
8
|
+
* @summary Функція дозволяє налаштувати доступ до сайту або API для адмін. та публічної частини веб-ресурсу
|
|
9
|
+
* @param {String} path - назва апі
|
|
10
|
+
* @returns {object|null} Returns object
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export default function checkPolicy(req) {
|
|
14
|
+
const {
|
|
15
|
+
originalUrl: path, hostname, query, params, headers: hs, log, sid = 35, funcs = {},
|
|
16
|
+
} = req;
|
|
17
|
+
const user = req.user || req.session?.passport?.user;
|
|
18
|
+
|
|
19
|
+
const { config } = funcs;
|
|
20
|
+
const isUser = config.debug || !!user;
|
|
21
|
+
|
|
22
|
+
const isServer = process.argv[2];
|
|
23
|
+
const { policy = [] } = req.routeOptions?.config || {};
|
|
24
|
+
|
|
25
|
+
/*= == 1.File injection === */
|
|
26
|
+
if (JSON.stringify(params || {})?.includes('../') || JSON.stringify(query || {})?.includes('../') || path?.includes('../')) {
|
|
27
|
+
log.warn({
|
|
28
|
+
name: 'injection/file', params, query, message: 'access restricted: 1',
|
|
29
|
+
});
|
|
30
|
+
return { message: 'access restricted: 1', status: 403 };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/*= == 1.1 File === */
|
|
34
|
+
const allowExtPublic = ['.png', '.jpg', '.svg'];
|
|
35
|
+
const ext = path.toLowerCase().substr(-4);
|
|
36
|
+
if (path.includes('files/') && allowExtPublic.includes(ext)) return null;
|
|
37
|
+
|
|
38
|
+
/*= == 2.SQL Injection policy: no-sql === */
|
|
39
|
+
if (!policy.includes('no-sql')) {
|
|
40
|
+
const stopWords = block.filter((el) => path.includes(el));
|
|
41
|
+
if (stopWords?.length) {
|
|
42
|
+
log.warn({ name: 'injection/sql', stopWords, message: 'access restricted: 2' });
|
|
43
|
+
return { message: 'access restricted: 2', status: 403 };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/* Check is Not API */
|
|
47
|
+
const isApi = ['/files/', '/api/format/', '/api-user/', '/logger', '/file/'].filter((el) => path.includes(el)).length;
|
|
48
|
+
if (!isApi) return null;
|
|
49
|
+
|
|
50
|
+
/*= == 3. policy: referer === */
|
|
51
|
+
if (!hs?.referer?.includes?.(hostname) && policy.includes('referer') && !config.local && !config.debug) {
|
|
52
|
+
log.warn({ name: 'referer', message: 'access restricted: 3' });
|
|
53
|
+
return { message: 'access restricted: 3', status: 403 };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/*= == policy: public === */
|
|
57
|
+
if (policy.includes('public')) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/*= == 4. policy: site auth === */
|
|
62
|
+
if (!policy.includes('site') && sid === 1 && isUser && !config.local && !config.debug) {
|
|
63
|
+
log.warn({ name: 'site', message: 'access restricted: 4' });
|
|
64
|
+
return { message: 'access restricted: 4', status: 403 };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/*= == 5. base policy: block api === */
|
|
68
|
+
if (sid === 35 && !isUser && isServer && !config.local && !config.debug) {
|
|
69
|
+
log.warn({ name: 'api', message: 'access restricted: 5' });
|
|
70
|
+
return { message: 'access restricted: 5', status: 403 };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
const sqlInjection = [
|
|
2
|
-
'()',
|
|
3
|
-
'^',
|
|
4
|
-
'*',
|
|
5
|
-
'like ',
|
|
6
|
-
'@variable',
|
|
7
|
-
'@@variable',
|
|
8
|
-
'group by ',
|
|
9
|
-
'union ',
|
|
10
|
-
'select ',
|
|
11
|
-
'having ',
|
|
12
|
-
'as injectx',
|
|
13
|
-
'where ',
|
|
14
|
-
'rlike ',
|
|
15
|
-
'if(',
|
|
16
|
-
'sleep(',
|
|
17
|
-
'waitfor delay',
|
|
18
|
-
'benchmark(',
|
|
19
|
-
'pg_sleep(',
|
|
20
|
-
"'\\\"",
|
|
21
|
-
'randomblob(',
|
|
22
|
-
'order by ',
|
|
23
|
-
'union all ',
|
|
24
|
-
'+or',
|
|
25
|
-
'or ',
|
|
26
|
-
'and ',
|
|
27
|
-
"'' ",
|
|
28
|
-
'""" ',
|
|
29
|
-
'<script',
|
|
30
|
-
'javascript:',
|
|
31
|
-
]
|
|
32
|
-
|
|
33
|
-
export default sqlInjection;
|
|
1
|
+
const sqlInjection = [
|
|
2
|
+
'()',
|
|
3
|
+
'^',
|
|
4
|
+
'*',
|
|
5
|
+
'like ',
|
|
6
|
+
'@variable',
|
|
7
|
+
'@@variable',
|
|
8
|
+
'group by ',
|
|
9
|
+
'union ',
|
|
10
|
+
'select ',
|
|
11
|
+
'having ',
|
|
12
|
+
'as injectx',
|
|
13
|
+
'where ',
|
|
14
|
+
'rlike ',
|
|
15
|
+
'if(',
|
|
16
|
+
'sleep(',
|
|
17
|
+
'waitfor delay',
|
|
18
|
+
'benchmark(',
|
|
19
|
+
'pg_sleep(',
|
|
20
|
+
"'\\\"",
|
|
21
|
+
'randomblob(',
|
|
22
|
+
'order by ',
|
|
23
|
+
'union all ',
|
|
24
|
+
'+or',
|
|
25
|
+
'or ',
|
|
26
|
+
'and ',
|
|
27
|
+
"'' ",
|
|
28
|
+
'""" ',
|
|
29
|
+
'<script',
|
|
30
|
+
'javascript:',
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
export default sqlInjection;
|
package/policy/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
// import fp from 'fastify-plugin';
|
|
2
|
-
|
|
3
|
-
import checkPolicy from './funcs/checkPolicy.js';
|
|
4
|
-
|
|
5
|
-
async function plugin(fastify) {
|
|
6
|
-
fastify.addHook('onRequest', async (request, reply) => {
|
|
7
|
-
const hookData = checkPolicy(request);
|
|
8
|
-
if (hookData?.status && hookData?.message) {
|
|
9
|
-
return reply.status(hookData?.status).send(hookData.message);
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default plugin;
|
|
1
|
+
// import fp from 'fastify-plugin';
|
|
2
|
+
|
|
3
|
+
import checkPolicy from './funcs/checkPolicy.js';
|
|
4
|
+
|
|
5
|
+
async function plugin(fastify) {
|
|
6
|
+
fastify.addHook('onRequest', async (request, reply) => {
|
|
7
|
+
const hookData = checkPolicy(request);
|
|
8
|
+
if (hookData?.status && hookData?.message) {
|
|
9
|
+
return reply.status(hookData?.status).send(hookData.message);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default plugin;
|
package/redis/client.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import redisClients from './funcs/redisClients.js';
|
|
2
|
-
import getRedis from './funcs/getRedis.js';
|
|
3
|
-
|
|
4
|
-
if (!redisClients[0]) {
|
|
5
|
-
getRedis({ db: 0 });
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export default redisClients[0];
|
|
1
|
+
import redisClients from './funcs/redisClients.js';
|
|
2
|
+
import getRedis from './funcs/getRedis.js';
|
|
3
|
+
|
|
4
|
+
if (!redisClients[0]) {
|
|
5
|
+
getRedis({ db: 0 });
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default redisClients[0];
|
package/redis/funcs/getRedis.js
CHANGED
|
@@ -2,7 +2,7 @@ import Redis from 'ioredis';
|
|
|
2
2
|
import config from '../../config.js';
|
|
3
3
|
import redisClients from './redisClients.js';
|
|
4
4
|
|
|
5
|
-
function getRedis({ db }) {
|
|
5
|
+
function getRedis({ db } = { db: 0 }) {
|
|
6
6
|
if (!config.redis) return null;
|
|
7
7
|
if (redisClients[db]) return redisClients[db];
|
|
8
8
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const redisClients = {};
|
|
2
|
-
export default redisClients;
|
|
1
|
+
const redisClients = {};
|
|
2
|
+
export default redisClients;
|
package/redis/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
// import client from './client.js';
|
|
2
|
-
import getRedis from './funcs/getRedis.js';
|
|
3
|
-
// import client from './funcs/redisClients.js';
|
|
4
|
-
|
|
5
|
-
function close(fastify) {
|
|
6
|
-
fastify.rclient.quit();
|
|
7
|
-
// fastify.rclient2.quit();
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
async function plugin(fastify) {
|
|
11
|
-
const client = getRedis({ db: 0, funcs: fastify });
|
|
12
|
-
client.getJSON = client.get;
|
|
13
|
-
fastify.decorate('rclient', client);
|
|
14
|
-
fastify.decorate('getRedis', getRedis);
|
|
15
|
-
// fastify.decorate('rclient2', client2);
|
|
16
|
-
fastify.addHook('onClose', close);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default plugin;
|
|
1
|
+
// import client from './client.js';
|
|
2
|
+
import getRedis from './funcs/getRedis.js';
|
|
3
|
+
// import client from './funcs/redisClients.js';
|
|
4
|
+
|
|
5
|
+
function close(fastify) {
|
|
6
|
+
fastify.rclient.quit();
|
|
7
|
+
// fastify.rclient2.quit();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async function plugin(fastify) {
|
|
11
|
+
const client = getRedis({ db: 0, funcs: fastify });
|
|
12
|
+
client.getJSON = client.get;
|
|
13
|
+
fastify.decorate('rclient', client);
|
|
14
|
+
fastify.decorate('getRedis', getRedis);
|
|
15
|
+
// fastify.decorate('rclient2', client2);
|
|
16
|
+
fastify.addHook('onClose', close);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default plugin;
|