@opengis/fastify-table 2.1.17 → 2.1.19

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.
@@ -1 +1 @@
1
- {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/auth/funcs/jwt.ts"],"names":[],"mappings":"AAmBA,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,mBAI5C;AAED,wBAAsB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,oBAI9D;AAED,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,oBAAQ,EAAE,EAAE,EAAE,MAAM,UAsBxE;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;;;EA8B/D;;AAED,wBAAoB"}
1
+ {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/auth/funcs/jwt.ts"],"names":[],"mappings":"AAkBA,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,mBAI5C;AAED,wBAAsB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,oBAI9D;AAED,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,oBAAQ,EAAE,EAAE,EAAE,MAAM,UAsBxE;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;;;EA8B/D;;AAED,wBAAoB"}
@@ -0,0 +1,13 @@
1
+ import type { ExtendedRequest } from "../../../types/core.js";
2
+ export default function checkJWT(req: ExtendedRequest): Promise<{
3
+ error: string;
4
+ code: number;
5
+ token?: undefined;
6
+ valid?: undefined;
7
+ } | {
8
+ token: string;
9
+ valid: boolean;
10
+ error?: undefined;
11
+ code?: undefined;
12
+ } | null>;
13
+ //# sourceMappingURL=checkJWT.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkJWT.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/policy/funcs/checkJWT.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,wBAAwB,CAAC;AAMhC,wBAA8B,QAAQ,CAAC,GAAG,EAAE,eAAe;;;;;;;;;;UA4D1D"}
@@ -0,0 +1,48 @@
1
+ import getIP from "./getIP.js";
2
+ import logger from "../../logger/getLogger.js";
3
+ import { verify } from "../../auth/funcs/jwt.js";
4
+ export default async function checkJWT(req) {
5
+ const { originalUrl: path, headers, method, routeOptions, pg } = req;
6
+ const ip = getIP(req);
7
+ const { policy, auth, scope } = (routeOptions?.config ||
8
+ {});
9
+ const requireUser = Array.isArray(policy)
10
+ ? policy.includes("user")
11
+ : ["L1", "L2", "L3"].includes(policy || "");
12
+ const requireJWT = auth === "user-jwt";
13
+ const user = req.user || req.session?.passport?.user;
14
+ // skip entirely if not required via API config or alternative exists
15
+ if (!requireJWT || (requireUser && user)) {
16
+ return null;
17
+ }
18
+ const jwtToken = headers.authorization?.split(" ")?.[1];
19
+ // restict access if header is not provided at all
20
+ if (!jwtToken) {
21
+ logger.file("policy/jwt", {
22
+ path,
23
+ method,
24
+ message: "unauthorized",
25
+ ip,
26
+ uid: user?.uid,
27
+ });
28
+ return { error: "unauthorized", code: 401 };
29
+ }
30
+ const secret = pg && scope
31
+ ? await pg
32
+ .query(`select client_secret_hash from oauth.clients where name=$1 and token_endpoint_auth_method=$2`, [scope, "private_key_jwt"])
33
+ .then((el) => el?.rows?.[0]?.client_secret_hash)
34
+ : null;
35
+ const isJWTValid = verify(jwtToken, secret, ip);
36
+ // restrict access if token is invalid
37
+ if (requireJWT && !isJWTValid) {
38
+ logger.file("policy/jwt", {
39
+ path,
40
+ method,
41
+ message: "forbidden",
42
+ ip,
43
+ uid: user?.uid,
44
+ });
45
+ return { error: "forbidden", code: 403 };
46
+ }
47
+ return { token: jwtToken, valid: true };
48
+ }
@@ -1,5 +1,5 @@
1
1
  import type { ExtendedRequest } from "../../../types/core.js";
2
- export default function checkPolicy(req: ExtendedRequest): {
2
+ export default function checkPolicy(req: ExtendedRequest, jwt?: any): {
3
3
  error: string;
4
4
  code: number;
5
5
  } | null;
@@ -1 +1 @@
1
- {"version":3,"file":"checkPolicy.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/policy/funcs/checkPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,wBAAwB,CAAC;AAKhC,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,GAAG,EAAE,eAAe;;;SAoKvD"}
1
+ {"version":3,"file":"checkPolicy.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/policy/funcs/checkPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,wBAAwB,CAAC;AAKhC,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,CAAC,EAAE,GAAG;;;SAqKlE"}
@@ -1,6 +1,6 @@
1
1
  import { config, logger } from "../../../../utils.js";
2
2
  import block from "../sqlInjection.js";
3
- export default function checkPolicy(req) {
3
+ export default function checkPolicy(req, jwt) {
4
4
  const { originalUrl: path, hostname, query, params, headers, method, routeOptions, } = req;
5
5
  const user = req.user || req.session?.passport?.user;
6
6
  const body = req.body
@@ -80,7 +80,7 @@ export default function checkPolicy(req) {
80
80
  return { error: "access restricted: 2", code: 409 };
81
81
  }
82
82
  // ! user required, but not logged in
83
- if (requireUser && !user) {
83
+ if (requireUser && !user && !jwt?.valid) {
84
84
  logger.file("policy/user", {
85
85
  path,
86
86
  method,
@@ -110,7 +110,8 @@ export default function checkPolicy(req) {
110
110
  if (isAdmin &&
111
111
  !req.url?.includes?.("/assets") &&
112
112
  !config.debug &&
113
- !user?.uid) {
113
+ !user?.uid &&
114
+ !jwt?.valid) {
114
115
  logger.file("policy/api", {
115
116
  path,
116
117
  method,
@@ -0,0 +1,3 @@
1
+ declare const getIP: (req: any) => any;
2
+ export default getIP;
3
+ //# sourceMappingURL=getIP.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getIP.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/policy/funcs/getIP.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,KAAK,GAAI,KAAK,GAAG,QASb,CAAC;AAEX,eAAe,KAAK,CAAC"}
@@ -0,0 +1,8 @@
1
+ const getIP = (req) => (req.headers?.["x-real-ip"] ||
2
+ req.headers?.["x-forwarded-for"] ||
3
+ req.ip ||
4
+ req.connection?.remoteAddress ||
5
+ "")
6
+ .split(":")
7
+ .pop();
8
+ export default getIP;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/policy/index.ts"],"names":[],"mappings":"AAKA,iBAAS,MAAM,CAAC,OAAO,EAAE,GAAG,QAiC3B;AAED,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/policy/index.ts"],"names":[],"mappings":"AAMA,iBAAS,MAAM,CAAC,OAAO,EAAE,GAAG,QAqC3B;AAED,eAAe,MAAM,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import config from "../../../config.js";
2
2
  import checkPolicy from "./funcs/checkPolicy.js";
3
3
  import checkPermissions from "./funcs/checkPermissions.js";
4
+ import checkJWT from "./funcs/checkJWT.js";
4
5
  function plugin(fastify) {
5
6
  fastify.addHook("preHandler", async (request, reply) => {
6
7
  // ! skip locally, skip tests
@@ -22,7 +23,11 @@ function plugin(fastify) {
22
23
  if (resp1) {
23
24
  return reply.status(resp1.code || 403).send(resp1);
24
25
  }
25
- const resp = checkPolicy(request);
26
+ const jwt = await checkJWT(request);
27
+ if (!jwt?.valid && jwt?.code) {
28
+ return reply.status(jwt.code).send(jwt);
29
+ }
30
+ const resp = checkPolicy(request, jwt);
26
31
  if (resp) {
27
32
  return reply.status(resp.code || 403).send(resp);
28
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../../../../../../server/routes/auth/controllers/jwt/authorize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAyBvC,wBAA8B,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,kBAkHpE"}
1
+ {"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../../../../../../server/routes/auth/controllers/jwt/authorize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAyBvC,wBAA8B,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,kBAmHpE"}
@@ -90,6 +90,7 @@ export default async function authorize(req, reply) {
90
90
  if (req.method === "POST") {
91
91
  return reply.status(200).send({
92
92
  code,
93
+ expire: expireMsec,
93
94
  redirect_uri: href,
94
95
  });
95
96
  }
@@ -1 +1 @@
1
- {"version":3,"file":"suggest.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/suggest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAuBpD,wBAAsB,kBAAkB,CAAC,EACvC,KAAK,EACL,QAAQ,EACR,MAAM,EACN,UAAU,EACV,QAAQ,EACR,UAAU,EACV,GAAG,EACH,EAAqB,GACtB,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,UAAU,CAAC;CACjB;;;;;UA+EA;AAED,wBAA8B,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,gBA6WzD"}
1
+ {"version":3,"file":"suggest.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/suggest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAuBpD,wBAAsB,kBAAkB,CAAC,EACvC,KAAK,EACL,QAAQ,EACR,MAAM,EACN,UAAU,EACV,QAAQ,EACR,UAAU,EACV,GAAG,EACH,EAAqB,GACtB,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,UAAU,CAAC;CACjB;;;;;UA+EA;AAED,wBAA8B,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,gBAmXzD"}
@@ -183,7 +183,7 @@ export default async function suggest(req, reply) {
183
183
  ? arr
184
184
  ?.filter((el) => !lower ||
185
185
  (el[lang] || el.text)?.toLowerCase()?.indexOf(lower) !== -1)
186
- ?.filter((el) => !query.val || el.id === query.val)
186
+ ?.filter((el) => !query.val || query.val?.split?.(",")?.includes?.(el.id))
187
187
  : arr;
188
188
  const data2 = data1.filter((el) => el.id && vals.includes(el.id.toString()));
189
189
  const data = data2.slice(0, Math.min(query.limit || limit, limit));
@@ -224,7 +224,7 @@ export default async function suggest(req, reply) {
224
224
  ? arr
225
225
  ?.filter((el) => !lower ||
226
226
  (el[lang] || el.text)?.toLowerCase()?.indexOf(lower) !== -1)
227
- ?.filter((el) => !query.val || el.id === query.val)
227
+ ?.filter((el) => !query.val || query.val?.split?.(",")?.includes?.(el.id))
228
228
  : arr;
229
229
  const data = data1.slice(0, Math.min(query.limit || limit, limit));
230
230
  if (config.debug) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.1.17",
3
+ "version": "2.1.19",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [