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

Commit 462e681

Browse files
committed
Merge tag 'v1.21.0rc2' into develop
Synapse 1.21.0rc2 (2020-10-02) ============================== Features -------- - Convert additional templates from inline HTML to Jinja2 templates. ([\#8444](#8444)) Bugfixes -------- - Fix a regression in v1.21.0rc1 which broke thumbnails of remote media. ([\#8438](#8438)) - Do not expose the experimental `uk.half-shot.msc2778.login.application_service` flow in the login API, which caused a compatibility problem with Element iOS. ([\#8440](#8440)) - Fix malformed log line in new federation "catch up" logic. ([\#8442](#8442)) - Fix DB query on startup for negative streams which caused long start up times. Introduced in [\#8374](#8374). ([\#8447](#8447))
2 parents 3bd2a2c + 9de6e9e commit 462e681

File tree

14 files changed

+163
-141
lines changed

14 files changed

+163
-141
lines changed

CHANGES.md

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
Synapse 1.21.0rc2 (2020-10-02)
2+
==============================
3+
4+
Features
5+
--------
6+
7+
- Convert additional templates from inline HTML to Jinja2 templates. ([\#8444](https://github.com/matrix-org/synapse/issues/8444))
8+
9+
Bugfixes
10+
--------
11+
12+
- Fix a regression in v1.21.0rc1 which broke thumbnails of remote media. ([\#8438](https://github.com/matrix-org/synapse/issues/8438))
13+
- Do not expose the experimental `uk.half-shot.msc2778.login.application_service` flow in the login API, which caused a compatibility problem with Element iOS. ([\#8440](https://github.com/matrix-org/synapse/issues/8440))
14+
- Fix malformed log line in new federation "catch up" logic. ([\#8442](https://github.com/matrix-org/synapse/issues/8442))
15+
- Fix DB query on startup for negative streams which caused long start up times. Introduced in [\#8374](https://github.com/matrix-org/synapse/issues/8374). ([\#8447](https://github.com/matrix-org/synapse/issues/8447))
16+
17+
118
Synapse 1.21.0rc1 (2020-10-01)
219
==============================
320

synapse/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
except ImportError:
4949
pass
5050

51-
__version__ = "1.21.0rc1"
51+
__version__ = "1.21.0rc2"
5252

5353
if bool(os.environ.get("SYNAPSE_TEST_PATCH_LOG_CONTEXTS", False)):
5454
# We import here so that we don't have to install a bunch of deps when

synapse/config/_base.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,11 @@ def read_templates(
242242
env = jinja2.Environment(loader=loader, autoescape=autoescape)
243243

244244
# Update the environment with our custom filters
245-
env.filters.update(
246-
{
247-
"format_ts": _format_ts_filter,
248-
"mxc_to_http": _create_mxc_to_http_filter(self.public_baseurl),
249-
}
250-
)
245+
env.filters.update({"format_ts": _format_ts_filter})
246+
if self.public_baseurl:
247+
env.filters.update(
248+
{"mxc_to_http": _create_mxc_to_http_filter(self.public_baseurl)}
249+
)
251250

252251
for filename in filenames:
253252
# Load the template

synapse/config/captcha.py

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def read_config(self, config, **kwargs):
2828
"recaptcha_siteverify_api",
2929
"https://www.recaptcha.net/recaptcha/api/siteverify",
3030
)
31+
self.recaptcha_template = self.read_templates(
32+
["recaptcha.html"], autoescape=True
33+
)[0]
3134

3235
def generate_config_section(self, **kwargs):
3336
return """\

synapse/config/consent_config.py

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ def __init__(self, *args):
8989

9090
def read_config(self, config, **kwargs):
9191
consent_config = config.get("user_consent")
92+
self.terms_template = self.read_templates(["terms.html"], autoescape=True)[0]
93+
9294
if consent_config is None:
9395
return
9496
self.user_consent_version = str(consent_config["version"])

synapse/config/registration.py

+5
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ def read_config(self, config, **kwargs):
187187
session_lifetime = self.parse_duration(session_lifetime)
188188
self.session_lifetime = session_lifetime
189189

190+
# The success template used during fallback auth.
191+
self.fallback_success_template = self.read_templates(
192+
["auth_success.html"], autoescape=True
193+
)[0]
194+
190195
def generate_config_section(self, generate_secrets=False, **kwargs):
191196
if generate_secrets:
192197
registration_shared_secret = 'registration_shared_secret: "%s"' % (

synapse/federation/sender/per_destination_queue.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ async def _catch_up_transmission_loop(self) -> None:
490490
)
491491

492492
if logger.isEnabledFor(logging.INFO):
493-
rooms = (p.room_id for p in catchup_pdus)
493+
rooms = [p.room_id for p in catchup_pdus]
494494
logger.info("Catching up rooms to %s: %r", self._destination, rooms)
495495

496496
success = await self._transaction_manager.send_new_transaction(
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<html>
2+
<head>
3+
<title>Success!</title>
4+
<meta name='viewport' content='width=device-width, initial-scale=1,
5+
user-scalable=no, minimum-scale=1.0, maximum-scale=1.0'>
6+
<link rel="stylesheet" href="/_matrix/static/client/register/style.css">
7+
<script>
8+
if (window.onAuthDone) {
9+
window.onAuthDone();
10+
} else if (window.opener && window.opener.postMessage) {
11+
window.opener.postMessage("authDone", "*");
12+
}
13+
</script>
14+
</head>
15+
<body>
16+
<div>
17+
<p>Thank you</p>
18+
<p>You may now close this window and return to the application</p>
19+
</div>
20+
</body>
21+
</html>

synapse/res/templates/recaptcha.html

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<html>
2+
<head>
3+
<title>Authentication</title>
4+
<meta name='viewport' content='width=device-width, initial-scale=1,
5+
user-scalable=no, minimum-scale=1.0, maximum-scale=1.0'>
6+
<script src="https://www.recaptcha.net/recaptcha/api.js"
7+
async defer></script>
8+
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
9+
<link rel="stylesheet" href="/_matrix/static/client/register/style.css">
10+
<script>
11+
function captchaDone() {
12+
$('#registrationForm').submit();
13+
}
14+
</script>
15+
</head>
16+
<body>
17+
<form id="registrationForm" method="post" action="{{ myurl }}">
18+
<div>
19+
<p>
20+
Hello! We need to prevent computer programs and other automated
21+
things from creating accounts on this server.
22+
</p>
23+
<p>
24+
Please verify that you're not a robot.
25+
</p>
26+
<input type="hidden" name="session" value="{{ session }}" />
27+
<div class="g-recaptcha"
28+
data-sitekey="{{ sitekey }}"
29+
data-callback="captchaDone">
30+
</div>
31+
<noscript>
32+
<input type="submit" value="All Done" />
33+
</noscript>
34+
</div>
35+
</div>
36+
</form>
37+
</body>
38+
</html>

synapse/res/templates/terms.html

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<html>
2+
<head>
3+
<title>Authentication</title>
4+
<meta name='viewport' content='width=device-width, initial-scale=1,
5+
user-scalable=no, minimum-scale=1.0, maximum-scale=1.0'>
6+
<link rel="stylesheet" href="/_matrix/static/client/register/style.css">
7+
</head>
8+
<body>
9+
<form id="registrationForm" method="post" action="{{ myurl }}">
10+
<div>
11+
<p>
12+
Please click the button below if you agree to the
13+
<a href="{{ terms_url }}">privacy policy of this homeserver.</a>
14+
</p>
15+
<input type="hidden" name="session" value="{{ session }}" />
16+
<input type="submit" value="Agree" />
17+
</div>
18+
</form>
19+
</body>
20+
</html>

synapse/rest/client/v1/login.py

-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ def on_GET(self, request: SynapseRequest):
111111
({"type": t} for t in self.auth_handler.get_supported_login_types())
112112
)
113113

114-
flows.append({"type": LoginRestServlet.APPSERVICE_TYPE})
115-
116114
return 200, {"flows": flows}
117115

118116
def on_OPTIONS(self, request: SynapseRequest):

synapse/rest/client/v2_alpha/auth.py

+26-110
Original file line numberDiff line numberDiff line change
@@ -25,94 +25,6 @@
2525

2626
logger = logging.getLogger(__name__)
2727

28-
RECAPTCHA_TEMPLATE = """
29-
<html>
30-
<head>
31-
<title>Authentication</title>
32-
<meta name='viewport' content='width=device-width, initial-scale=1,
33-
user-scalable=no, minimum-scale=1.0, maximum-scale=1.0'>
34-
<script src="https://www.recaptcha.net/recaptcha/api.js"
35-
async defer></script>
36-
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
37-
<link rel="stylesheet" href="/_matrix/static/client/register/style.css">
38-
<script>
39-
function captchaDone() {
40-
$('#registrationForm').submit();
41-
}
42-
</script>
43-
</head>
44-
<body>
45-
<form id="registrationForm" method="post" action="%(myurl)s">
46-
<div>
47-
<p>
48-
Hello! We need to prevent computer programs and other automated
49-
things from creating accounts on this server.
50-
</p>
51-
<p>
52-
Please verify that you're not a robot.
53-
</p>
54-
<input type="hidden" name="session" value="%(session)s" />
55-
<div class="g-recaptcha"
56-
data-sitekey="%(sitekey)s"
57-
data-callback="captchaDone">
58-
</div>
59-
<noscript>
60-
<input type="submit" value="All Done" />
61-
</noscript>
62-
</div>
63-
</div>
64-
</form>
65-
</body>
66-
</html>
67-
"""
68-
69-
TERMS_TEMPLATE = """
70-
<html>
71-
<head>
72-
<title>Authentication</title>
73-
<meta name='viewport' content='width=device-width, initial-scale=1,
74-
user-scalable=no, minimum-scale=1.0, maximum-scale=1.0'>
75-
<link rel="stylesheet" href="/_matrix/static/client/register/style.css">
76-
</head>
77-
<body>
78-
<form id="registrationForm" method="post" action="%(myurl)s">
79-
<div>
80-
<p>
81-
Please click the button below if you agree to the
82-
<a href="%(terms_url)s">privacy policy of this homeserver.</a>
83-
</p>
84-
<input type="hidden" name="session" value="%(session)s" />
85-
<input type="submit" value="Agree" />
86-
</div>
87-
</form>
88-
</body>
89-
</html>
90-
"""
91-
92-
SUCCESS_TEMPLATE = """
93-
<html>
94-
<head>
95-
<title>Success!</title>
96-
<meta name='viewport' content='width=device-width, initial-scale=1,
97-
user-scalable=no, minimum-scale=1.0, maximum-scale=1.0'>
98-
<link rel="stylesheet" href="/_matrix/static/client/register/style.css">
99-
<script>
100-
if (window.onAuthDone) {
101-
window.onAuthDone();
102-
} else if (window.opener && window.opener.postMessage) {
103-
window.opener.postMessage("authDone", "*");
104-
}
105-
</script>
106-
</head>
107-
<body>
108-
<div>
109-
<p>Thank you</p>
110-
<p>You may now close this window and return to the application</p>
111-
</div>
112-
</body>
113-
</html>
114-
"""
115-
11628

11729
class AuthRestServlet(RestServlet):
11830
"""
@@ -145,26 +57,30 @@ def __init__(self, hs):
14557
self._cas_server_url = hs.config.cas_server_url
14658
self._cas_service_url = hs.config.cas_service_url
14759

60+
self.recaptcha_template = hs.config.recaptcha_template
61+
self.terms_template = hs.config.terms_template
62+
self.success_template = hs.config.fallback_success_template
63+
14864
async def on_GET(self, request, stagetype):
14965
session = parse_string(request, "session")
15066
if not session:
15167
raise SynapseError(400, "No session supplied")
15268

15369
if stagetype == LoginType.RECAPTCHA:
154-
html = RECAPTCHA_TEMPLATE % {
155-
"session": session,
156-
"myurl": "%s/r0/auth/%s/fallback/web"
70+
html = self.recaptcha_template.render(
71+
session=session,
72+
myurl="%s/r0/auth/%s/fallback/web"
15773
% (CLIENT_API_PREFIX, LoginType.RECAPTCHA),
158-
"sitekey": self.hs.config.recaptcha_public_key,
159-
}
74+
sitekey=self.hs.config.recaptcha_public_key,
75+
)
16076
elif stagetype == LoginType.TERMS:
161-
html = TERMS_TEMPLATE % {
162-
"session": session,
163-
"terms_url": "%s_matrix/consent?v=%s"
77+
html = self.terms_template.render(
78+
session=session,
79+
terms_url="%s_matrix/consent?v=%s"
16480
% (self.hs.config.public_baseurl, self.hs.config.user_consent_version),
165-
"myurl": "%s/r0/auth/%s/fallback/web"
81+
myurl="%s/r0/auth/%s/fallback/web"
16682
% (CLIENT_API_PREFIX, LoginType.TERMS),
167-
}
83+
)
16884

16985
elif stagetype == LoginType.SSO:
17086
# Display a confirmation page which prompts the user to
@@ -222,14 +138,14 @@ async def on_POST(self, request, stagetype):
222138
)
223139

224140
if success:
225-
html = SUCCESS_TEMPLATE
141+
html = self.success_template.render()
226142
else:
227-
html = RECAPTCHA_TEMPLATE % {
228-
"session": session,
229-
"myurl": "%s/r0/auth/%s/fallback/web"
143+
html = self.recaptcha_template.render(
144+
session=session,
145+
myurl="%s/r0/auth/%s/fallback/web"
230146
% (CLIENT_API_PREFIX, LoginType.RECAPTCHA),
231-
"sitekey": self.hs.config.recaptcha_public_key,
232-
}
147+
sitekey=self.hs.config.recaptcha_public_key,
148+
)
233149
elif stagetype == LoginType.TERMS:
234150
authdict = {"session": session}
235151

@@ -238,18 +154,18 @@ async def on_POST(self, request, stagetype):
238154
)
239155

240156
if success:
241-
html = SUCCESS_TEMPLATE
157+
html = self.success_template.render()
242158
else:
243-
html = TERMS_TEMPLATE % {
244-
"session": session,
245-
"terms_url": "%s_matrix/consent?v=%s"
159+
html = self.terms_template.render(
160+
session=session,
161+
terms_url="%s_matrix/consent?v=%s"
246162
% (
247163
self.hs.config.public_baseurl,
248164
self.hs.config.user_consent_version,
249165
),
250-
"myurl": "%s/r0/auth/%s/fallback/web"
166+
myurl="%s/r0/auth/%s/fallback/web"
251167
% (CLIENT_API_PREFIX, LoginType.TERMS),
252-
}
168+
)
253169
elif stagetype == LoginType.SSO:
254170
# The SSO fallback workflow should not post here,
255171
raise SynapseError(404, "Fallback SSO auth does not support POST requests.")

0 commit comments

Comments
 (0)