Skip to content

Commit

Permalink
activitypub._load_user: handle bad web ids
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Oct 17, 2024
1 parent 6560c49 commit 61b30f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion activitypub.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,12 @@ def _load_user(handle_or_id, create=False):
id = handle_or_id

assert id
user = proto.get_or_create(id) if create else proto.get_by_id(id)
try:
user = proto.get_or_create(id) if create else proto.get_by_id(id)
except ValueError as e:
logging.warning(e)
user = None

if not user or not user.is_enabled(ActivityPub):
error(f'{proto.LABEL} user {id} not found', status=404)

Expand Down
6 changes: 6 additions & 0 deletions tests/test_activitypub.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,12 @@ def test_actor_opted_out(self, *_):
got = self.client.get('/user.com')
self.assertEqual(404, got.status_code)

def test_actor_bad_id(self, *_):
# Web.get_or_create => urllib.parse.urlparse raises
# ValueError: Invalid IPv6 URL
got = self.client.get('/bsky]foo.bar')
self.assertEqual(404, got.status_code)

def test_actor_protocol_bot_user(self, *_):
"""Web users are special cased to drop the /web/ prefix."""
actor_as2 = json_loads(util.read('bsky.brid.gy.as2.json'))
Expand Down

0 comments on commit 61b30f0

Please sign in to comment.