Skip to main content
Menu
Advisories

Method-level guards ignored on routes synthesized by router-contract @Implement in @orpc/nest

GHSA-58R7-2F58-X3F6Published Updated GitHub

Description

Method-level @UseGuards (as well as @UsePipes, @UseFilters, and @SetMetadata) applied to a controller method decorated with @Implement for a contract router were silently ignored. Routes that appeared protected by a guard were publicly reachable.

This does not happen when @Implement is used with a single contract procedure. Class-level enhancers and global guards were also unaffected.

Details

NestJS stores enhancer metadata on the decorated function object. When @Implement receives a contract router, it synthesizes a fresh route function for each procedure in the router and registers those as the actual route handlers. Nest then looks up guard metadata on the synthesized functions, not on the original method, so the guards never run. This happens regardless of decorator order.

Vulnerable pattern (contract router, guard silently ignored):

@Controller()
export class PlanetController {
  @UseGuards(AuthGuard) // never executed before v1.14.14
  @Implement(planetContract) // a contract router with multiple procedures
  planets() {
    return {
      list: implement(planetContract.list).handler(listPlanets),
      create: implement(planetContract.create).handler(createPlanet),
    }
  }
}

Not affected (single contract procedure, guard runs as expected):

@Controller()
export class PlanetController {
  @UseGuards(AuthGuard) // works correctly in all versions
  @Implement(planetContract.create) // a single procedure
  create() {
    return implement(planetContract.create).handler(createPlanet)
  }
}

Impact

Any authorization or authentication enforced through method-level guards on a router-contract @Implement handler was not applied. Unauthenticated requests to those routes succeeded instead of being rejected.

Patches

Fixed in v1.14.14 (github.com/middleapi/orpc/pull/1775): each synthesized route function now inherits from the original method via its prototype chain, so Nest resolves guards, pipes, filters, and metadata correctly in either decorator order. Upgrade to @orpc/nest@1.14.14 or later.

Workarounds

If upgrading is not possible, apply guards at the class level (@UseGuards on the controller) or register them globally, or use @Implement with individual procedures instead of a router. All of these were unaffected.

Affected versions

References

GitHub · middleapi/orpc