Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Tweak AS registration check and AS component HTTP clients #1785

Merged
merged 11 commits into from
Mar 5, 2021

Conversation

neilalexander
Copy link
Contributor

@neilalexander neilalexander commented Mar 3, 2021

This tweaks the check for AS registration vs normal registration, since it seems that AS users are incorrectly being subjected to normal username checks (e.g. not being allowed to have usernames prefixed with _).

This also makes the following changes to the appservice component:

  • A new appservice client is used for appservice HTTP requests
  • A new DisableTLSValidation option has been added to the appservice config section for appservice traffic only

@neilalexander neilalexander changed the title Tweak AS registration check Tweak AS registration check and AS component HTTP clients Mar 4, 2021
setup/base.go Show resolved Hide resolved
@@ -33,7 +34,7 @@ const userIDExistsPath = "/users/"

// AppServiceQueryAPI is an implementation of api.AppServiceQueryAPI
type AppServiceQueryAPI struct {
HTTPClient *http.Client
HTTPClient *gomatrixserverlib.Client
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using this client instead of a normal one? GMSL.Client is for federation traffic only I thought? ASes do not get sent signed traffic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gomatrixserverlib.Client is for normal requests (like what the media API uses to fetch media), gomatrixserverlib.FederationClient is for signed requests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between GMSL.Client and net/http.Client?

Copy link
Contributor Author

@neilalexander neilalexander Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not much, mostly just that gomatrixserverlib.Client has all of the correct wiring already to give it a timeout and/or disable TLS validation without needing to reinvent the wheel again in the AS code.


if resErr = validateUsername(r.Username); resErr != nil {
return *resErr
if r.Auth.Type == authtypes.LoginTypeApplicationService || accessTokenErr == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer it if we only look at the access token if the login type is set to AS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that this isn't always the case. It's another one of those "spec is vague" things but Synapse also treats all calls to /register with an access_token as if they are coming from an AS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided with @Half-Shot to instead enforce authtypes.LoginTypeApplicationService only.

clientapi/routing/register.go Outdated Show resolved Hide resolved
@neilalexander
Copy link
Contributor Author

I need to fix the sytests again to send m.login.application_service as the auth type, so I will do that before merging.

@Half-Shot
Copy link
Contributor

I need to fix the sytests again to send m.login.application_service as the auth type, so I will do that before merging.

matrix-org/sytest#1018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants