Skip to content

Commit fd55f85

Browse files
authored
Merge pull request #2355 from CortexFoundation/dev
rpc: add method name length limit
2 parents 079f36d + 7fcf407 commit fd55f85

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

rpc/handler.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,10 @@ func (h *handler) handleCall(cp *callProc, msg *jsonrpcMessage) *jsonrpcMessage
449449
if msg.isUnsubscribe() {
450450
callb = h.unsubscribeCb
451451
} else {
452+
// Check method name length
453+
if len(msg.Method) > maxMethodNameLength {
454+
return msg.errorResponse(&invalidRequestError{fmt.Sprintf("method name too long: %d > %d", len(msg.Method), maxMethodNameLength)})
455+
}
452456
callb = h.reg.callback(msg.Method)
453457
}
454458
if callb == nil {
@@ -482,6 +486,11 @@ func (h *handler) handleSubscribe(cp *callProc, msg *jsonrpcMessage) *jsonrpcMes
482486
return msg.errorResponse(ErrNotificationsUnsupported)
483487
}
484488

489+
// Check method name length
490+
if len(msg.Method) > maxMethodNameLength {
491+
return msg.errorResponse(&invalidRequestError{fmt.Sprintf("subscription name too long: %d > %d", len(msg.Method), maxMethodNameLength)})
492+
}
493+
485494
// Subscription method name is first argument.
486495
name, err := parseSubscriptionName(msg.Params)
487496
if err != nil {

rpc/json.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const (
3535
subscribeMethodSuffix = "_subscribe"
3636
unsubscribeMethodSuffix = "_unsubscribe"
3737
notificationMethodSuffix = "_subscription"
38+
maxMethodNameLength = 2048
3839

3940
defaultWriteTimeout = 10 * time.Second // used if context has no deadline
4041
)

0 commit comments

Comments
 (0)