mirror of https://github.com/status-im/go-waku.git
fix: validate lightpush requests (#1082)
This commit is contained in:
parent
714a310462
commit
46b4efec56
|
@ -33,6 +33,7 @@ func (msg lightpushRequest) Check() error {
|
|||
if msg.Message == nil {
|
||||
return errors.New("waku message is required")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -66,6 +67,19 @@ func (serv *LightpushService) postMessagev1(w http.ResponseWriter, req *http.Req
|
|||
message, err := request.Message.ToProto()
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
_, err = w.Write([]byte(err.Error()))
|
||||
if err != nil {
|
||||
serv.log.Error("writing response", zap.Error(err))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if err = message.Validate(); err != nil {
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
_, err = w.Write([]byte(err.Error()))
|
||||
if err != nil {
|
||||
serv.log.Error("writing response", zap.Error(err))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ func (wakuLP *WakuLightPush) onRequest(ctx context.Context) func(network.Stream)
|
|||
|
||||
responsePushRPC.RequestId = requestPushRPC.RequestId
|
||||
if err := requestPushRPC.ValidateRequest(); err != nil {
|
||||
responseMsg := err.Error()
|
||||
responseMsg := "invalid request: " + err.Error()
|
||||
responsePushRPC.Response.Info = &responseMsg
|
||||
wakuLP.metrics.RecordError(requestBodyFailure)
|
||||
wakuLP.reply(stream, responsePushRPC, logger)
|
||||
|
@ -204,6 +204,9 @@ func (wakuLP *WakuLightPush) request(ctx context.Context, req *pb.PushRequest, p
|
|||
return nil, err
|
||||
}
|
||||
pushRequestRPC := &pb.PushRpc{RequestId: hex.EncodeToString(params.requestID), Request: req}
|
||||
if err = pushRequestRPC.ValidateRequest(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
writer := pbio.NewDelimitedWriter(stream)
|
||||
reader := pbio.NewDelimitedReader(stream, math.MaxInt32)
|
||||
|
@ -233,7 +236,7 @@ func (wakuLP *WakuLightPush) request(ctx context.Context, req *pb.PushRequest, p
|
|||
|
||||
if err = pushResponseRPC.ValidateResponse(pushRequestRPC.RequestId); err != nil {
|
||||
wakuLP.metrics.RecordError(responseBodyFailure)
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("invalid response: %w", err)
|
||||
}
|
||||
|
||||
return pushResponseRPC.Response, nil
|
||||
|
|
Loading…
Reference in New Issue