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

Disabling 3pid changes still sends validation email #12277

Closed
SPiRiT369 opened this issue Mar 23, 2022 · 6 comments · Fixed by #14725
Closed

Disabling 3pid changes still sends validation email #12277

SPiRiT369 opened this issue Mar 23, 2022 · 6 comments · Fixed by #14725
Labels
good first issue Good for newcomers S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. Z-Help-Wanted We know exactly how to fix this issue, and would be grateful for any contribution

Comments

@SPiRiT369
Copy link

I want to disable removing/adding email addresses, but only allow this during registration.

Reproduce the bug with:

  • Set enable_3pid_changes: false on configuration file.
  • On client side (e.g. Element Web) - try to add another email address to your account.
  • Synapse will send you a verification mail.
  • Go back to client side to proceed with adding the verified email.
  • You'll only then receive:
    image

Synapse should deny the request at start, and not send verification email.

@anoadragon453
Copy link
Member

The process of adding an email during registration is:

  1. Request an email via POST /_matrix/client/v3/register/email/requestToken.
  2. Verify that email by navigating via your browser to a URL provided by the homeserver.
  3. Send a request to POST /_matrix/client/v3/register to complete the registration.

For adding an email to your account after it's already been created, the process is:

  1. Request an email via POST /_matrix/client/v3/account/3pid/email/requestToken (notice the difference in path)
  2. Verify that email by navigating via your browser to a URL provided by the homeserver.
  3. Send a request to POST /_matrix/client/v3/account/3pid/add.

Currently the check behind enable_3pid_changes is employed in step 3 of adding an email to your account. I don't see a problem with additionally adding the check to step 1 as well. This would prevent an email from being sent out, and would not affect registration (or password resets).

@anoadragon453 anoadragon453 added Z-Help-Wanted We know exactly how to fix this issue, and would be grateful for any contribution S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. good first issue Good for newcomers labels Mar 25, 2022
@santhoshivan23
Copy link
Contributor

@anoadragon453 I guess the check already exists in step 1.

This is the POST handler for the endpoint account/3pid/email/requestToken

    async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
        if self.config.email.threepid_behaviour_email == ThreepidBehaviour.OFF:
            if self.config.email.local_threepid_handling_disabled_due_to_email_config:
                logger.warning(
                    "Adding emails have been disabled due to lack of an email config"
                )
            raise SynapseError(
                400, "Adding an email to your account is disabled on this server"
            )

@a-0-dev
Copy link

a-0-dev commented Dec 1, 2022

I would like to bump this issue as it is causing some usability questions in my institution as well. The two relevant points in synapse code are:

async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
("step 1", as far as I can see the check is not performed in this function)

async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
("step 3", here the check is performed)

If it somehow helps with the process I can of course post some merge request, but I assume since it's such a minor change it's easier for you (synapse devs) to just change it yourself (?)

Anyways, thanks for your great work!

JeyRathnam added a commit to JeyRathnam/synapse that referenced this issue Dec 16, 2022
@JeyRathnam
Copy link
Contributor

Would the fix for this issue be to send back http code 400 and message : "3PID changes are disabled on this server" when enable_3pid_changes is set to false? If so, I have a draft PR, need a bit of help fixing up test case.

Test case: tests.rest.client.test_account.ThreepidEmailRestTestCase.test_add_email_if_disabled calls _request_token

session_id = self._request_token(self.email, client_secret)

_request_token() checks for http status code 200 (OK) and fails as the change would return 400 now

if channel.code != expect_code:

@squahtx
Copy link
Contributor

squahtx commented Dec 19, 2022

Would the fix for this issue be to send back http code 400 and message : "3PID changes are disabled on this server" when enable_3pid_changes is set to false? If so, I have a draft PR, need a bit of help fixing up test case.

Yes, that's the fix proposed by anoadragon453 in #12277 (comment).

@JeyRathnam
Copy link
Contributor

I have PR #14682 ready for review.

DMRobertson pushed a commit that referenced this issue Jan 9, 2023
* Fixes #12277 :Disable sending confirmation email when 3pid is disabled

* Fix test_add_email_if_disabled test case to reflect changes to enable_3pid_changes flag

* Add changelog file

* Rename newsfragment.

Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. Z-Help-Wanted We know exactly how to fix this issue, and would be grateful for any contribution
Projects
None yet
6 participants