Page MenuHomePhabricator

Update ContactPage for IP masking
Open, HighPublic

Description

From @Tgr :

ContactPage has some logic to format messages from logged-in users and anons differently (e.g. username vs. IP). It should probably just treat temp users as logged-in.

Content-Transform-Team doesn't have a lot of experience with ContactPage, but from that spec we ought to be able to do this update.

Event Timeline

I debug Contact extension locally, and noticed that user's IP address is added to the email message title.
Here is the logic for adding IP address (link):

$includeIP = isset( $config['IncludeIP'] ) && $config['IncludeIP']
&& ( $user->isAnon() || $formData['IncludeIP'] );

Depending on temp user account type (whether it should be isAnon or has some specific role, see this discussion) the implementation of the code block above should be changed.

In general, IP addresses should still be sent (or at least forms should be configurable to allow IP addresses to be sent). This information is necessary for the Stewards IP block appeal and exemption workflow.

If I understand this correctly, the code as is appropriately reports the IP address in a contact page email and is/maybe needed to aid in an IP block appeal exemption, and as such removing the IP here is not correct nor appropriate as part of the ongoing IPMasking issue. Let me know if I should close this ticket, or let others comment/review.

In general, IP addresses should still be sent (or at least forms should be configurable to allow IP addresses to be sent). This information is necessary for the Stewards IP block appeal and exemption workflow.

		if ( $user->isRegistered() ) {
			// Use real name if set
			$realName = $user->getRealName();
			if ( $realName ) {
				$fromName = $realName;
			} else {
				$fromName = $user->getName();
			}
			$fromAddress = $user->getEmail();
		}

this should probably use !$user->isAnon().

		$includeIP = isset( $config['IncludeIP'] ) && $config['IncludeIP']
			&& ( $user->isAnon() || $formData['IncludeIP'] );

this is probably fine as it is, we don't want to send temp users' IPs by default.

I can apply this change, but without commenting out lines 132-135 in SpecialContact.php like this, I cannot ever reach line 164, so unless I am missing something, this code is currently unreachable, or I cannot create a test environment condition with a logged out browser to reach it as a temporary user, which also maybe a configuration I have not set correctly in my local wiki instance:

[line 131]		$recipient = User::newFromName( $config['RecipientUser'] );
//		if ( $recipient === null || !$recipient->canReceiveEmail() ) {
//			$this->getOutput()->showErrorPage( 'noemailtitle', 'noemailtext' );
//			return;
//		}
In T335962#8897361, @Tgr wrote (and Sbailey merged the change recommended):
[line 164]         if ( !$user->isAnon() ) { // Was if ( $user->isRegistered() )
			// Use real name if set
			$realName = $user->getRealName();
			if ( $realName ) {
				$fromName = $realName;
			} else {
				$fromName = $user->getName();
			}
			$fromAddress = $user->getEmail();
		}

I cannot ever reach line 164, so unless I am missing something

$recipient is user that's going to receive the email, as set in $wgContactConfig['default']['RecipientUser']. That needs to be a valid account on the wiki, with a verified email. You can set $wgEmailAuthentication = false; for the purpose of testing.

$user, on the other hand, is the sender, which can be logged out.

Change 926585 had a related patch set uploaded (by Sbailey; author: Sbailey):

[mediawiki/extensions/ContactPage@master] Do not display users IP as User Name in ContactPage for anonymous users

https://gerrit.wikimedia.org/r/926585

Thanks Arlo, also had to create a recipient account and fix the recipientUser string to match and then things worked.

The current code using isRegistered() but should be using isAnon() as Tgr pointed out and the patch I submitted changes that. I tested this as best I can with a local wiki and the email in this case does contain the the email header:
'Contact message testing ... (from Shannon at 127.0.0.1)'

I assume that on a production wiki, the users IP address included would not be localhost.

Dreamy_Jazz subscribed.
		if ( $user->isRegistered() ) {
			// Use real name if set
			$realName = $user->getRealName();
			if ( $realName ) {
				$fromName = $realName;
			} else {
				$fromName = $user->getName();
			}
			$fromAddress = $user->getEmail();
		}

this should probably use !$user->isAnon().

I'm not so sure about that, as temporary users cannot have preferences which means that they cannot have an email address and/or real name. Checking for whether the user is named makes more sense in this case to me.

I'm not so sure about that, as temporary users cannot have preferences which means that they cannot have an email address and/or name. Checking for whether the user is named makes more sense in this case to me.

But they do have a username, and that is how you want to identify them to the person reading the email.

I'm not so sure about that, as temporary users cannot have preferences which means that they cannot have an email address and/or name. Checking for whether the user is named makes more sense in this case to me.

But they do have a username, and that is how you want to identify them to the person reading the email.

Okay. I missed that the code also checks for the name (and not the real name).

Change 926585 abandoned by Sbailey:

[mediawiki/extensions/ContactPage@master] Corrects sending users IP in ContactPage for anonymous users

Reason:

https://gerrit.wikimedia.org/r/926585

MSantos triaged this task as High priority.Thu, Aug 15, 2:11 PM
MSantos moved this task from Blocked to Current Deploy Target on the Content-Transform-Team-WIP board.