Apply federated blocks when downloading announces

main
Bob Mottram 2024-02-09 22:09:18 +00:00
parent 2e23b3b9e5
commit d296f166c5
11 changed files with 54 additions and 24 deletions

View File

@ -12959,6 +12959,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.debug,
self.server.buy_sites,
self.server.blocked_cache,
self.server.block_federated,
self.server.auto_cw_cache)
if conv_str:
msg = conv_str.encode('utf-8')

View File

@ -787,7 +787,8 @@ def _read_local_box_post(session, nickname: str, domain: str,
translate: {}, your_actor: str,
domain_full: str, person_cache: {},
signing_priv_key_pem: str,
blocked_cache: {}, bold_reading: bool) -> {}:
blocked_cache: {}, block_federated: [],
bold_reading: bool) -> {}:
"""Reads a post from the given timeline
Returns the post json
"""
@ -835,7 +836,7 @@ def _read_local_box_post(session, nickname: str, domain: str,
system_language,
domain_full, person_cache,
signing_priv_key_pem,
blocked_cache, bold_reading,
blocked_cache, block_federated, bold_reading,
show_vote_posts,
languages_understood)
if post_json_object2:
@ -1515,6 +1516,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
media_creator = ''
blocked_cache = {}
block_federated = []
languages_understood = []
indent = ' '
@ -1811,7 +1813,8 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
espeak, translate, your_actor,
domain_full, person_cache,
signing_priv_key_pem,
blocked_cache, bold_reading)
blocked_cache, block_federated,
bold_reading)
print('')
say_str = 'Press Enter to continue...'
say_str2 = _highlight_text(say_str)
@ -2685,6 +2688,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
domain_full, person_cache,
signing_priv_key_pem,
blocked_cache,
block_federated,
bold_reading,
show_vote_posts,
languages_understood)

View File

@ -2720,9 +2720,11 @@ def _command_options() -> None:
signing_priv_key_pem = None
if argb.secure_mode:
signing_priv_key_pem = get_instance_actor_key(base_dir, domain)
block_federated = []
ctr = migrate_accounts(base_dir, session,
http_prefix, cached_webfingers,
True, signing_priv_key_pem)
True, signing_priv_key_pem,
block_federated)
if ctr == 0:
print('No followed accounts have moved')
else:

View File

@ -729,7 +729,8 @@ def save_post_to_inbox_queue(base_dir: str, http_prefix: str,
print('No post Domain in actor')
return None
if is_blocked(base_dir, nickname, domain,
post_nickname, post_domain, blocked_cache):
post_nickname, post_domain,
blocked_cache, block_federated):
if debug:
print('DEBUG: post from ' + post_nickname + ' blocked')
return None
@ -775,7 +776,7 @@ def save_post_to_inbox_queue(base_dir: str, http_prefix: str,
return None
if is_blocked(base_dir, nickname, domain,
reply_nickname, reply_domain,
blocked_cache):
blocked_cache, block_federated):
if debug:
print('WARN: post contains reply from ' +
str(actor) +
@ -1833,6 +1834,7 @@ def _receive_move_activity(session, base_dir: str,
i2p_domain: str,
sites_unavailable: [],
blocked_cache: [],
block_federated: [],
system_language: str) -> bool:
"""Receives a move activity within the POST section of HTTPServer
https://codeberg.org/fediverse/fep/src/branch/main/fep/7628/fep-7628.md
@ -1898,7 +1900,8 @@ def _receive_move_activity(session, base_dir: str,
return False
# is the moved actor blocked?
if is_blocked(base_dir, nickname, domain,
moved_nickname, moved_domain, blocked_cache):
moved_nickname, moved_domain,
blocked_cache, block_federated):
print('INBOX: Move activity actor is blocked: ' + moved_actor)
return False
print('INBOX: Move activity sending follow request: ' +
@ -3208,7 +3211,8 @@ def _receive_announce(recent_posts_cache: {},
if debug:
print('DEBUG: announced nickname is blocked')
return False
if is_blocked(base_dir, nickname, domain, actor_nickname, actor_domain):
if is_blocked(base_dir, nickname, domain, actor_nickname, actor_domain,
None, block_federated):
print('Receive announce blocked for actor: ' +
actor_nickname + '@' + actor_domain)
return False
@ -3230,7 +3234,8 @@ def _receive_announce(recent_posts_cache: {},
print('WARN: _receive_announce no announced_actor_domain')
return False
if is_blocked(base_dir, nickname, domain,
announced_actor_nickname, announced_actor_domain):
announced_actor_nickname, announced_actor_domain,
None, block_federated):
print('Receive announce object blocked for actor: ' +
announced_actor_nickname + '@' + announced_actor_domain)
return False
@ -3324,7 +3329,8 @@ def _receive_announce(recent_posts_cache: {},
system_language,
domain_full, person_cache,
signing_priv_key_pem,
blocked_cache, bold_reading,
blocked_cache, block_federated,
bold_reading,
show_vote_posts,
languages_understood)
if not post_json_object:
@ -6467,6 +6473,7 @@ def run_inbox_queue(server,
i2p_domain,
server.sites_unavailable,
server.blocked_cache,
server.block_federated,
server.system_language):
if debug:
print('Queue: _receive_move_activity ' + key_id)

View File

@ -26,7 +26,8 @@ def _move_following_handles_for_account(base_dir: str,
http_prefix: str,
cached_webfingers: {},
debug: bool,
signing_priv_key_pem: str) -> int:
signing_priv_key_pem: str,
block_federated: []) -> int:
"""Goes through all follows for an account and updates any that have moved
"""
ctr = 0
@ -42,14 +43,16 @@ def _move_following_handles_for_account(base_dir: str,
_update_moved_handle(base_dir, nickname, domain,
follow_handle, session,
http_prefix, cached_webfingers,
debug, signing_priv_key_pem)
debug, signing_priv_key_pem,
block_federated)
return ctr
def _update_moved_handle(base_dir: str, nickname: str, domain: str,
handle: str, session,
http_prefix: str, cached_webfingers: {},
debug: bool, signing_priv_key_pem: str) -> int:
debug: bool, signing_priv_key_pem: str,
block_federated: []) -> int:
"""Check if an account has moved, and if so then alter following.txt
for each account.
Returns 1 if moved, 0 otherwise
@ -118,7 +121,8 @@ def _update_moved_handle(base_dir: str, nickname: str, domain: str,
moved_to_domain_full = moved_to_domain + ':' + str(moved_to_port)
group_account = has_group_type(base_dir, moved_to_url, None)
if is_blocked(base_dir, nickname, domain,
moved_to_nickname, moved_to_domain):
moved_to_nickname, moved_to_domain,
None, block_federated):
# someone that you follow has moved to a blocked domain
# so just unfollow them
unfollow_account(base_dir, nickname, domain,
@ -207,7 +211,8 @@ def _update_moved_handle(base_dir: str, nickname: str, domain: str,
def migrate_accounts(base_dir: str, session,
http_prefix: str, cached_webfingers: {},
debug: bool, signing_priv_key_pem: str) -> int:
debug: bool, signing_priv_key_pem: str,
block_federated: []) -> int:
"""If followed accounts change then this modifies the
following lists for each account accordingly.
Returns the number of accounts migrated
@ -224,6 +229,7 @@ def migrate_accounts(base_dir: str, session,
_move_following_handles_for_account(base_dir, nickname, domain,
session, http_prefix,
cached_webfingers, debug,
signing_priv_key_pem)
signing_priv_key_pem,
block_federated)
break
return ctr

View File

@ -4390,6 +4390,7 @@ def is_image_media(session, base_dir: str, http_prefix: str,
"""
if post_json_object['type'] == 'Announce':
blocked_cache = {}
block_federated = []
post_json_announce = \
download_announce(session, base_dir, http_prefix,
nickname, domain, post_json_object,
@ -4401,7 +4402,8 @@ def is_image_media(session, base_dir: str, http_prefix: str,
system_language,
domain_full, person_cache,
signing_priv_key_pem,
blocked_cache, bold_reading,
blocked_cache, block_federated,
bold_reading,
show_vote_posts,
languages_understood)
if post_json_announce:
@ -5784,7 +5786,8 @@ def download_announce(session, base_dir: str, http_prefix: str,
system_language: str,
domain_full: str, person_cache: {},
signing_priv_key_pem: str,
blocked_cache: {}, bold_reading: bool,
blocked_cache: {}, block_federated: [],
bold_reading: bool,
show_vote_posts: bool,
languages_understood: []) -> {}:
"""Download the post referenced by an announce
@ -5917,6 +5920,7 @@ def download_announce(session, base_dir: str, http_prefix: str,
convert_video_to_note(base_dir, nickname, domain,
system_language,
announced_json, blocked_cache,
block_federated,
languages_understood)
if converted_json:
announced_json = converted_json

View File

@ -296,7 +296,7 @@ def _indicate_new_share_available(base_dir: str, http_prefix: str,
# does this account block you?
if account_nickname != nickname:
if is_blocked(base_dir, account_nickname, domain,
nickname, domain, None):
nickname, domain, None, None):
continue
local_actor = \
local_actor_url(http_prefix, account_nickname, domain_full)

View File

@ -26,6 +26,7 @@ from filters import is_filtered
def convert_video_to_note(base_dir: str, nickname: str, domain: str,
system_language: str,
post_json_object: {}, blocked_cache: {},
block_federated: [],
languages_understood: []) -> {}:
"""Converts a PeerTube Video ActivityPub(ish) object into
a Note, so that it can then be displayed in a timeline
@ -67,7 +68,8 @@ def convert_video_to_note(base_dir: str, nickname: str, domain: str,
return None
post_domain_full = get_full_domain(post_domain, post_domain_port)
if is_blocked(base_dir, nickname, domain,
post_nickname, post_domain_full, blocked_cache):
post_nickname, post_domain_full,
blocked_cache, block_federated):
return None
# check that the content is valid

View File

@ -49,6 +49,7 @@ def html_conversation_view(authorized: bool, post_id: str,
min_images_for_accounts: [],
debug: bool, buy_sites: {},
blocked_cache: [],
block_federated: [],
auto_cw_cache: {}) -> str:
"""Show a page containing a conversation thread
"""
@ -91,7 +92,7 @@ def html_conversation_view(authorized: bool, post_id: str,
if from_nickname and from_domain:
if is_blocked(base_dir, nickname, domain,
from_nickname, from_domain,
blocked_cache):
blocked_cache, block_federated):
show_individual_post_icons = False
allow_deletion = False
post_str = \

View File

@ -2260,6 +2260,7 @@ def individual_post_as_html(signing_priv_key_pem: str,
if post_json_object['type'] == 'Announce':
announce_json_object = post_json_object.copy()
blocked_cache = {}
block_federated = []
show_vote_posts = True
show_vote_file = acct_dir(base_dir, nickname, domain) + '/.noVotes'
if os.path.isfile(show_vote_file):
@ -2275,7 +2276,8 @@ def individual_post_as_html(signing_priv_key_pem: str,
system_language,
domain_full, person_cache,
signing_priv_key_pem,
blocked_cache, bold_reading,
blocked_cache, block_federated,
bold_reading,
show_vote_posts,
languages_understood)
if not post_json_announce:

View File

@ -484,7 +484,7 @@ def shares_timeline_json(actor: str, page_number: int, items_per_page: int,
# Don't include shared items from blocked accounts
if account_nickname != nickname:
if is_blocked(base_dir, nickname, domain,
account_nickname, domain, None):
account_nickname, domain, None, None):
continue
# actor who owns this share
owner = actor.split('/users/')[0] + '/users/' + account_nickname
@ -529,7 +529,8 @@ def shares_timeline_json(actor: str, page_number: int, items_per_page: int,
if not share_nickname:
continue
if is_blocked(base_dir, nickname, domain,
share_nickname, federated_domain, None):
share_nickname, federated_domain,
None, None):
continue
item['actor'] = share_actor
item['shareId'] = item_id