From 17244096476998adfe8169432758c425385a0eec Mon Sep 17 00:00:00 2001 From: shaurya947 Date: Wed, 3 May 2023 16:19:43 -0400 Subject: [PATCH] rpcserver: enforce memo length is less than 500 characters In this commit we ensure that the string length of the memo field specified as part of the OpenChannelRequest is no longer than 500. --- rpcserver.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rpcserver.go b/rpcserver.go index 952b769ec..0cc50bf00 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -2169,6 +2169,15 @@ func (r *rpcServer) parseOpenChannelReq(in *lnrpc.OpenChannelRequest, in.CommitmentType) } + // We limit the channel memo to be 500 characters long. This enforces + // a reasonable upper bound on storage consumption. This also mimics + // the length limit for the label of a TX. + const maxMemoLength = 500 + if len(in.Memo) > maxMemoLength { + return nil, fmt.Errorf("provided memo (%s) is of length %d, "+ + "exceeds %d", in.Memo, len(in.Memo), maxMemoLength) + } + // Instruct the server to trigger the necessary events to attempt to // open a new channel. A stream is returned in place, this stream will // be used to consume updates of the state of the pending channel.