fix: check max message size in validator according to configured value (#2424)

This commit is contained in:
gabrielmer 2024-02-14 17:29:10 +02:00 committed by GitHub
parent d00065e9d3
commit 731dfcbdf6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 14 deletions

View File

@ -523,7 +523,7 @@ suite "Waku v2 Rest API - Relay":
check:
response.status == 400
$response.contentType == $MIMETYPE_TEXT
response.data == fmt"Failed to publish: Message size exceeded maximum of {DefaultMaxWakuMessageSizeStr}"
response.data == fmt"Failed to publish: Message size exceeded maximum of {MaxWakuMessageSize} bytes"
await restServer.stop()
await restServer.closeWait()
@ -567,7 +567,7 @@ suite "Waku v2 Rest API - Relay":
check:
response.status == 400
$response.contentType == $MIMETYPE_TEXT
response.data == fmt"Failed to publish: Message size exceeded maximum of {DefaultMaxWakuMessageSizeStr}"
response.data == fmt"Failed to publish: Message size exceeded maximum of {MaxWakuMessageSize} bytes"
await restServer.stop()
await restServer.closeWait()

View File

@ -216,21 +216,15 @@ proc generateOrderedValidator*(w: WakuRelay): auto {.gcsafe.} =
return ValidationResult.Accept
return wrappedValidator
proc isValidSize(message: WakuMessage): Future[Result[void, string]] {.async.} =
let messageSizeBytes = uint64(message.encode().buffer.len)
if(messageSizeBytes > MaxWakuMessageSize):
let message = fmt"Message size exceeded maximum of {DefaultMaxWakuMessageSizeStr}"
debug "Invalid Waku Message", error=message
return err(message)
return ok()
proc validateMessage*(w: WakuRelay, pubsubTopic: string, msg: WakuMessage):
Future[Result[void, string]] {.async.} =
(await msg.isValidSize()).isOkOr:
return err(error)
let messageSizeBytes = msg.encode().buffer.len
if messageSizeBytes > w.maxMessageSize:
let message = fmt"Message size exceeded maximum of {w.maxMessageSize} bytes"
debug "Invalid Waku Message", error=message
return err(message)
for (validator, message) in w.wakuValidators:
let validatorRes = await validator(pubsubTopic, msg)