Skip to content

fix: reject microCMS endpoints and content ids that are not a single path segment - #44

Closed
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/microcms-path-segment-validation-1d0a
Closed

cursor[bot] wants to merge 1 commit into
mainfrom
cursor/microcms-path-segment-validation-1d0a

Conversation

@cursor

@cursor cursor Bot commented Nov 20, 2026

Copy link
Copy Markdown

Problem

useMicroCMSGetListDetail built its request path as `${endpoint}/${contentId}`, and useMicroCMSGetList and useMicroCMSGetObject passed endpoint through as is. useFetch then joined that path to https://{serviceDomain}.microcms.io/api/v1 and sent the X-MICROCMS-API-KEY header. Pages commonly pass a route param as the content id. Because of that, a visitor could use a value like ..\other-api?limit=100 (a backslash or dot segment, optionally with a query) to make the server fetch a different content API with the service key. The response then ended up in the Nuxt payload.

Fix

src/runtime/composables/useMicroCMSGet.ts: the shared useMicroCMSGet helper now takes path segments instead of a ready-made URL string. Before calling useFetch, it checks that every segment is a string matching ^[A-Za-z0-9_-]+$ and URL-encodes it. If any segment fails the check, it throws and no request is sent. All three exported composables go through this helper, so they are all covered. Nothing else in the repository builds microCMS request URLs.

The allowlist matches what microCMS accepts:

  • Content ids may only use a-z, A-Z, 0-9, - and _ (see the microCMS docs, "コンテンツIDの設定").
  • API endpoints may only use lowercase alphanumerics, - and _ (see "APIの作成・管理").

So no valid id or endpoint is rejected. The README now documents the constraint.

Behaviour changes for callers:

  • An invalid endpoint or contentId now throws an Error, which Nuxt shows as a 500 during SSR. Before, the request was sent to whatever path the value resolved to.
  • An empty contentId, which used to fetch the list endpoint by accident, is also rejected.

Tests

The tests that prove the fix are in #43 (#43). They are not part of this PR.

Check Before fix With fix
node --test test/content-id-traversal.test.mjs from #43 6 pass, 14 fail. Hostile ids sent the key to /api/v1/other-api, /api/v1/other-api?limit=100, /api/other-api and /api/v1/blogs/hello-world?limit=100 20/20 pass
Extra variants run against the #43 fixture build (not committed) – No request sent for any of the 29 hostile inputs
npm run lint on this branch – pass
nuxt-module-build build on this branch – pass
nuxi build playground on this branch – pass

The extra variants were:

  • double-encoded %252e%252e%255c and %252F
  • #, &, tab, NUL and space inside the id
  • full-width ../ and ∕
  • ..;/, @host
  • //host and https://host as the endpoint
  • repeated and array query params
  • multi-segment catch-all ids
  • dot segments in the endpoint

Legitimate ids such as hello-world and endpoints such as blogs and banner still fetch /api/v1/blogs/hello-world, /api/v1/blogs and /api/v1/banner.

The repository has no other test suite for this code.

Open in Web Open in Cursor 

…path segment

useMicroCMSGetList, useMicroCMSGetListDetail and useMicroCMSGetObject
concatenated caller-supplied endpoint and contentId into the request
path, so values such as '..\other-api?limit=100' made the server send
its API key to a different content API. Validate every segment against
the characters microCMS allows and encode it before calling useFetch.
@YouheiNozaki YouheiNozaki self-assigned this Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants