CRE Gateway: Checks on json request id size to prevent abuse#21019
CRE Gateway: Checks on json request id size to prevent abuse#21019prashantkumar1982 merged 9 commits intodevelopfrom
Conversation
prashantkumar1982
commented
Feb 3, 2026
- Put a fixed size limit on json request id in gateway, to prevent abuses.
- Vault Get public key endpoint is unauthenticated, so made its fetching of cached entries efficient and cheap, to prevent potential dos.
… into vault_reqid_check
|
I see you updated files related to
|
| return errors.New("request ID cannot be empty") | ||
| } | ||
| if len(req.ID) > 200 { | ||
| // Arbitrary limit to prevent abuse |
There was a problem hiding this comment.
are requestIDs well formed? i'm surprised we can't lock in a known limit of the size of the request ID here
There was a problem hiding this comment.
Here's the spec: https://www.jsonrpc.org/specification
It just needs a unique id that could be a string.
So there's no fixed locked size.
I just think 200 is a safe enough buffer for anyone using any funky way for associating this id to their internal ids.
There was a problem hiding this comment.
@prashantkumar1982 sure, but my understanding is the gateway isn't a domain agnostic rpc proxy. We use it for particular domains, and those domains should have our request patterns well mapped. What is that for the Vault DON? @MStreet3 do you know the max expected request.ID size for HTTP Triggers?
There was a problem hiding this comment.
For Vault, we don't have any restriction.
All we enforce, is that ids should be unique strings.
… into vault_reqid_check
There was a problem hiding this comment.
Pull request overview
Adds request ID length limits to mitigate abuse and refactors Vault public key handling to rely on cached responses for cheaper unauthenticated access.
Changes:
- Enforce a max length (200 chars) on JSON-RPC request IDs in the gateway and Vault handler.
- Refactor Vault
PublicKeyGetto return a cached response directly (and adjust periodic cache refresh to use internal handler methods). - Add/adjust tests for the new request ID limit and the public key caching path.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| core/services/gateway/handlers/vault/handler.go | Adds request ID length validation; changes PublicKeyGet to serve cached responses directly; updates periodic cache refresh helper to return errors. |
| core/services/gateway/handlers/vault/handler_test.go | Updates public key test flow to seed cache via internal methods before asserting cached behavior. |
| core/services/gateway/gateway.go | Adds request ID length validation at the gateway layer. |
| core/services/gateway/gateway_test.go | Adds coverage for gateway rejection of overly long request IDs. |
Comments suppressed due to low confidence (2)
core/services/gateway/handlers/vault/handler_test.go:764
- This test seeds the public key cache by calling private methods directly, but it no longer covers the cold-cache behavior for a user request (HandleJSONRPCUserMessage with MethodPublicKeyGet). Given the handler change, it would be valuable to add an assertion that the first user request still succeeds (or returns a well-defined error) when the cache is empty.
"d6da96fe596705b32bc3a0e11cdefad77feaad79000000000000000000000000",
"327aa349c9718cd36c877d1e90458fe1929768ad000000000000000000000000",
"e9bf394856d73402b30e160d0e05c847796f0e29000000000000000000000000",
"efd5bdb6c3256f04489a6ca32654d547297f48b9000000000000000000000000",
core/services/gateway/handlers/vault/handler_test.go:795
- Grammar in this comment is a bit unclear ("make HandleJSONRPCUserMessage request"). Consider rephrasing to something like "make another request via HandleJSONRPCUserMessage" for readability.
ID: "request_id",
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| case <-tickerVaultPublicKeyRefresh.Chan(): | ||
| // periodically, fetch vault public key, so we can cache it | ||
| h.fetchVaultPublicKey(ctx) | ||
| _ = h.fetchVaultPublicKey(ctx) |
There was a problem hiding this comment.
Nit: maybe handle the error here and log it? I see we do a lot of logging of errors inside fetchVaultPublicKey so we can move that out maybe?
There was a problem hiding this comment.
I had changed signature of this to call it from tests. But later didn't use it. Reverting it back to old logging.
… into vault_reqid_check
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if len(jsonRequest.ID) > 200 { | ||
| // Arbitrary limit to prevent abuse | ||
| return newError(jsonRequest.ID, api.UserMessageParseError, "request ID is too long: "+strconv.Itoa(len(jsonRequest.ID))+". max is 200 characters") | ||
| } |
There was a problem hiding this comment.
The magic number 200 for maximum request ID length is duplicated across multiple files (gateway.go and vault/handler.go). Consider defining a constant like MaxRequestIDLength to ensure consistency and make future changes easier to maintain. This constant could be defined in a shared package like core/services/gateway/api/constants.go.
| if len(req.ID) > 200 { | ||
| // Arbitrary limit to prevent abuse | ||
| return errors.New("request ID is too long: " + strconv.Itoa(len(req.ID)) + ". max is 200 characters") | ||
| } |
There was a problem hiding this comment.
The request ID length validation logic is duplicated between gateway.go and vault/handler.go. This creates a maintenance burden and risk of inconsistency if the limit needs to be changed. Consider extracting this validation into a shared function or performing it only at the gateway layer to follow the DRY principle.
| if len(req.ID) > 200 { | |
| // Arbitrary limit to prevent abuse | |
| return errors.New("request ID is too long: " + strconv.Itoa(len(req.ID)) + ". max is 200 characters") | |
| } |
|
patrickhuie19
left a comment
There was a problem hiding this comment.
approved. please circle back to my comment on request.id size @prashantkumar1982



