GHSA-72gr-qfp7-vwhw: H3 Path Traversal Vulnerability

MODERATE
CVSS 5.9
CWE-22
Published
Advisory Summary

GHSA-72gr-qfp7-vwhw is a MODERATE (CVSS 5.9) path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting H3 libraries in the npm ecosystem. The issue involves double decoding in `servestatic` bypasses `resolvedotsegments` path traversal protection via `%252e%252e`. Remediation is available by upgrading affected packages to version 1.15.9.

GHSA-72gr-qfp7-vwhw at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-72gr-qfp7-vwhw
Severity MODERATE
CVSS v3.1 Base Score 5.9
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product H3
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 5.9

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity None (I:N)
Availability None (A:N)

How to Fix GHSA-72gr-qfp7-vwhw

To remediate this vulnerability, upgrade all affected H3 dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

h3 fixed: 1.15.9
npm install h3@1.15.9
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls h3

How to Check if You Are Affected

To determine whether your Node.js application is affected by GHSA-72gr-qfp7-vwhw, inspect your project dependencies using npm:

npm ls h3

Analyze the terminal output to locate any version of H3 in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.15.9), your application is affected.

Note: The npm ls h3 command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. In H3, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

## Summary The `serveStatic` utility in h3 applies a redundant `decodeURI()` call to the request pathname after `H3Event` has already performed percent-decoding with `%25` preservation. This double decoding converts `%252e%252e` into `%2e%2e`, which bypasses `resolveDotSegments()` (since it checks for literal `.` characters, not percent-encoded equivalents). When the resulting asset ID is resolved by URL-based backends (CDN, S3, object storage), `%2e%2e` is interpreted as `..` per the URL Standard, enabling path traversal to read arbitrary files from the backend. ## Details The vulnerability is a conflict between two decoding stages: **Stage 1 — `H3Event` constructor** (`src/event.ts:65-69`): ```typescript if (url.pathname.includes("%")) { url.pathname = decodeURI( url.pathname.includes("%25") ? url.pathname.replace(/%25/g, "%2525") : url.pathname, ); } ``` This correctly preserves `%25` sequences by escaping them before decoding. A request for `/%252e%252e/etc/passwd` produces `event.url.pathname` = `/%2e%2e/etc/passwd` — the `%25` was preserved so `%252e` became `%2e` (not `.`). **Stage 2 — `serveStatic`** (`src/utils/static.ts:86-88`): ```typescript const originalId = resolveDotSegments( decodeURI(withLeadingSlash(withoutTrailingSlash(event.url.pathname))), ); ``` This applies a **second** `decodeURI()`, which decodes `%2e` → `.`, producing `/../../../etc/passwd`. However, the decoding happens *inside* the `resolveDotSegments()` call argument — `decodeURI` runs first, then `resolveDotSegments` processes the result. Wait — re-examining the flow more carefully: 1. Input pathname after event.ts: `/%2e%2e/%2e%2e/etc/passwd` 2. `decodeURI()` in static.ts converts `%2e` → `.`, producing: `/../../../etc/passwd` 3. `resolveDotSegments("/../../../etc/passwd")` **does** resolve `..` segments, clamping to `/etc/passwd` The actual bypass is subtler. `decodeURI()` does **not** decode `%2e` — it only decodes characters that `encodeURI` would encode. Since `.` is never encoded by `encodeURI`, `%2e` is **not** decoded by `decodeURI()`. So the chain is: 1. Request: `/%252e%252e/%252e%252e/etc/passwd` 2. After event.ts decode: `/%2e%2e/%2e%2e/etc/passwd` 3. `decodeURI()` in static.ts: `/%2e%2e/%2e%2e/etc/passwd` (unchanged — `decodeURI` doesn't decode `%2e`) 4. `resolveDotSegments()` fast-returns at line 56 because `%2e` contains no literal `.` character: ```typescript if (!path.includes(".")) { return path; } ``` 5. Asset ID `/%2e%2e/%2e%2e/etc/passwd` is passed to `getMeta()` and `getContents()` callbacks 6. URL-based backends resolve `%2e%2e` as `..` per RFC 3986 / URL Standard The root cause is `resolveDotSegments()` only checks for literal `.` characters and does not account for percent-encoded dot sequences (`%2e`). The `decodeURI()` in static.ts is redundant (event.ts already decodes) but is not the direct cause — the real gap is that `%2e%2e` survives as a traversal payload through both decoding stages and `resolveDotSegments`. ## PoC **1. Create a minimal h3 server with a URL-based static backend:** ```javascript // server.mjs import { H3, serveStatic } from "h3"; import { serve } from "srvx"; const app = new H3(); app.get("/**", (event) => { return serveStatic(event, { getMeta(id) { console.log("[getMeta] asset ID:", id); // Simulate URL-based backend (CDN/S3) const url = new URL(id, "https://cdn.example.com/static/"); console.log("[getMeta] resolved URL:", url.href); return { type: "text/plain" }; }, getContents(id) { console.log("[getContents] asset ID:", id); const url = new URL(id, "https://cdn.example.com/static/"); console.log("[getContents] resolved URL:", url.href); return `Fetched from: ${url.href}`; }, }); }); serve({ fetch: app.fetch, port: 3000 }); ``` **2. Send the double-encoded traversal request:** ```bash curl -v 'http://localhost:3000/%252e%252e/%252e%252e/etc/passwd' ``` **3. Observe server logs:** ``` [getMeta] asset ID: /%2e%2e/%2e%2e/etc/passwd [getMeta] resolved URL: https://cdn.example.com/etc/passwd [getContents] asset ID: /%2e%2e/%2e%2e/etc/passwd [getContents] resolved URL: https://cdn.example.com/etc/passwd ``` The `%2e%2e` sequences in the asset ID are resolved as `..` by the `URL` constructor, causing the backend URL to traverse from `/static/` to `/etc/passwd`. ## Impact - **Arbitrary file read from backend storage:** An unauthenticated attacker can read files outside the intended static asset directory on any URL-based backend (CDN origins, S3 buckets, object storage, reverse-proxied file servers). - **Sensitive data exposure:** Depending on the backend, this could expose configuration files, credentials, source code, or other tenants' data in shared storage. - **Affected deployments:** Applications using `serveStatic` with callbacks that resolve asset IDs via URL construction (`new URL(id, baseUrl)` or equivalent). This is a common pattern for CDN proxying and cloud object storage backends. Filesystem-based backends using `path.join()` are not affected since `%2e%2e` is not resolved as a traversal sequence by filesystem APIs. ## Recommended Fix The `resolveDotSegments()` function must account for percent-encoded dot sequences. Additionally, the redundant `decodeURI()` in `serveStatic` should be removed since `H3Event` already handles decoding. **Fix 1 — Remove redundant `decodeURI` in `src/utils/static.ts:86-88`:** ```diff const originalId = resolveDotSegments( - decodeURI(withLeadingSlash(withoutTrailingSlash(event.url.pathname))), + withLeadingSlash(withoutTrailingSlash(event.url.pathname)), ); ``` **Fix 2 — Harden `resolveDotSegments` in `src/utils/internal/path.ts:55-73` to handle percent-encoded dots:** ```diff export function resolveDotSegments(path: string): string { - if (!path.includes(".")) { + if (!path.includes(".") && !path.toLowerCase().includes("%2e")) { return path; } // Normalize backslashes to forward slashes to prevent traversal via `\` - const segments = path.replaceAll("\\", "/").split("/"); + const segments = path.replaceAll("\\", "/") + .replaceAll(/%2e/gi, ".") + .split("/"); const resolved: string[] = []; ``` Both fixes should be applied. Fix 1 removes the unnecessary double-decode. Fix 2 provides defense-in-depth by ensuring `resolveDotSegments` cannot be bypassed with percent-encoded dots regardless of the caller.

GHSA-72gr-qfp7-vwhw Affected H3 Versions

1 component(s)
Fixed Versions:
1.15.9
Product / Package Ecosystem Affected Versions Fixed Version
h3
npm
< 1.15.9
1.15.9

References

Frequently Asked Questions

What is GHSA-72gr-qfp7-vwhw?
GHSA-72gr-qfp7-vwhw is a security vulnerability in H3 involving Double Decoding in `serveStatic` Bypasses `resolveDotSegments` Path Traversal Protection via `%252e%252e` under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which H3 versions are affected?
Affected versions include releases prior to 1.15.9 across affected packages: h3.
What version fixes GHSA-72gr-qfp7-vwhw?
Upgrading to 1.15.9 (or the latest patched release for your respective branch) resolves the vulnerability.
Is h3 affected?
Yes, h3 is affected in releases prior to 1.15.9. Upgrade your dependency to 1.15.9 or later.
What is the CVSS score of GHSA-72gr-qfp7-vwhw?
GHSA-72gr-qfp7-vwhw has a CVSS v3.1 base score of 5.9 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N.
What CWE is associated with GHSA-72gr-qfp7-vwhw?
GHSA-72gr-qfp7-vwhw is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') (The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.).
How can I check npm dependencies for GHSA-72gr-qfp7-vwhw?
Run the dependency tree command: 'npm ls h3'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-72gr-qfp7-vwhw",
  "modified" : "2026-03-20T20:50:09Z",
  "published" : "2026-03-20T20:50:09Z",
  "aliases" : [ ],
  "summary" : "h3: Double Decoding in `serveStatic` Bypasses `resolveDotSegments` Path Traversal Protection via `%252e%252e`",
  "details" : "## Summary\n\nThe `serveStatic` utility in h3 applies a redundant `decodeURI()` call to the request pathname after `H3Event` has already performed percent-decoding with `%25` preservation. This double decoding converts `%252e%252e` into `%2e%2e`, which bypasses `resolveDotSegments()` (since it checks for literal `.` characters, not percent-encoded equivalents). When the resulting asset ID is resolved by URL-based backends (CDN, S3, object storage), `%2e%2e` is interpreted as `..` per the URL Standard, enabling path traversal to read arbitrary files from the backend.\n\n## Details\n\nThe vulnerability is a conflict between two decoding stages:\n\n**Stage 1 — `H3Event` constructor** (`src/event.ts:65-69`):\n\n```typescript\nif (url.pathname.includes(\"%\")) {\n  url.pathname = decodeURI(\n    url.pathname.includes(\"%25\") ? url.pathname.replace(/%25/g, \"%2525\") : url.pathname,\n  );\n}\n```\n\nThis correctly preserves `%25` sequences by escaping them before decoding. A request for `/%252e%252e/etc/passwd` produces `event.url.pathname` = `/%2e%2e/etc/passwd` — the `%25` was preserved so `%252e` became `%2e` (not `.`).\n\n**Stage 2 — `serveStatic`** (`src/utils/static.ts:86-88`):\n\n```typescript\nconst originalId = resolveDotSegments(\n  decodeURI(withLeadingSlash(withoutTrailingSlash(event.url.pathname))),\n);\n```\n\nThis applies a **second** `decodeURI()`, which decodes `%2e` → `.`, producing `/../../../etc/passwd`. However, the decoding happens *inside* the `resolveDotSegments()` call argument — `decodeURI` runs first, then `resolveDotSegments` processes the result.\n\nWait — re-examining the flow more carefully:\n\n1. Input pathname after event.ts: `/%2e%2e/%2e%2e/etc/passwd`\n2. `decodeURI()` in static.ts converts `%2e` → `.`, producing: `/../../../etc/passwd`\n3. `resolveDotSegments(\"/../../../etc/passwd\")` **does** resolve `..` segments, clamping to `/etc/passwd`\n\nThe actual bypass is subtler. `decodeURI()` does **not** decode `%2e` — it only decodes characters that `encodeURI` would encode. Since `.` is never encoded by `encodeURI`, `%2e` is **not** decoded by `decodeURI()`. So the chain is:\n\n1. Request: `/%252e%252e/%252e%252e/etc/passwd`\n2. After event.ts decode: `/%2e%2e/%2e%2e/etc/passwd`\n3. `decodeURI()` in static.ts: `/%2e%2e/%2e%2e/etc/passwd` (unchanged — `decodeURI` doesn't decode `%2e`)\n4. `resolveDotSegments()` fast-returns at line 56 because `%2e` contains no literal `.` character:\n   ```typescript\n   if (!path.includes(\".\")) {\n     return path;\n   }\n   ```\n5. Asset ID `/%2e%2e/%2e%2e/etc/passwd` is passed to `getMeta()` and `getContents()` callbacks\n6. URL-based backends resolve `%2e%2e` as `..` per RFC 3986 / URL Standard\n\nThe root cause is `resolveDotSegments()` only checks for literal `.` characters and does not account for percent-encoded dot sequences (`%2e`). The `decodeURI()` in static.ts is redundant (event.ts already decodes) but is not the direct cause — the real gap is that `%2e%2e` survives as a traversal payload through both decoding stages and `resolveDotSegments`.\n\n## PoC\n\n**1. Create a minimal h3 server with a URL-based static backend:**\n\n```javascript\n// server.mjs\nimport { H3, serveStatic } from \"h3\";\nimport { serve } from \"srvx\";\n\nconst app = new H3();\n\napp.get(\"/**\", (event) => {\n  return serveStatic(event, {\n    getMeta(id) {\n      console.log(\"[getMeta] asset ID:\", id);\n      // Simulate URL-based backend (CDN/S3)\n      const url = new URL(id, \"https://cdn.example.com/static/\");\n      console.log(\"[getMeta] resolved URL:\", url.href);\n      return { type: \"text/plain\" };\n    },\n    getContents(id) {\n      console.log(\"[getContents] asset ID:\", id);\n      const url = new URL(id, \"https://cdn.example.com/static/\");\n      console.log(\"[getContents] resolved URL:\", url.href);\n      return `Fetched from: ${url.href}`;\n    },\n  });\n});\n\nserve({ fetch: app.fetch, port: 3000 });\n```\n\n**2. Send the double-encoded traversal request:**\n\n```bash\ncurl -v 'http://localhost:3000/%252e%252e/%252e%252e/etc/passwd'\n```\n\n**3. Observe server logs:**\n\n```\n[getMeta] asset ID: /%2e%2e/%2e%2e/etc/passwd\n[getMeta] resolved URL: https://cdn.example.com/etc/passwd\n[getContents] asset ID: /%2e%2e/%2e%2e/etc/passwd\n[getContents] resolved URL: https://cdn.example.com/etc/passwd\n```\n\nThe `%2e%2e` sequences in the asset ID are resolved as `..` by the `URL` constructor, causing the backend URL to traverse from `/static/` to `/etc/passwd`.\n\n## Impact\n\n- **Arbitrary file read from backend storage:** An unauthenticated attacker can read files outside the intended static asset directory on any URL-based backend (CDN origins, S3 buckets, object storage, reverse-proxied file servers).\n- **Sensitive data exposure:** Depending on the backend, this could expose configuration files, credentials, source code, or other tenants' data in shared storage.\n- **Affected deployments:** Applications using `serveStatic` with callbacks that resolve asset IDs via URL construction (`new URL(id, baseUrl)` or equivalent). This is a common pattern for CDN proxying and cloud object storage backends. Filesystem-based backends using `path.join()` are not affected since `%2e%2e` is not resolved as a traversal sequence by filesystem APIs.\n\n## Recommended Fix\n\nThe `resolveDotSegments()` function must account for percent-encoded dot sequences. Additionally, the redundant `decodeURI()` in `serveStatic` should be removed since `H3Event` already handles decoding.\n\n**Fix 1 — Remove redundant `decodeURI` in `src/utils/static.ts:86-88`:**\n\n```diff\n  const originalId = resolveDotSegments(\n-   decodeURI(withLeadingSlash(withoutTrailingSlash(event.url.pathname))),\n+   withLeadingSlash(withoutTrailingSlash(event.url.pathname)),\n  );\n```\n\n**Fix 2 — Harden `resolveDotSegments` in `src/utils/internal/path.ts:55-73` to handle percent-encoded dots:**\n\n```diff\n export function resolveDotSegments(path: string): string {\n-  if (!path.includes(\".\")) {\n+  if (!path.includes(\".\") && !path.toLowerCase().includes(\"%2e\")) {\n     return path;\n   }\n   // Normalize backslashes to forward slashes to prevent traversal via `\\`\n-  const segments = path.replaceAll(\"\\\\\", \"/\").split(\"/\");\n+  const segments = path.replaceAll(\"\\\\\", \"/\")\n+    .replaceAll(/%2e/gi, \".\")\n+    .split(\"/\");\n   const resolved: string[] = [];\n```\n\nBoth fixes should be applied. Fix 1 removes the unnecessary double-decode. Fix 2 provides defense-in-depth by ensuring `resolveDotSegments` cannot be bypassed with percent-encoded dots regardless of the caller.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "h3"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.15.9"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 1.15.8"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/h3js/h3/security/advisories/GHSA-72gr-qfp7-vwhw"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/h3js/h3"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-03-20T20:50:09Z",
    "nvd_published_at" : null
  }
}