Skip to content

Reject endpoint names and content ids that are not a single path segment - #13

Open
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/content-path-segment-validation-9a8b
Open

cursor[bot] wants to merge 1 commit into
mainfrom
cursor/content-path-segment-validation-9a8b

Conversation

@cursor

@cursor cursor Bot commented Nov 20, 2026

Copy link
Copy Markdown

Problem

Microcms\Client built request paths by joining the endpoint name and the content id with /, and did no validation. Guzzle resolves the result against https://{service}.microcms.io/api/v1/ and removes dot segments. So a content id such as ../inquiries passed to get('blog', ...) sent GET /api/v1/inquiries with the application's X-MICROCMS-API-KEY header. That reached a different content API. create, update and delete used the same join, so writes and deletes could also be redirected. An endpoint value that is an absolute URL would also have replaced the base URI.

Fix

list, get, create, update and delete now build their path through one private buildPath() helper. Every endpoint name and content id, including the id taken from a create/update body, must match \A[A-Za-z0-9_-]+\z. Anything else throws InvalidArgumentException before a request is made. That includes /, \, ., %, ?, #, :, whitespace, a trailing newline, empty ids, and non-scalar ids. Integer ids are still accepted, as before. This is the character set microCMS uses for endpoint names and content ids, so ordinary calls behave the same.

These five methods are the only places in the repository that build request paths (src/Client.php). All of them are covered.

Tests

The tests that prove the fix are in #11. This PR does not include them.

  • PR Add failing tests for content path traversal #11's head branch with this fix applied: vendor/bin/phpunit tests reported OK (52 tests, 83 assertions). That covers all 45 tests in ContentPathTraversalTest plus the existing ClientTest. Without the fix, 44 of the 45 failed.
  • This branch: vendor/bin/phpunit tests reported OK (7 tests, 36 assertions) (the existing ClientTest).
  • vendor/bin/phpstan analyse: no errors. php-cs-fixer fix --dry-run src: no changes.
  • An extra local script tried other inputs against every call form (list, and both the endpoint and the id positions of get, create, update and delete). The inputs were ..%2finquiries, %2e%2e, ..\inquiries, a trailing newline, a NUL byte, a leading space, https://…, //host/x, host:80, ?x=1, #frag, ., .., a full-width letter, and array, null, float and bool ids. Every one was rejected and no request was sent.
Open in Web Open in Cursor 

@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