@voyantjs/hono 0.6.8 → 0.6.9

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":"cors.d.ts","sourceRoot":"","sources":["../../src/middleware/cors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAE7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAWjD,wBAAgB,IAAI,IAAI,iBAAiB,CAAC;IAAE,QAAQ,EAAE,cAAc,CAAA;CAAE,CAAC,CAwCtE"}
1
+ {"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../../src/middleware/cors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAE7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAkCjD,wBAAgB,IAAI,IAAI,iBAAiB,CAAC;IAAE,QAAQ,EAAE,cAAc,CAAA;CAAE,CAAC,CAwCtE"}
@@ -7,11 +7,36 @@ function parseAllowlist(env) {
7
7
  .map((s) => s.trim())
8
8
  .filter(Boolean);
9
9
  }
10
+ function isLocalhostOrigin(origin) {
11
+ try {
12
+ const { hostname } = new URL(origin);
13
+ return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";
14
+ }
15
+ catch {
16
+ return false;
17
+ }
18
+ }
19
+ function matchesPattern(origin, pattern) {
20
+ if (pattern === origin)
21
+ return true;
22
+ if (!pattern.includes("*"))
23
+ return false;
24
+ const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
25
+ return new RegExp(`^${escaped}$`).test(origin);
26
+ }
27
+ function isAllowedOrigin(origin, allowlist) {
28
+ if (allowlist.length === 0)
29
+ return false;
30
+ const hasLocalhostEntry = allowlist.some((p) => isLocalhostOrigin(p) || p.includes("localhost"));
31
+ if (hasLocalhostEntry && isLocalhostOrigin(origin))
32
+ return true;
33
+ return allowlist.some((p) => matchesPattern(origin, p));
34
+ }
10
35
  export function cors() {
11
36
  return async (c, next) => {
12
37
  const origin = c.req.header("origin") || "";
13
38
  const allowlist = parseAllowlist(c.env);
14
- const allowed = allowlist.length === 0 ? false : allowlist.includes(origin);
39
+ const allowed = isAllowedOrigin(origin, allowlist);
15
40
  if (origin && !allowed) {
16
41
  console.warn("[CORS] Origin not in allowlist - CORS headers will NOT be set", {
17
42
  origin,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voyantjs/hono",
3
- "version": "0.6.8",
3
+ "version": "0.6.9",
4
4
  "license": "FSL-1.1-Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -77,10 +77,10 @@
77
77
  "drizzle-orm": "^0.45.2",
78
78
  "hono": "^4.12.10",
79
79
  "zod": "^4.3.6",
80
- "@voyantjs/core": "0.6.8",
81
- "@voyantjs/db": "0.6.8",
82
- "@voyantjs/types": "0.6.8",
83
- "@voyantjs/utils": "0.6.8"
80
+ "@voyantjs/core": "0.6.9",
81
+ "@voyantjs/db": "0.6.9",
82
+ "@voyantjs/types": "0.6.9",
83
+ "@voyantjs/utils": "0.6.9"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@cloudflare/workers-types": "^4.20260403.1",