Skip to content

Commit

Permalink
Change out the triple-dot sequence in third-party invites to an ellip…
Browse files Browse the repository at this point in the history
…sis character (#324)

Besides a slightly nicer presentation, this can be useful when email addresses that contain period characters are obfuscated. Consider the address: `firstname.lastname@example.com`.

If this address is obfuscated to `firstname....@exa...`, we end up with a slightly odd-looking sequence of four periods on the left-hand side.

With an ellipsis character, we'd instead get `firstname.…@exa…`, which is still a little odd, but is clearer with regards to what exactly was obfuscated.

Applying this to the `dinsic` branch as it grew out of [a dinsic PR conversation](#323 (comment)), but will be ported to mainline with the rest of the obfuscated code it touches.
  • Loading branch information
anoadragon453 authored Dec 1, 2020
1 parent e70fa31 commit c33d976
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions changelog.d/324.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Switch out triple-period sequences in third-party invites for an ellipsis character.
10 changes: 5 additions & 5 deletions sydent/http/servlets/store_invite_servlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def _redact(self, s, characters_to_reveal):
:type s: unicode
:param characters_to_reveal: How many characters of the string to leave before
the '...'
the ellipsis
:type characters_to_reveal: int
:return: The redacted string.
Expand All @@ -191,16 +191,16 @@ def _redact(self, s, characters_to_reveal):
# redact based on size instead. This ensures that at least *some*
# part of the string is obfuscated, regardless of its total length.
if len(s) > 5:
return s[:3] + u"..."
return s[:3] + u""
if len(s) > 1:
return s[0] + u"..."
return u"..."
return s[0] + u""
return u""

# Otherwise just return the original string.
return s

# Truncate to the configured length and add an ellipses.
return s[:characters_to_reveal] + u"..."
return s[:characters_to_reveal] + u""

def _randomString(self, length):
"""
Expand Down
18 changes: 10 additions & 8 deletions tests/test_invites.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

from mock import Mock
from sydent.http.httpclient import FederationHttpClient
from sydent.db.invite_tokens import JoinTokenStore
Expand Down Expand Up @@ -83,43 +85,43 @@ def test_invited_email_address_obfuscation(self):
email_address = "1234567890@1234567890.com"
redacted_address = store_invite_servlet.redact_email_address(email_address)

self.assertEqual(redacted_address, "123456...@12345678...")
self.assertEqual(redacted_address, u"123456@12345678")

# Addresses that are shorter than the configured reveal length are not redacted if
# always_obfuscate is false
short_email_address = "1@1.com"
redacted_address = store_invite_servlet.redact_email_address(short_email_address)
self.assertEqual(redacted_address, "1@1.com")
self.assertEqual(redacted_address, u"1@1.com")

# Set always_obfuscate to true
self.sydent.always_obfuscate = True
redacted_address = store_invite_servlet.redact_email_address(short_email_address)
self.assertEqual(redacted_address, "...@1...")
self.assertEqual(redacted_address, u"…@1…")

# Try using a username separator string
self.sydent.third_party_invite_username_separator_string = "-"
email_address = "johnathon-jingle-smithington@john-smith.notarealtld"
redacted_address = store_invite_servlet.redact_email_address(email_address)
# Each individual component of the username should be obfuscated, but not the domain
self.assertEqual(redacted_address, "johnat...-jin...-smithi...@john-smi...")
self.assertEqual(redacted_address, u"johnat-jin-smithi@john-smi")

# Try one with a separator at a word boundary
email_address = "applejack-@someexample.com"
redacted_address = store_invite_servlet.redact_email_address(email_address)
self.assertEqual(redacted_address, "applej...-@someexam...")
self.assertEqual(redacted_address, u"applej-@someexam")

# Try one where the username is just the separator.
email_address = "-@someexample.com"
redacted_address = store_invite_servlet.redact_email_address(email_address)
self.assertEqual(redacted_address, "-@someexam...")
self.assertEqual(redacted_address, u"-@someexam")

# Try multiple, sequential separators
self.sydent.username_reveal_characters = 3
self.sydent.domain_reveal_characters = 3

email_address = "donuld--fauntleboy--puck@disnie.com"
redacted_address = store_invite_servlet.redact_email_address(email_address)
self.assertEqual(redacted_address, "don...--fau...--puc...@dis...")
self.assertEqual(redacted_address, u"don--fau--puc@dis")

class ThreepidInvitesFallbackConfigTestCase(unittest.TestCase):
"""Tests that any fallback config options work."""
Expand All @@ -146,7 +148,7 @@ def test_invited_email_address_obfuscation_fallback_config(self):
email_address = "1234567890@1234567890.com"
redacted_address = store_invite_servlet.redact_email_address(email_address)

self.assertEqual(redacted_address, "123456789...@1234...")
self.assertEqual(redacted_address, u"123456789@1234")


class ThreepidInvitesNoDeleteTestCase(unittest.TestCase):
Expand Down

0 comments on commit c33d976

Please sign in to comment.