Commit 2b81d89
authored
fix(nest): run method-level guards on routes synthesized by router-contract @implement (#1775)
Method-level `@UseGuards` (and `@UsePipes`, `@UseFilters`,
`@SetMetadata`) on a handler decorated with a router-contract
`@Implement` were silently ignored: Nest stores that metadata on the
decorated function object, but `@Implement` registers freshly
synthesized functions as the actual routes, so the guards never ran.
Routes that looked protected were publicly reachable. Each synthesized
route function now inherits from the original method via its prototype
chain, so Nest resolves the metadata from the registered callback in
either decorator order.
## Fixes
- Method-level guards, pipes, filters, and `@SetMetadata` now execute on
every route synthesized from a router contract, whether the decorator is
placed above or below `@Implement`. An eager metadata copy could not
achieve this: decorators evaluate bottom-up, so anything written above
`@Implement` attaches its metadata after `@Implement` has already run.
- User-supplied method-level `@UseInterceptors` is merged ahead of
oRPC's own interceptor when placed below `@Implement`. Placing it above
still loses it — an inherent limit of Nest's array-metadata scheme,
since the synthesized route must define its own interceptor entry.
- Single-procedure `@Implement`, class-level enhancers, and global
providers were unaffected and remain so.
## Testing
- New end-to-end tests boot a Nest app with a `CanActivate` guard on the
router method in both decorator orderings: denied requests get 403 with
the procedure handler never invoked, allowed requests succeed. All 4 new
tests fail against the previous code (unauthenticated requests returned
200).
- Full `@orpc/nest` suite passes (29 tests).1 parent e5e7ee7 commit 2b81d89
2 files changed
Lines changed: 84 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | | - | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
244 | 245 | | |
245 | 246 | | |
246 | 247 | | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
247 | 328 | | |
248 | 329 | | |
249 | 330 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
88 | 90 | | |
89 | 91 | | |
90 | 92 | | |
| |||
0 commit comments