Skip to content

Nested route validators, route-level consumes, encrypted idempotency storage - #3

Merged
JustSteveKing merged 4 commits into
mainfrom
fix/nested-routes-and-stored-secrets
Oct 20, 2026
Merged

JustSteveKing merged 4 commits into
mainfrom
fix/nested-routes-and-stored-secrets

Conversation

@JustSteveKing

Copy link
Copy Markdown
Owner

Three changes found while building an example application on Kit. Two change behaviour, so this is a minor release: v0.4.0.

Nested routes take validators from the child

RouteValidators returned the first route parameter implementing HasValidators. On folders/{folder}/documents/{document} that is the folder, so a GET sent the folder's ETag and a PATCH checked If-Match against the folder: a stale write to the document went through. A URI names parents first, so it now returns the last bound validator. Tests cover the GET, a matching If-Match, and one that only matches the parent.

A route's consumes: overrides its group's

With consumes:application/json on an API group, a merge patch route had to lift the group's declaration with withoutMiddleware() first, or the group answered 415 before the route's own middleware ran. Only the last declaration a route lists now applies: group, then route, then controller. A declaration removed with withoutMiddleware() does not count.

Stored idempotent responses are encrypted

A replay must return the original response, and some carry a secret shown once, such as a new API key. They sat in the cache as plain arrays for the whole TTL. Each is now encrypted with AES-256-GCM under a key derived by HKDF from the application key and the client's Idempotency-Key, and stored under a hash of that key. Neither the cache nor the cache plus APP_KEY can read an entry without the key that wrote it.

  • Keys in APP_PREVIOUS_KEYS still decrypt, so rotating APP_KEY keeps replays working until the TTL passes.
  • Unencrypted entries written by 0.3.x are read until they expire, so a retry that straddles the upgrade does not run twice.
  • IdempotencyStore's methods now take the scope and the IdempotencyKey instead of a precomputed storage key, and its constructor takes the application's keys. It is an internal class, but anyone constructing it directly needs to update.

Suite, PHPStan and Pint pass locally.

…tes use the child

RouteValidators returned the first route parameter implementing HasValidators.
On folders/{folder}/documents/{document} that is the folder, so a GET sent
the folder's ETag and a PATCH checked If-Match against the folder, letting
a stale write to the document through. A URI names parents first, so the
last bound validator is the resource the request is about.
With consumes:application/json on an API group, a PATCH route that took
application/merge-patch+json had to lift the group's declaration with
withoutMiddleware() first, or the group answered 415 before the route's
own middleware ran. Only the last declaration a route lists now applies:
group, then route, then controller.
…pply

A replay must return the original response, and some responses carry a
secret shown once, such as a new API key. They sat in the cache as plain
arrays for the whole TTL. Each is now encrypted with AES-256-GCM under a
key derived by HKDF from the application key and the client's
Idempotency-Key, and stored under a hash of that key, so neither the
cache nor the cache plus APP_KEY can read it. Previous application keys
still decrypt, and unencrypted entries from earlier versions are read
until they expire.
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a383bd13-2ebc-4b9b-9a3b-a66c561eb126
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@JustSteveKing JustSteveKing self-assigned this Oct 20, 2026
@JustSteveKing
JustSteveKing merged commit ed77856 into main Oct 20, 2026
7 checks passed
@JustSteveKing
JustSteveKing deleted the fix/nested-routes-and-stored-secrets branch October 20, 2026 19:55
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.

1 participant