@opengis/fastify-table 1.2.22 → 1.2.24
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/package.json
CHANGED
|
@@ -71,16 +71,16 @@ export default function checkPolicy(req, reply) {
|
|
|
71
71
|
|
|
72
72
|
/* === 0. policy: unauthorized access from admin URL === */
|
|
73
73
|
const refererHost = headers?.referer?.match?.(/(https?:\/\/[^\/]+)/g)?.[0];
|
|
74
|
-
const validToken = headers?.token && refererHost && config.auth?.tokens?.[refererHost] === headers.token;
|
|
74
|
+
const validToken = (req.ip === '127.0.0.1' || config.debug) && headers?.uid && headers?.token && refererHost && config.auth?.tokens?.[refererHost] === headers.token;
|
|
75
75
|
if (!validToken && !user?.uid && !config.auth?.disable && isAdmin && !policy.includes('public') && !skipCheckPolicyRoutes.filter((el) => el).find(el => req.url.includes(el))) {
|
|
76
76
|
logger.file('policy/unauthorized', {
|
|
77
|
-
path, method, params, query, body, referer: refererHost, token: headers?.token, headers, message: 'unauthorized',
|
|
77
|
+
path, method, params, query, body, referer: refererHost, token: headers?.token, userId: headers?.uid, ip: req.ip, headers, message: 'unauthorized',
|
|
78
78
|
});
|
|
79
79
|
return reply.status(401).send('unauthorized');
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/* === 3. policy: user === */
|
|
83
|
-
if (!user && policy.includes('user')) {
|
|
83
|
+
if (!validToken && !user && policy.includes('user')) {
|
|
84
84
|
logger.file('policy/user', {
|
|
85
85
|
path, method, params, query, body, message: 'access restricted: 3',
|
|
86
86
|
});
|
|
@@ -88,7 +88,7 @@ export default function checkPolicy(req, reply) {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
/* === 4. policy: referer === */
|
|
91
|
-
if (!headers?.referer?.includes?.(hostname) && policy.includes('referer') && !config.local && !config.debug) {
|
|
91
|
+
if (!validToken && !headers?.referer?.includes?.(hostname) && policy.includes('referer') && !config.local && !config.debug) {
|
|
92
92
|
logger.file('policy/referer', {
|
|
93
93
|
path, method, params, query, body, message: 'access restricted: 4', uid: user?.uid,
|
|
94
94
|
});
|
|
@@ -96,7 +96,7 @@ export default function checkPolicy(req, reply) {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
/* === 5. policy: site auth === */
|
|
99
|
-
if (!policy.includes('site') && !isAdmin && !config.local && !config.debug && !unittest
|
|
99
|
+
if (!validToken && !policy.includes('site') && !isAdmin && !config.local && !config.debug && !unittest
|
|
100
100
|
&& !['/auth/redirect', '/logout', `${config.prefix || '/api'}/login`].find(el => path.includes(el))) {
|
|
101
101
|
logger.file('policy/site', {
|
|
102
102
|
path, method, params, query, body, message: 'access restricted: 5', uid: user?.uid,
|
|
@@ -105,7 +105,7 @@ export default function checkPolicy(req, reply) {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
/* === 6. base policy: block api, except login === */
|
|
108
|
-
if (isAdmin && !isUser && isServer && !config.local && !config.debug
|
|
108
|
+
if (!validToken && isAdmin && !isUser && isServer && !config.local && !config.debug
|
|
109
109
|
&& !path.startsWith(`${config.prefix || '/api'}/login`)) {
|
|
110
110
|
logger.file('policy/api', {
|
|
111
111
|
path, method, params, query, body, message: 'access restricted: 6', uid: user?.uid,
|
|
@@ -113,5 +113,6 @@ export default function checkPolicy(req, reply) {
|
|
|
113
113
|
return reply.status(403).send('access restricted: 6');
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
// console.log(headers);
|
|
116
117
|
return null;
|
|
117
118
|
}
|