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