Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit d9b8346

Browse files
committed
Merge branch 'rav/no_state_on_outliers/06_batch_send_check' into rav/no_state_on_outliers/03_raise_for_state_on_outliers
2 parents 318fbd4 + cb703eb commit d9b8346

37 files changed

+411
-119
lines changed

changelog.d/12083.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Refactor `create_new_client_event` to use a new parameter, `state_event_ids`, which accurately describes the usage with [MSC2716](https://github.com/matrix-org/matrix-doc/pull/2716) instead of abusing `auth_event_ids`.

changelog.d/12091.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Refuse to start if registration is enabled without email, captcha, or token-based verification unless new config flag `enable_registration_without_verification` is set.

changelog.d/12195.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow modules to store already existing 3PID associations.

changelog.d/12261.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug introduced in Synapse 1.52 where admins could not deactivate and GDPR-erase a user if Synapse was configured with limits on avatars.

changelog.d/12272.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add a new cache `_get_membership_from_event_id` to speed up push rule calculations in large rooms.

changelog.d/12275.doc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Corrected Authentik OpenID typo, added helpful note for troubleshooting. Contributed by @IronTooch.

changelog.d/12279.doc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
HAProxy reverse proxy guide update to stop sending IPv4-mapped address to homeserver. Contributed by @villepeh.

changelog.d/12288.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Refuse to start if DB has non-`C` locale, unless config flag `allow_unsafe_db_locale` is set to true.

changelog.d/12301.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Enhance logging for inbound federation events.

changelog.d/12311.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve type annotations for `execute_values`.

changelog.d/12313.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix compatibility with the recently-released Jinja 3.1.

changelog.d/12316.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Avoid trying to calculate the state at outlier events.

demo/start.sh

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ for port in 8080 8081 8082; do
3838
printf '\n\n# Customisation made by demo/start.sh\n\n'
3939
echo "public_baseurl: http://localhost:$port/"
4040
echo 'enable_registration: true'
41+
echo 'enable_registration_without_verification: true'
4142
echo ''
4243

4344
# Warning, this heredoc depends on the interaction of tabs and spaces.

docs/openid.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ oidc_providers:
225225
3. Create an application for synapse in Authentik and link it to the provider.
226226
4. Note the slug of your application, Client ID and Client Secret.
227227

228+
Note: RSA keys must be used for signing for Authentik, ECC keys do not work.
229+
228230
Synapse config:
229231
```yaml
230232
oidc_providers:
@@ -240,7 +242,7 @@ oidc_providers:
240242
- "email"
241243
user_mapping_provider:
242244
config:
243-
localpart_template: "{{ user.preferred_username }}}"
245+
localpart_template: "{{ user.preferred_username }}"
244246
display_name_template: "{{ user.preferred_username|capitalize }}" # TO BE FILLED: If your users have names in Authentik and you want those in Synapse, this should be replaced with user.name|capitalize.
245247
```
246248

docs/reverse_proxy.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ matrix.example.com {
182182

183183
```
184184
frontend https
185-
bind :::443 v4v6 ssl crt /etc/ssl/haproxy/ strict-sni alpn h2,http/1.1
185+
bind *:443,[::]:443 ssl crt /etc/ssl/haproxy/ strict-sni alpn h2,http/1.1
186186
http-request set-header X-Forwarded-Proto https if { ssl_fc }
187187
http-request set-header X-Forwarded-Proto http if !{ ssl_fc }
188188
http-request set-header X-Forwarded-For %[src]
@@ -195,7 +195,7 @@ frontend https
195195
use_backend matrix if matrix-host matrix-path
196196
197197
frontend matrix-federation
198-
bind :::8448 v4v6 ssl crt /etc/ssl/haproxy/synapse.pem alpn h2,http/1.1
198+
bind *:8448,[::]:8448 ssl crt /etc/ssl/haproxy/synapse.pem alpn h2,http/1.1
199199
http-request set-header X-Forwarded-Proto https if { ssl_fc }
200200
http-request set-header X-Forwarded-Proto http if !{ ssl_fc }
201201
http-request set-header X-Forwarded-For %[src]

docs/sample_config.yaml

+9-1
Original file line numberDiff line numberDiff line change
@@ -1218,10 +1218,18 @@ oembed:
12181218
# Registration can be rate-limited using the parameters in the "Ratelimiting"
12191219
# section of this file.
12201220

1221-
# Enable registration for new users.
1221+
# Enable registration for new users. Defaults to 'false'. It is highly recommended that if you enable registration,
1222+
# you use either captcha, email, or token-based verification to verify that new users are not bots. In order to enable registration
1223+
# without any verification, you must also set `enable_registration_without_verification`, found below.
12221224
#
12231225
#enable_registration: false
12241226

1227+
# Enable registration without email or captcha verification. Note: this option is *not* recommended,
1228+
# as registration without verification is a known vector for spam and abuse. Defaults to false. Has no effect
1229+
# unless `enable_registration` is also enabled.
1230+
#
1231+
#enable_registration_without_verification: true
1232+
12251233
# Time that a user's session remains valid for, after they log in.
12261234
#
12271235
# Note that this is not currently compatible with guest logins.

docs/upgrade.md

+13
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,21 @@ experimental_features:
9999
groups_enabled: false
100100
```
101101

102+
## Change in behaviour for PostgreSQL databases with unsafe locale
103+
104+
Synapse now refuses to start when using PostgreSQL with non-`C` values for `COLLATE` and
105+
`CTYPE` unless the config flag `allow_unsafe_locale`, found in the database section of
106+
the configuration file, is set to `true`. See the [PostgreSQL documentation](https://matrix-org.github.io/synapse/latest/postgres.html#fixing-incorrect-collate-or-ctype)
107+
for more information and instructions on how to fix a database with incorrect values.
108+
102109
# Upgrading to v1.55.0
103110

111+
## Open registration without verification is now disabled by default
112+
113+
Synapse will refuse to start if registration is enabled without email, captcha, or token-based verification unless the new config
114+
flag `enable_registration_without_verification` is set to "true".
115+
116+
104117
## `synctl` script has been moved
105118

106119
The `synctl` script

synapse/app/homeserver.py

+17
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,23 @@ def setup(config_options: List[str]) -> SynapseHomeServer:
351351
if config.server.gc_seconds:
352352
synapse.metrics.MIN_TIME_BETWEEN_GCS = config.server.gc_seconds
353353

354+
if (
355+
config.registration.enable_registration
356+
and not config.registration.enable_registration_without_verification
357+
):
358+
if (
359+
not config.captcha.enable_registration_captcha
360+
and not config.registration.registrations_require_3pid
361+
and not config.registration.registration_requires_token
362+
):
363+
364+
raise ConfigError(
365+
"You have enabled open registration without any verification. This is a known vector for "
366+
"spam and abuse. If you would like to allow public registration, please consider adding email, "
367+
"captcha, or token-based verification. Otherwise this check can be removed by setting the "
368+
"`enable_registration_without_verification` config option to `true`."
369+
)
370+
354371
hs = SynapseHomeServer(
355372
config.server.server_name,
356373
config=config,

synapse/config/registration.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ def read_config(self, config, **kwargs):
3333
str(config["disable_registration"])
3434
)
3535

36+
self.enable_registration_without_verification = strtobool(
37+
str(config.get("enable_registration_without_verification", False))
38+
)
39+
3640
self.registrations_require_3pid = config.get("registrations_require_3pid", [])
3741
self.allowed_local_3pids = config.get("allowed_local_3pids", [])
3842
self.enable_3pid_lookup = config.get("enable_3pid_lookup", True)
@@ -207,10 +211,18 @@ def generate_config_section(self, generate_secrets=False, **kwargs):
207211
# Registration can be rate-limited using the parameters in the "Ratelimiting"
208212
# section of this file.
209213
210-
# Enable registration for new users.
214+
# Enable registration for new users. Defaults to 'false'. It is highly recommended that if you enable registration,
215+
# you use either captcha, email, or token-based verification to verify that new users are not bots. In order to enable registration
216+
# without any verification, you must also set `enable_registration_without_verification`, found below.
211217
#
212218
#enable_registration: false
213219
220+
# Enable registration without email or captcha verification. Note: this option is *not* recommended,
221+
# as registration without verification is a known vector for spam and abuse. Defaults to false. Has no effect
222+
# unless `enable_registration` is also enabled.
223+
#
224+
#enable_registration_without_verification: true
225+
214226
# Time that a user's session remains valid for, after they log in.
215227
#
216228
# Note that this is not currently compatible with guest logins.

synapse/federation/federation_server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ async def _process_incoming_pdus_in_room_inner(
10921092
# has started processing).
10931093
while True:
10941094
async with lock:
1095-
logger.info("handling received PDU: %s", event)
1095+
logger.info("handling received PDU in room %s: %s", room_id, event)
10961096
try:
10971097
with nested_logging_context(event.event_id):
10981098
await self._federation_event_handler.on_receive_pdu(

synapse/handlers/message.py

+47-16
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ async def create_event(
493493
allow_no_prev_events: bool = False,
494494
prev_event_ids: Optional[List[str]] = None,
495495
auth_event_ids: Optional[List[str]] = None,
496+
state_event_ids: Optional[List[str]] = None,
496497
require_consent: bool = True,
497498
outlier: bool = False,
498499
historical: bool = False,
@@ -527,6 +528,15 @@ async def create_event(
527528
528529
If non-None, prev_event_ids must also be provided.
529530
531+
state_event_ids:
532+
The full state at a given event. This is used particularly by the MSC2716
533+
/batch_send endpoint. One use case is with insertion events which float at
534+
the beginning of a historical batch and don't have any `prev_events` to
535+
derive from; we add all of these state events as the explicit state so the
536+
rest of the historical batch can inherit the same state and state_group.
537+
This should normally be left as None, which will cause the auth_event_ids
538+
to be calculated based on the room state at the prev_events.
539+
530540
require_consent: Whether to check if the requester has
531541
consented to the privacy policy.
532542
@@ -612,6 +622,7 @@ async def create_event(
612622
allow_no_prev_events=allow_no_prev_events,
613623
prev_event_ids=prev_event_ids,
614624
auth_event_ids=auth_event_ids,
625+
state_event_ids=state_event_ids,
615626
depth=depth,
616627
)
617628

@@ -772,6 +783,7 @@ async def create_and_send_nonmember_event(
772783
allow_no_prev_events: bool = False,
773784
prev_event_ids: Optional[List[str]] = None,
774785
auth_event_ids: Optional[List[str]] = None,
786+
state_event_ids: Optional[List[str]] = None,
775787
ratelimit: bool = True,
776788
txn_id: Optional[str] = None,
777789
ignore_shadow_ban: bool = False,
@@ -801,6 +813,14 @@ async def create_and_send_nonmember_event(
801813
based on the room state at the prev_events.
802814
803815
If non-None, prev_event_ids must also be provided.
816+
state_event_ids:
817+
The full state at a given event. This is used particularly by the MSC2716
818+
/batch_send endpoint. One use case is with insertion events which float at
819+
the beginning of a historical batch and don't have any `prev_events` to
820+
derive from; we add all of these state events as the explicit state so the
821+
rest of the historical batch can inherit the same state and state_group.
822+
This should normally be left as None, which will cause the auth_event_ids
823+
to be calculated based on the room state at the prev_events.
804824
ratelimit: Whether to rate limit this send.
805825
txn_id: The transaction ID.
806826
ignore_shadow_ban: True if shadow-banned users should be allowed to
@@ -856,8 +876,10 @@ async def create_and_send_nonmember_event(
856876
requester,
857877
event_dict,
858878
txn_id=txn_id,
879+
allow_no_prev_events=allow_no_prev_events,
859880
prev_event_ids=prev_event_ids,
860881
auth_event_ids=auth_event_ids,
882+
state_event_ids=state_event_ids,
861883
outlier=outlier,
862884
historical=historical,
863885
depth=depth,
@@ -893,6 +915,7 @@ async def create_new_client_event(
893915
allow_no_prev_events: bool = False,
894916
prev_event_ids: Optional[List[str]] = None,
895917
auth_event_ids: Optional[List[str]] = None,
918+
state_event_ids: Optional[List[str]] = None,
896919
depth: Optional[int] = None,
897920
) -> Tuple[EventBase, EventContext]:
898921
"""Create a new event for a local client
@@ -915,38 +938,42 @@ async def create_new_client_event(
915938
Should normally be left as None, which will cause them to be calculated
916939
based on the room state at the prev_events.
917940
941+
state_event_ids:
942+
The full state at a given event. This is used particularly by the MSC2716
943+
/batch_send endpoint. One use case is with insertion events which float at
944+
the beginning of a historical batch and don't have any `prev_events` to
945+
derive from; we add all of these state events as the explicit state so the
946+
rest of the historical batch can inherit the same state and state_group.
947+
This should normally be left as None, which will cause the auth_event_ids
948+
to be calculated based on the room state at the prev_events.
949+
918950
depth: Override the depth used to order the event in the DAG.
919951
Should normally be set to None, which will cause the depth to be calculated
920952
based on the prev_events.
921953
922954
Returns:
923955
Tuple of created event, context
924956
"""
925-
# Strip down the auth_event_ids to only what we need to auth the event.
957+
# Strip down the state_event_ids to only what we need to auth the event.
926958
# For example, we don't need extra m.room.member that don't match event.sender
927-
full_state_ids_at_event = None
928-
if auth_event_ids is not None:
929-
# If auth events are provided, prev events must be also.
959+
if state_event_ids is not None:
960+
# Do a quick check to make sure that prev_event_ids is present to
961+
# make the type-checking around `builder.build` happy.
930962
# prev_event_ids could be an empty array though.
931963
assert prev_event_ids is not None
932964

933-
# Copy the full auth state before it stripped down
934-
full_state_ids_at_event = auth_event_ids.copy()
935-
936965
temp_event = await builder.build(
937966
prev_event_ids=prev_event_ids,
938-
auth_event_ids=auth_event_ids,
967+
auth_event_ids=state_event_ids,
939968
depth=depth,
940969
)
941-
auth_events = await self.store.get_events_as_list(auth_event_ids)
970+
state_events = await self.store.get_events_as_list(state_event_ids)
942971
# Create a StateMap[str]
943-
auth_event_state_map = {
944-
(e.type, e.state_key): e.event_id for e in auth_events
945-
}
946-
# Actually strip down and use the necessary auth events
972+
state_map = {(e.type, e.state_key): e.event_id for e in state_events}
973+
# Actually strip down and only use the necessary auth events
947974
auth_event_ids = self._event_auth_handler.compute_auth_events(
948975
event=temp_event,
949-
current_state_ids=auth_event_state_map,
976+
current_state_ids=state_map,
950977
for_verification=False,
951978
)
952979

@@ -989,12 +1016,16 @@ async def create_new_client_event(
9891016
context = EventContext.for_outlier()
9901017
elif (
9911018
event.type == EventTypes.MSC2716_INSERTION
992-
and full_state_ids_at_event
1019+
and state_event_ids
9931020
and builder.internal_metadata.is_historical()
9941021
):
1022+
# Add explicit state to the insertion event so it has state to derive
1023+
# from even though it's floating with no `prev_events`. The rest of
1024+
# the batch can derive from this state and state_group.
1025+
#
9951026
# TODO(faster_joins): figure out how this works, and make sure that the
9961027
# old state is complete.
997-
old_state = await self.store.get_events_as_list(full_state_ids_at_event)
1028+
old_state = await self.store.get_events_as_list(state_event_ids)
9981029
context = await self.state.compute_event_context(event, old_state=old_state)
9991030
else:
10001031
context = await self.state.compute_event_context(event)

synapse/handlers/profile.py

+6
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,18 @@ async def check_avatar_size_and_mime_type(self, mxc: str) -> bool:
336336
"""Check that the size and content type of the avatar at the given MXC URI are
337337
within the configured limits.
338338
339+
If the given `mxc` is empty, no checks are performed. (Users are always able to
340+
unset their avatar.)
341+
339342
Args:
340343
mxc: The MXC URI at which the avatar can be found.
341344
342345
Returns:
343346
A boolean indicating whether the file can be allowed to be set as an avatar.
344347
"""
348+
if mxc == "":
349+
return True
350+
345351
if not self.max_avatar_size and not self.allowed_avatar_mimetypes:
346352
return True
347353

0 commit comments

Comments
 (0)