Skip to content

fix(authz): decode the request body once in the resource middleware - #13014

Merged
vikrantgupta25 merged 7 commits into
mainfrom
keystone-pod/issues/37
Sep 29, 2026
Merged

vikrantgupta25 merged 7 commits into
mainfrom
keystone-pod/issues/37

Conversation

@vikrantgupta25

@vikrantgupta25 vikrantgupta25 commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Description

  • The resource middleware now decodes the body once into the route's declared OpenAPIDef.Request type, rejects a malformed body before any check, and carries the decoded value on ExtractorContext.Body. BodyField / BodyFields read ids off that value, and handlers read the same value via coretypes.BodyFromContext.
  • handler.Handler exposes Request(), and handler.New panics when a route with resource defs declares a non-pointer request, since the middleware instantiates it.
  • Only POST /api/v1/service_account_roles is wired to the new extractors in this PR to keep the review small. The remaining body routes still use the gjson extractors and decode again in their handlers.

Issues closed by this PR

gjson and encoding/json disagree on duplicate and case-variant keys, so
extractors and handlers could act on different values. The middleware now
decodes into the route's declared request type and both read that value.
@github-actions github-actions Bot added the bug Something isn't working label Sep 29, 2026
@vikrantgupta25 vikrantgupta25 added the safe-to-integrate Run integration tests label Sep 29, 2026
Routes whose extractors read path params or the response keep their body
untouched, so handlers that accept more than the declared shape still work.
@vikrantgupta25 vikrantgupta25 added safe-to-integrate Run integration tests review/greptile Request a review from Greptile and removed safe-to-integrate Run integration tests labels Sep 29, 2026
…options

Rendering the decode error in the resource middleware skipped the audit
middleware, so malformed requests were never logged. The error now rides on
the resolved resources and authz renders it inside audit. Routes can declare
bind options once, and the single decode honours them.
@vikrantgupta25 vikrantgupta25 added review/greptile Request a review from Greptile and removed review/greptile Request a review from Greptile labels Sep 29, 2026
@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Critical risk] Refactors request body decoding in the authorization middleware.

The PR appears safe to merge based on the findings eligible for this review.

Summary

The PR decodes resource-middleware request bodies into their declared types, shares the decoded body with extractors and handlers, and applies the new extractors to service-account role creation. The change since the previous review converts the request-type test cases into named subtests.

Reviews (3) · Last reviewed commit: "test(authz): table-drive the request poi..."

Comment thread pkg/http/middleware/resource.go Resolved
@vikrantgupta25
vikrantgupta25 marked this pull request as ready for review September 29, 2026 19:04
@vikrantgupta25 vikrantgupta25 added safe-to-integrate Run integration tests and removed safe-to-integrate Run integration tests labels Sep 29, 2026
Comment thread pkg/http/handler/handler_test.go Resolved
@vikrantgupta25
vikrantgupta25 added this pull request to the merge queue Sep 29, 2026
Merged via the queue into main with commit 8d80f98 Sep 29, 2026
24 checks passed
@vikrantgupta25
vikrantgupta25 deleted the keystone-pod/issues/37 branch September 29, 2026 21:41
pull Bot pushed a commit to TheTechOddBug/signoz that referenced this pull request Sep 30, 2026
…est (SigNoz#13015)

#### Description

- Follows SigNoz#13014. Moves the remaining body-derived resource ids (gateway
limits, zeus hosts, cloud integration check-ins, auth domains, query
range) off gjson and onto the decoded request, with the handlers reading
the same value. Part of SigNoz/keystone-pod#37.
- Removes `BodyJSONPath`, `BodyJSONArray`, and
`ExtractorContext.RequestBody`.

#### Issues closed by this PR 

- Closes: SigNoz/keystone-pod#37
vikrantgupta25 added a commit that referenced this pull request Sep 30, 2026
This reverts commit 8d80f98 (#13014).
Authz should not own request body decoding.
pull Bot pushed a commit to itsrbpandit/signoz that referenced this pull request Sep 30, 2026
…ware (SigNoz#13024)

#### Description

- Reverts SigNoz#13014 and SigNoz#13015. The resource middleware goes back to
reading body-derived resource ids with `BodyJSONPath` / `BodyJSONArray`
over the raw body, and handlers decode their own request bodies again.
- Authz should not own request decoding; that ownership stays with the
handlers.

#### Additional Information

- Contributes to: SigNoz/keystone-pod#37
ahrefabhi pushed a commit that referenced this pull request Oct 13, 2026
…13014)

#### Description

- The resource middleware now decodes the body once into the route's
declared `OpenAPIDef.Request` type, rejects a malformed body before any
check, and carries the decoded value on `ExtractorContext.Body`.
`BodyField` / `BodyFields` read ids off that value, and handlers read
the same value via `coretypes.BodyFromContext`.
- `handler.Handler` exposes `Request()`, and `handler.New` panics when a
route with resource defs declares a non-pointer request, since the
middleware instantiates it.
- Only `POST /api/v1/service_account_roles` is wired to the new
extractors in this PR to keep the review small. The remaining body
routes still use the gjson extractors and decode again in their
handlers.

#### Issues closed by this PR
- Contributes to: SigNoz/keystone-pod#37
ahrefabhi pushed a commit that referenced this pull request Oct 13, 2026
…est (#13015)

#### Description

- Follows #13014. Moves the remaining body-derived resource ids (gateway
limits, zeus hosts, cloud integration check-ins, auth domains, query
range) off gjson and onto the decoded request, with the handlers reading
the same value. Part of SigNoz/keystone-pod#37.
- Removes `BodyJSONPath`, `BodyJSONArray`, and
`ExtractorContext.RequestBody`.

#### Issues closed by this PR 

- Closes: SigNoz/keystone-pod#37
ahrefabhi pushed a commit that referenced this pull request Oct 13, 2026
…ware (#13024)

#### Description

- Reverts #13014 and #13015. The resource middleware goes back to
reading body-derived resource ids with `BodyJSONPath` / `BodyJSONArray`
over the raw body, and handlers decode their own request bodies again.
- Authz should not own request decoding; that ownership stays with the
handlers.

#### Additional Information

- Contributes to: SigNoz/keystone-pod#37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working review/greptile Request a review from Greptile safe-to-integrate Run integration tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants