Minimal useragent validation

This commit is contained in:
Dmitri Bogomolov 2021-03-17 22:47:26 +02:00
parent e03b1dfa38
commit a7d6037fc5
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13

View File

@ -5,6 +5,7 @@ Class BMProto defines bitmessage's network protocol workflow.
import base64 import base64
import hashlib import hashlib
import logging import logging
import re
import socket import socket
import struct import struct
import time import time
@ -535,6 +536,10 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
return True return True
self.append_write_buf(protocol.CreatePacket('verack')) self.append_write_buf(protocol.CreatePacket('verack'))
self.verackSent = True self.verackSent = True
ua_valid = re.match(
r'^/[a-zA-Z]+:[0-9]+\.?[\w\s\(\)\./:;-]*/$', self.userAgent)
if not ua_valid:
self.userAgent = '/INVALID:0/'
if not self.isOutbound: if not self.isOutbound:
self.append_write_buf(protocol.assembleVersionMessage( self.append_write_buf(protocol.assembleVersionMessage(
self.destination.host, self.destination.port, self.destination.host, self.destination.port,