Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion froide/account/services.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import hashlib
import hmac
import re
import unicodedata
from datetime import timedelta
from typing import Dict, Optional
from urllib.parse import urlencode
Expand Down Expand Up @@ -313,7 +314,7 @@ def check_against_blocklist(cls, user, save=True) -> bool:
user.save()
return blocklisted

def apply_name_redaction(self, content, replacement=""):
def apply_name_redaction(self, content, replacement="", unicode=True):
if not self.user.private:
return content

Expand All @@ -328,6 +329,15 @@ def apply_name_redaction(self, content, replacement=""):
*self.user.first_name.split(),
*self.user.last_name.split(),
]

if not unicode:
user_asciiish_name = (
unicodedata.normalize("NFKD", self.user.get_full_name())
.encode("ascii", "ignore")
.decode()
)
needles.extend(user_asciiish_name.split())

if self.user.organization_name:
needles.append(self.user.organization_name)

Expand Down
10 changes: 10 additions & 0 deletions froide/account/tests/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,3 +854,13 @@ def test_multipart_name_redaction():
repl = "NAME"
redacted_name = account_service.apply_name_redaction(name, repl)
assert redacted_name == "Reply-NAME-NAME-NAME.pdf"


@pytest.mark.django_db
def test_unicode_name_redaction():
user = User.objects.create(first_name="Älex", last_name="Eğçamplé", private=True)
account_service = AccountService(user)
name = "reply-alex-egcample.pdf"
repl = "NAME"
redacted_name = account_service.apply_name_redaction(name, repl, unicode=False)
assert redacted_name == "reply-NAME-NAME.pdf"
4 changes: 3 additions & 1 deletion froide/foirequest/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,9 @@ def add_attachments(self, foirequest, message, attachments):

# Translators: replacement for person name in filename
repl = str(_("NAME"))
att.name = account_service.apply_name_redaction(att.name, repl)
att.name = account_service.apply_name_redaction(
att.name, repl, unicode=False
)
att.name = re.sub(r"[^A-Za-z0-9_\.\-]", "", att.name)
att.name = att.name[:250]

Expand Down