Skip to content

Commit fc5da5d

Browse files
committed
Refactor type 2 message decoding, drop any extra lines from subject.
This allows other clients to insert headers in extra lines of text between the Subject and Body fields of the message, as discussed on the 24x7 mailing list. The PyBitmessage client was never able to meaningfully display multi-line subjects, so this does not break anything. The extra lines are thrown away and never stored anywhere, so this also protects against watermarking attacks.
1 parent eed8c66 commit fc5da5d

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

src/class_receiveDataThread.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -528,13 +528,7 @@ def processbroadcast(self, readPosition, data):
528528
print 'fromAddress:', fromAddress
529529

530530
if messageEncodingType == 2:
531-
bodyPositionIndex = string.find(message, '\nBody:')
532-
if bodyPositionIndex > 1:
533-
subject = message[8:bodyPositionIndex]
534-
body = message[bodyPositionIndex + 6:]
535-
else:
536-
subject = ''
537-
body = message
531+
subject, body = self.decodeType2Message(message)
538532
elif messageEncodingType == 1:
539533
body = message
540534
subject = ''
@@ -684,13 +678,7 @@ def processbroadcast(self, readPosition, data):
684678
print 'fromAddress:', fromAddress
685679

686680
if messageEncodingType == 2:
687-
bodyPositionIndex = string.find(message, '\nBody:')
688-
if bodyPositionIndex > 1:
689-
subject = message[8:bodyPositionIndex]
690-
body = message[bodyPositionIndex + 6:]
691-
else:
692-
subject = ''
693-
body = message
681+
subject, body = self.decodeType2Message(message)
694682
elif messageEncodingType == 1:
695683
body = message
696684
subject = ''
@@ -1005,15 +993,7 @@ def processmsg(self, readPosition, encryptedData):
1005993
toLabel = toAddress
1006994

1007995
if messageEncodingType == 2:
1008-
bodyPositionIndex = string.find(message, '\nBody:')
1009-
if bodyPositionIndex > 1:
1010-
subject = message[8:bodyPositionIndex]
1011-
subject = subject[
1012-
:500] # Only save and show the first 500 characters of the subject. Any more is probably an attak.
1013-
body = message[bodyPositionIndex + 6:]
1014-
else:
1015-
subject = ''
1016-
body = message
996+
subject, body = self.decodeType2Message(message)
1017997
elif messageEncodingType == 1:
1018998
body = message
1019999
subject = ''
@@ -1086,6 +1066,21 @@ def processmsg(self, readPosition, encryptedData):
10861066
print 'Time to decrypt this message successfully:', timeRequiredToAttemptToDecryptMessage
10871067
print 'Average time for all message decryption successes since startup:', sum / len(shared.successfullyDecryptMessageTimings)
10881068

1069+
def decodeType2Message(self, message):
1070+
bodyPositionIndex = string.find(message, '\nBody:')
1071+
if bodyPositionIndex > 1:
1072+
subject = message[8:bodyPositionIndex]
1073+
# Only save and show the first 500 characters of the subject.
1074+
# Any more is probably an attack.
1075+
subject = subject[:500]
1076+
body = message[bodyPositionIndex + 6:]
1077+
else:
1078+
subject = ''
1079+
body = message
1080+
# Throw away any extra lines (headers) after the subject.
1081+
if subject:
1082+
subject = subject.splitlines()[0]
1083+
return subject, body
10891084

10901085
def isAckDataValid(self, ackData):
10911086
if len(ackData) < 24:

0 commit comments

Comments
 (0)