on master help sign in
Add hex validation for messageIds in ForwardMessage, AckMessages, and FederationAck
commit31ee934ab1522b98d87cda18685ff6ea9ac3d6dc authoriko <mail@iko.soy> dateThu 26 Mar 2026, 18:40 (7 months ago) parent027ee68
1 file changed+3−1
server.knot+3−1
server.knot+3−1
@@ -378,6 +378,7 @@ serve = \req -> case req of
378378 t <- now
379379 let dedupedIds = fold (\acc mid ->
380380 if mid == "" then acc
381+ else if not (isValidHex mid) then acc
381382 else if tooLong mid maxPubkeyLen then acc
382383 else if count acc >= maxMessageIds then acc
383384 else if count (do a <- acc; where a == mid; yield a) > 0 then acc
@@ -620,7 +621,7 @@ serve = \req -> case req of
620621 t <- now
621622 let authorized = verifyFederationAuth authorization
622623 let validOrigin = not (originServer == "") && not (originServer == serverHost)
623− let validFields = not (toKey == "") && not (fromKey == "") && not (encryptedBlob == "") && not (messageId == "") && isValidHex toKey && isValidHex fromKey && not (tooLong toKey maxPubkeyLen) && not (tooLong fromKey maxPubkeyLen) && not (tooLong encryptedBlob maxBlobLen) && not (tooLong messageId maxPubkeyLen)
624+ let validFields = not (toKey == "") && not (fromKey == "") && not (encryptedBlob == "") && not (messageId == "") && isValidHex toKey && isValidHex fromKey && isValidHex messageId && not (tooLong toKey maxPubkeyLen) && not (tooLong fromKey maxPubkeyLen) && not (tooLong encryptedBlob maxBlobLen) && not (tooLong messageId maxPubkeyLen)
624625 let clampedTs = if timestamp > t then t else if timestamp < t - messageMaxAge then t else timestamp
625626 pruneResult <- atomic do
626627 pr <- pruneExpired t
@@ -648,6 +649,7 @@ serve = \req -> case req of
648649 let authorized = verifyFederationAuth authorization
649650 let dedupedIds = fold (\acc mid ->
650651 if mid == "" then acc
652+ else if not (isValidHex mid) then acc
651653 else if tooLong mid maxPubkeyLen then acc
652654 else if count acc >= maxMessageIds then acc
653655 else if count (do a <- acc; where a == mid; yield a) > 0 then acc