@friggframework/core 2.0.0-next.125 → 2.0.0-next.126

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.
@@ -9,6 +9,17 @@ const serverlessHttp = require('serverless-http');
9
9
 
10
10
  const log = getLogger('frigg.http');
11
11
 
12
+ const isHttpErrorStatus = (statusCode) =>
13
+ Number.isInteger(statusCode) && statusCode >= 400 && statusCode <= 599;
14
+
15
+ const toBoom = (err) => {
16
+ if (err.isBoom) return err;
17
+ if (err.isClientSafe === true && isHttpErrorStatus(err.statusCode)) {
18
+ return Boom.boomify(err, { statusCode: err.statusCode });
19
+ }
20
+ return Boom.boomify(err);
21
+ };
22
+
12
23
  const createApp = (applyMiddleware) => {
13
24
  const app = express();
14
25
 
@@ -27,7 +38,7 @@ const createApp = (applyMiddleware) => {
27
38
 
28
39
  // The express boundary: send the error response and log it one time.
29
40
  app.use((err, req, res, next) => {
30
- const boomError = err.isBoom ? err : Boom.boomify(err);
41
+ const boomError = toBoom(err);
31
42
  const {
32
43
  output: { statusCode = 500 },
33
44
  } = boomError;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@friggframework/core",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "2.0.0-next.125",
4
+ "version": "2.0.0-next.126",
5
5
  "dependencies": {
6
6
  "@aws-sdk/client-apigatewaymanagementapi": "^3.588.0",
7
7
  "@aws-sdk/client-kms": "^3.588.0",
@@ -11,7 +11,7 @@
11
11
  "@aws-sdk/client-sqs": "^3.588.0",
12
12
  "@aws-sdk/client-ssm": "^3.588.0",
13
13
  "@aws-sdk/s3-request-presigner": "^3.588.0",
14
- "@friggframework/schemas": "2.0.0-next.125",
14
+ "@friggframework/schemas": "2.0.0-next.126",
15
15
  "@hapi/boom": "^10.0.1",
16
16
  "@opentelemetry/api": "^1.9.1",
17
17
  "@opentelemetry/context-async-hooks": "^2.9.0",
@@ -49,9 +49,9 @@
49
49
  }
50
50
  },
51
51
  "devDependencies": {
52
- "@friggframework/eslint-config": "2.0.0-next.125",
53
- "@friggframework/prettier-config": "2.0.0-next.125",
54
- "@friggframework/test": "2.0.0-next.125",
52
+ "@friggframework/eslint-config": "2.0.0-next.126",
53
+ "@friggframework/prettier-config": "2.0.0-next.126",
54
+ "@friggframework/test": "2.0.0-next.126",
55
55
  "@prisma/client": "^6.19.3",
56
56
  "@types/lodash": "4.17.15",
57
57
  "@typescript-eslint/eslint-plugin": "^8.0.0",
@@ -92,5 +92,5 @@
92
92
  "publishConfig": {
93
93
  "access": "public"
94
94
  },
95
- "gitHead": "a64e5964dd1a945ce6439df062d79d637d861caf"
95
+ "gitHead": "be8690d56e4e772fc744f414a7e3bed7363ad9b5"
96
96
  }
@@ -119,7 +119,19 @@ class TokenRepositoryDocumentDB extends TokenRepositoryInterface {
119
119
 
120
120
  getJSONTokenFromBase64BufferToken(buffer) {
121
121
  const tokenStr = Buffer.from(buffer.trim(), 'base64').toString('ascii');
122
- return JSON.parse(tokenStr);
122
+ let jsonToken;
123
+ try {
124
+ jsonToken = JSON.parse(tokenStr);
125
+ } catch {
126
+ jsonToken = null;
127
+ }
128
+ if (
129
+ !['string', 'number'].includes(typeof jsonToken?.id) ||
130
+ typeof jsonToken?.token !== 'string'
131
+ ) {
132
+ throw new ClientSafeError('Invalid Token: Token is malformed', 401);
133
+ }
134
+ return jsonToken;
123
135
  }
124
136
 
125
137
  _mapToken(record) {
@@ -212,7 +212,19 @@ class TokenRepositoryMongo extends TokenRepositoryInterface {
212
212
  */
213
213
  getJSONTokenFromBase64BufferToken(buffer) {
214
214
  const tokenStr = Buffer.from(buffer.trim(), 'base64').toString('ascii');
215
- return JSON.parse(tokenStr);
215
+ let jsonToken;
216
+ try {
217
+ jsonToken = JSON.parse(tokenStr);
218
+ } catch {
219
+ jsonToken = null;
220
+ }
221
+ if (
222
+ !['string', 'number'].includes(typeof jsonToken?.id) ||
223
+ typeof jsonToken?.token !== 'string'
224
+ ) {
225
+ throw new ClientSafeError('Invalid Token: Token is malformed', 401);
226
+ }
227
+ return jsonToken;
216
228
  }
217
229
  }
218
230
 
@@ -257,7 +257,19 @@ class TokenRepositoryPostgres extends TokenRepositoryInterface {
257
257
  */
258
258
  getJSONTokenFromBase64BufferToken(buffer) {
259
259
  const tokenStr = Buffer.from(buffer.trim(), 'base64').toString('ascii');
260
- return JSON.parse(tokenStr);
260
+ let jsonToken;
261
+ try {
262
+ jsonToken = JSON.parse(tokenStr);
263
+ } catch {
264
+ jsonToken = null;
265
+ }
266
+ if (
267
+ !['string', 'number'].includes(typeof jsonToken?.id) ||
268
+ typeof jsonToken?.token !== 'string'
269
+ ) {
270
+ throw new ClientSafeError('Invalid Token: Token is malformed', 401);
271
+ }
272
+ return jsonToken;
261
273
  }
262
274
  }
263
275