@@ -378,6 +378,7 @@ serve = \req -> case req of
379 let dedupedIds = fold (\acc mid ->
379 let dedupedIds = fold (\acc mid ->
380 if mid == "" then acc
380 if mid == "" then acc
381+ else if tooLong mid maxPubkeyLen then acc
381 else if count acc >= maxMessageIds then acc
382 else if count acc >= maxMessageIds then acc
382 else if count (do a <- acc; where a == mid; yield a) > 0 then acc
383 else if count (do a <- acc; where a == mid; yield a) > 0 then acc
383 else union acc [mid]) [] messageIds
384 else union acc [mid]) [] messageIds
@@ -437,7 +438,7 @@ serve = \req -> case req of
437 let foundServer = case session of
438 let foundServer = case session of
438 Nothing {} -> ""
439 Nothing {} -> ""
439 Just {value: _} ->
440 Just {value: _} ->
440− if pubkey == "" || tooLong pubkey maxPubkeyLen || count valid == 0
441+ if pubkey == "" || tooLong pubkey maxPubkeyLen || not (isValidHex pubkey) || count valid == 0
442 else case single (do
443 else case single (do
443 p <- valid
444 p <- valid
@@ -575,6 +576,7 @@ serve = \req -> case req of
575 where validRequest
576 where validRequest
576 where not (e.server == "")
577 where not (e.server == "")
577 where not (e.pubkey == "")
578 where not (e.pubkey == "")
579+ where isValidHex e.pubkey
578 where not (tooLong e.pubkey maxPubkeyLen)
580 where not (tooLong e.pubkey maxPubkeyLen)
579 where not (tooLong e.server maxPubkeyLen)
581 where not (tooLong e.server maxPubkeyLen)
580 where not (e.server == serverHost)
582 where not (e.server == serverHost)
@@ -618,7 +620,7 @@ serve = \req -> case req of
619 let authorized = verifyFederationAuth authorization
621 let authorized = verifyFederationAuth authorization
620 let validOrigin = not (originServer == "") && not (originServer == serverHost)
622 let validOrigin = not (originServer == "") && not (originServer == serverHost)
621− let validFields = not (toKey == "") && not (fromKey == "") && not (encryptedBlob == "") && not (messageId == "") && not (tooLong toKey maxPubkeyLen) && not (tooLong fromKey maxPubkeyLen) && not (tooLong encryptedBlob maxBlobLen) && not (tooLong messageId maxPubkeyLen)
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)
622 let clampedTs = if timestamp > t then t else if timestamp < t - messageMaxAge then t else timestamp
624 let clampedTs = if timestamp > t then t else if timestamp < t - messageMaxAge then t else timestamp
623 pruneResult <- atomic do
625 pruneResult <- atomic do
624 pr <- pruneExpired t
626 pr <- pruneExpired t
@@ -646,10 +648,11 @@ serve = \req -> case req of
646 let authorized = verifyFederationAuth authorization
648 let authorized = verifyFederationAuth authorization
647 let dedupedIds = fold (\acc mid ->
649 let dedupedIds = fold (\acc mid ->
648 if mid == "" then acc
650 if mid == "" then acc
651+ else if tooLong mid maxPubkeyLen then acc
649 else if count acc >= maxMessageIds then acc
652 else if count acc >= maxMessageIds then acc
650 else if count (do a <- acc; where a == mid; yield a) > 0 then acc
653 else if count (do a <- acc; where a == mid; yield a) > 0 then acc
651 else union acc [mid]) [] messageIds
654 else union acc [mid]) [] messageIds
652− let validAck = authorized && originServer == serverHost && not (fromServer == "") && not (fromServer == serverHost) && not (tooLong fromServer maxPubkeyLen) && count dedupedIds <= maxMessageIds
655+ let validAck = authorized && originServer == serverHost && not (fromServer == "") && not (fromServer == serverHost) && not (tooLong fromServer maxPubkeyLen)
653 pruneResult <- atomic do
656 pruneResult <- atomic do
654 pr <- pruneExpired t
657 pr <- pruneExpired t
655 messages <- *messages
658 messages <- *messages