Skip to content

hydra-gates: report routes.php entries that an earlier route shadows (first-match order) #922

Open

Description

@WilcoLouwerse

Problem

Nextcloud matches a request against appinfo/routes.php with Symfony's UrlMatcher. It walks the routes in declaration order and takes the first one whose path and verb match. A route declared after a broader route for the same verb (a {param} wildcard, a generic {objectType}/{objectId} pair) is registered, resolves, and has a working controller method, but is never reached.

No current check sees this:

  • gate 14 (route registration) checks that a route resolves;
  • the ADR-029 reachability checks look at the controller method;
  • unit tests call the controller method directly.

All three pass while the router sends the request elsewhere.

Cases so far

  • opencatalogi#1912. 19 of the 29 dedicated OPTIONS preflights were answered by the publications wildcard /api/{catalogSlug}, so six of them returned wider Access-Control-Allow-Methods than their own controller. Fixed on beta in opencatalogi#2397, which adds an app-level tests/Unit/AppInfo/RouteShadowingTest.php. That test covers OPTIONS only.
  • pipelinq#2303. DELETE /api/notes/single/{noteId} was routed to the admin-only bulk delete /api/notes/{objectType}/{objectId}, so a non-admin could not delete their own note.
  • Known hit for a first run: opencatalogi GET /. ui#dashboard is shadowed by GenericDashboard#page; tracked in opencatalogi#2411.

Proposal

Add a gate that replays the first-match rule over appinfo/routes.php, per verb:

  • Build each route's regex from url plus requirements; a parameter without a requirement defaults to [^/]+. Honour defaults for an optional trailing parameter.
  • Fill each parameter with every sample value that fits its requirement, in every combination. One sample per parameter is not enough: an earlier route whose requirement only a numeric id meets (\d+) stays invisible with a non-numeric sample, while the router sends real ids to it.
  • Report a route when an earlier route of the same verb matches one of its sample paths and names a different controller#action. Two entries for the same action answer identically and are not a finding (opencatalogi's /api/listings/{id} catching /api/listings/sync, both listings#preflightedCors).
  • Run diff-scoped per ADR-020: only when appinfo/routes.php is in the diff.

The opencatalogi test linked above is a working reference for the sampling and the first-match replay (141 sample paths, 17 ms).

Plan and measurements of the first case: opencatalogi-1912 plan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions