hono 3.1.1 → 3.1.3

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.
@@ -104,12 +104,16 @@ const verify = async (token, secret, alg = import_types.AlgorithmTypes.HS256) =>
104
104
  throw new import_types2.JwtTokenInvalid(token);
105
105
  }
106
106
  const { payload } = decode(token);
107
- if (payload.nbf && payload.nbf > Math.floor(Date.now() / 1e3)) {
107
+ const now = Math.floor(Date.now() / 1e3);
108
+ if (payload.nbf && payload.nbf > now) {
108
109
  throw new import_types2.JwtTokenNotBefore(token);
109
110
  }
110
- if (payload.exp && payload.exp <= Math.floor(Date.now() / 1e3)) {
111
+ if (payload.exp && payload.exp <= now) {
111
112
  throw new import_types2.JwtTokenExpired(token);
112
113
  }
114
+ if (payload.iat && now < payload.iat) {
115
+ throw new import_types.JwtTokenIssuedAt(now, payload.iat);
116
+ }
113
117
  const signaturePart = tokenParts.slice(0, 2).join(".");
114
118
  const signature = await signing(signaturePart, secret, alg);
115
119
  const encodedSignature = encodeSignaturePart(signature);
@@ -23,6 +23,7 @@ __export(types_exports, {
23
23
  JwtAlorithmNotImplemented: () => JwtAlorithmNotImplemented,
24
24
  JwtTokenExpired: () => JwtTokenExpired,
25
25
  JwtTokenInvalid: () => JwtTokenInvalid,
26
+ JwtTokenIssuedAt: () => JwtTokenIssuedAt,
26
27
  JwtTokenNotBefore: () => JwtTokenNotBefore,
27
28
  JwtTokenSignatureMismatched: () => JwtTokenSignatureMismatched
28
29
  });
@@ -52,6 +53,12 @@ class JwtTokenExpired extends Error {
52
53
  this.name = "JwtTokenExpired";
53
54
  }
54
55
  }
56
+ class JwtTokenIssuedAt extends Error {
57
+ constructor(currentTimestamp, iat) {
58
+ super(`Incorrect "iat" claim must be a older than "${currentTimestamp}" (iat: "${iat}")`);
59
+ this.name = "JwtTokenIssuedAt";
60
+ }
61
+ }
55
62
  class JwtTokenSignatureMismatched extends Error {
56
63
  constructor(token) {
57
64
  super(`token(${token}) signature mismatched`);
@@ -71,6 +78,7 @@ var AlgorithmTypes = /* @__PURE__ */ ((AlgorithmTypes2) => {
71
78
  JwtAlorithmNotImplemented,
72
79
  JwtTokenExpired,
73
80
  JwtTokenInvalid,
81
+ JwtTokenIssuedAt,
74
82
  JwtTokenNotBefore,
75
83
  JwtTokenSignatureMismatched
76
84
  });
@@ -87,7 +87,7 @@ const getPattern = (label) => {
87
87
  const getPathFromURL = (url, strict = true) => {
88
88
  const queryIndex = url.indexOf("?", 8);
89
89
  const result = url.substring(url.indexOf("/", 8), queryIndex === -1 ? url.length : queryIndex);
90
- if (strict === false && result.endsWith("/")) {
90
+ if (strict === false && /.+\/$/.test(result)) {
91
91
  return result.slice(0, -1);
92
92
  }
93
93
  return result;
@@ -142,7 +142,7 @@ const getQueryParam = (queryString, key) => {
142
142
  const v = strings.substring(eqIndex + 1);
143
143
  const k = strings.substring(0, eqIndex);
144
144
  if (key === k) {
145
- return /\%/.test(v) ? decodeURI(v) : v;
145
+ return /\%/.test(v) ? decodeURIComponent(v) : v;
146
146
  } else {
147
147
  results[k] || (results[k] = v);
148
148
  }
@@ -164,7 +164,7 @@ const getQueryParams = (queryString, key) => {
164
164
  if (v === void 0)
165
165
  v = "";
166
166
  results[k] || (results[k] = []);
167
- results[k].push(v.indexOf("%") !== -1 ? decodeURI(v) : v);
167
+ results[k].push(v.indexOf("%") !== -1 ? decodeURIComponent(v) : v);
168
168
  }
169
169
  if (key)
170
170
  return results[key] ? results[key] : null;
@@ -4,7 +4,7 @@ export declare class JwtAlgorithmNotImplemented extends Error {
4
4
  /**
5
5
  * Export for backward compatibility
6
6
  * @deprecated Use JwtAlgorithmNotImplemented instead
7
- **/
7
+ **/
8
8
  export declare const JwtAlorithmNotImplemented: typeof JwtAlgorithmNotImplemented;
9
9
  export declare class JwtTokenInvalid extends Error {
10
10
  constructor(token: string);
@@ -15,6 +15,9 @@ export declare class JwtTokenNotBefore extends Error {
15
15
  export declare class JwtTokenExpired extends Error {
16
16
  constructor(token: string);
17
17
  }
18
+ export declare class JwtTokenIssuedAt extends Error {
19
+ constructor(currentTimestamp: number, iat: number);
20
+ }
18
21
  export declare class JwtTokenSignatureMismatched extends Error {
19
22
  constructor(token: string);
20
23
  }
@@ -1,6 +1,6 @@
1
1
  // src/utils/jwt/jwt.ts
2
2
  import { encodeBase64Url, decodeBase64Url } from "../../utils/encode.js";
3
- import { AlgorithmTypes } from "./types.js";
3
+ import { AlgorithmTypes, JwtTokenIssuedAt } from "./types.js";
4
4
  import {
5
5
  JwtTokenInvalid,
6
6
  JwtTokenNotBefore,
@@ -68,12 +68,16 @@ var verify = async (token, secret, alg = AlgorithmTypes.HS256) => {
68
68
  throw new JwtTokenInvalid(token);
69
69
  }
70
70
  const { payload } = decode(token);
71
- if (payload.nbf && payload.nbf > Math.floor(Date.now() / 1e3)) {
71
+ const now = Math.floor(Date.now() / 1e3);
72
+ if (payload.nbf && payload.nbf > now) {
72
73
  throw new JwtTokenNotBefore(token);
73
74
  }
74
- if (payload.exp && payload.exp <= Math.floor(Date.now() / 1e3)) {
75
+ if (payload.exp && payload.exp <= now) {
75
76
  throw new JwtTokenExpired(token);
76
77
  }
78
+ if (payload.iat && now < payload.iat) {
79
+ throw new JwtTokenIssuedAt(now, payload.iat);
80
+ }
77
81
  const signaturePart = tokenParts.slice(0, 2).join(".");
78
82
  const signature = await signing(signaturePart, secret, alg);
79
83
  const encodedSignature = encodeSignaturePart(signature);
@@ -24,6 +24,12 @@ var JwtTokenExpired = class extends Error {
24
24
  this.name = "JwtTokenExpired";
25
25
  }
26
26
  };
27
+ var JwtTokenIssuedAt = class extends Error {
28
+ constructor(currentTimestamp, iat) {
29
+ super(`Incorrect "iat" claim must be a older than "${currentTimestamp}" (iat: "${iat}")`);
30
+ this.name = "JwtTokenIssuedAt";
31
+ }
32
+ };
27
33
  var JwtTokenSignatureMismatched = class extends Error {
28
34
  constructor(token) {
29
35
  super(`token(${token}) signature mismatched`);
@@ -42,6 +48,7 @@ export {
42
48
  JwtAlorithmNotImplemented,
43
49
  JwtTokenExpired,
44
50
  JwtTokenInvalid,
51
+ JwtTokenIssuedAt,
45
52
  JwtTokenNotBefore,
46
53
  JwtTokenSignatureMismatched
47
54
  };
package/dist/utils/url.js CHANGED
@@ -57,7 +57,7 @@ var getPattern = (label) => {
57
57
  var getPathFromURL = (url, strict = true) => {
58
58
  const queryIndex = url.indexOf("?", 8);
59
59
  const result = url.substring(url.indexOf("/", 8), queryIndex === -1 ? url.length : queryIndex);
60
- if (strict === false && result.endsWith("/")) {
60
+ if (strict === false && /.+\/$/.test(result)) {
61
61
  return result.slice(0, -1);
62
62
  }
63
63
  return result;
@@ -112,7 +112,7 @@ var getQueryParam = (queryString, key) => {
112
112
  const v = strings.substring(eqIndex + 1);
113
113
  const k = strings.substring(0, eqIndex);
114
114
  if (key === k) {
115
- return /\%/.test(v) ? decodeURI(v) : v;
115
+ return /\%/.test(v) ? decodeURIComponent(v) : v;
116
116
  } else {
117
117
  results[k] || (results[k] = v);
118
118
  }
@@ -134,7 +134,7 @@ var getQueryParams = (queryString, key) => {
134
134
  if (v === void 0)
135
135
  v = "";
136
136
  results[k] || (results[k] = []);
137
- results[k].push(v.indexOf("%") !== -1 ? decodeURI(v) : v);
137
+ results[k].push(v.indexOf("%") !== -1 ? decodeURIComponent(v) : v);
138
138
  }
139
139
  if (key)
140
140
  return results[key] ? results[key] : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "3.1.1",
3
+ "version": "3.1.3",
4
4
  "description": "Ultrafast web framework for the Edge",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",
@@ -16,8 +16,8 @@
16
16
  "test:fastly": "jest --config ./jest.fastly.config.js",
17
17
  "test:lagon": "start-server-and-test \"lagon dev test_lagon/index.ts\" http://127.0.0.1:1234 \"yarn jest test_lagon/index.test.ts --testMatch '**/*.test.ts'\"",
18
18
  "test:node": "env NAME=Node jest --config ./jest.node.config.js",
19
- "test:wrangler": "jest --config ./jest.lambda.config.js",
20
- "test:lambda": "env NAME=Node jest --config ./jest.node.config.js",
19
+ "test:wrangler": "jest --config ./jest.wrangler.config.js",
20
+ "test:lambda": "env NAME=Node jest --config ./jest.lambda.config.js",
21
21
  "test:all": "yarn test && yarn test:deno && yarn test:bun && yarn test:fastly && yarn test:lagon && yarn test:node && yarn test:wrangler && yarn test:lambda",
22
22
  "lint": "eslint --ext js,ts src .eslintrc.cjs",
23
23
  "lint:fix": "eslint --ext js,ts src .eslintrc.cjs --fix",