Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event is not failed when creating a spam checker module that filters federated rooms #16727

Open
matrixbot opened this issue Dec 21, 2023 · 0 comments

Comments

@matrixbot
Copy link
Collaborator

matrixbot commented Dec 21, 2023

This issue has been migrated from #16727.


Description

I am trying to create a module that blocks federation of rooms between two matrix servers.
Logics is based on m.room.member event type and determines source server and destination server.
If source server is different than destination server and room id is not in allowed rooms, then return forbidden.

Rooms are provided as config in values file:

- module: federation_event_checker.FilterFederatedRooms
  config: 
    fedrooms_allowed:
      - "!AanXREkoCFRofkefum:matrix2.dev.development.int" #matrix2tomatrix

Python module

async def check_event_for_spam(self, event: "synapse.events.EventBase"):

    event_dict = event.get_dict()

    try:
        event_type = event_dict.get('type', None) 
        if event_type == 'm.room.member':
            print("Identifier passed event type")
            event_content = event_dict.get('content', None) 
            print("Identifier print event content",event_content)
            if event_content["membership"] == 'invite':
                print("Identifier determine source server and destination server")
                source_server = event.origin
                dest_server = event.state_key.split(":")[1]
                fedroom = event_dict.get('room_id', None) 
                if source_server != dest_server: 
                    if fedroom not in self.fedrooms_allowed: 
                       print("Identifier: For room id", fedroom, " federation IS NOT allowed with other matrix servers")
                       return synapse.module_api.errors.Codes.FORBIDDEN
    except Exception:
        print("Identifier exception for event", event_dict)
        return synapse.module_api.errors.Codes.FORBIDDEN
    return synapse.module_api.NOT_SPAM

Logs from execution

2023-12-05 06:45:20,474 - synapse.util.metrics - 163 - DEBUG - PUT-62- Entering block federation_event_checker.FilterFederatedRooms.check_event_for_spam

2023-12-05 06:45:20,475 - twisted - 275 - INFO - PUT-62- Identifier passed event type
2023-12-05 06:45:20,475 - twisted - 275 - INFO - PUT-62- Identifier print event content {'displayname': 'xxxxx', 'membership': 'invite'}
2023-12-05 06:45:20,475 - twisted - 275 - INFO - PUT-62- Identifier determine source server and destination server
2023-12-05 06:45:20,475 - twisted - 275 - INFO - PUT-62- Identifier For room id !zznlJqNveedzoyXqee:matrix2.dev.development.int federation IS NOT allowed with other matrix servers
2023-12-05 06:45:20,475 - synapse.util.metrics - 176 - DEBUG - PUT-62- Exiting block federation_event_checker.FilterFederatedRooms.check_event_for_spam
2023-12-05 06:45:20,475 - synapse.federation.federation_base - 143 - WARNING - PUT-62- Event contains spam, soft-failing $rQtlVB1HGJsli1eRemKWawHYO4hL0L9RGCA5zPbXISE

Last line is very important: "Event contains spam, soft-failing $rQtlVB1HGJsli1eRemKWawHYO4hL0L9RGCA5zPbXISE"
It says that the event contains spam and soft failing but still invite can be sent to the other user and the other use may accept the invite then talk.

Steps to reproduce

  • Having two federated matrix servers: matrix and matrix2
  • Creating a new room on matrix2 server (room is not in allowed list)
  • Inviting a user to the room from matrix server
  • User from matrix server is able to accept the request and join the room but it should not be able

Homeserver

local homeserver

Synapse Version

{"server":{"name":"Synapse","version":"1.92.3"}}

Installation Method

Docker (matrixdotorg/synapse)

Database

Postgresql

Workers

Single process

Platform

Rancher - Kubernetes

Configuration

  • module: federation_event_checker.FilterFederatedRooms
    config:
    fedrooms_allowed:
    - "!AanXREkoCFRofkefum:matrix2.dev.development.int" #matrix2tomatrix

Relevant log output

2023-12-05 06:45:20,474 - synapse.util.metrics - 163 - DEBUG - PUT-62- Entering block federation_event_checker.FilterFederatedRooms.check_event_for_spam

2023-12-05 06:45:20,475 - twisted - 275 - INFO - PUT-62- Identifier passed event type
2023-12-05 06:45:20,475 - twisted - 275 - INFO - PUT-62- Identifier print event content {'displayname': 'vlad_ad', 'membership': 'invite'}
2023-12-05 06:45:20,475 - twisted - 275 - INFO - PUT-62- Identifier determine source server and destination server
2023-12-05 06:45:20,475 - twisted - 275 - INFO - PUT-62- Identifier For room id !zznlJqNveedzoyXqee:matrix2.dev.development.int federation IS NOT allowed with other matrix servers
2023-12-05 06:45:20,475 - synapse.util.metrics - 176 - DEBUG - PUT-62- Exiting block federation_event_checker.FilterFederatedRooms.check_event_for_spam
2023-12-05 06:45:20,475 - synapse.federation.federation_base - 143 - WARNING - PUT-62- Event contains spam, soft-failing $rQtlVB1HGJsli1eRemKWawHYO4hL0L9RGCA5zPbXISE

Anything else that would be useful to know?

No response

@matrixbot matrixbot changed the title Dummy issue Event is not failed when creating a spam checker module that filters federated rooms Dec 22, 2023
@matrixbot matrixbot reopened this Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant