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

strip out mailto: from author email uri with wp_parse_url #229

Closed
wants to merge 5 commits into from

Conversation

dougbeal
Copy link

No description provided.

Copy link
Collaborator

@dshanske dshanske left a comment

Choose a reason for hiding this comment

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

WordPress has an is_email function. We probably should validate the output as an email address and if not, reject it.

@dougbeal
Copy link
Author

It doesn't look like the $author['url'] is validated either?
What should happen if $author['email'] isn't an address? Would it be valid to put in a URL to a email submission form?

@dshanske
Copy link
Collaborator

I agree, we should improve both.

@pfefferle
Copy link
Owner

pfefferle commented Oct 14, 2019

What if it has no mailto:? Does your change work for both cases?

@dougbeal
Copy link
Author

is_email has a warning: Does not grok i18n domains. Not RFC compliant.

I wrote quick test:

$strings = [
    "foo@snar.com",
    "foo+dir@snar.com",    
    "mailto:foo@snar.com",
    "mailto:foo+dir@snar.com",    
    "snar.com",
    "com",
    "https://snar.com/path/to/email/form"
];

$parse = "wp_parse_url";
if( ! function_exists( $parse ) ) {
    $parse = "parse_url";
}

$isemail = "is_email";
if( ! function_exists( $parse ) ) {
    $parse = "parse_url";
}
$validate = "filter_var";
if ( function_exists( "is_email" ) ) {
    $validate = "is_email";
}
echo "Using " . $parse . " and " . $validate . "\n";
foreach ($strings as $string)
{
    $email = $parse($string, PHP_URL_PATH );
    $valid = "n ";
    if( function_exists( "is_email" ) && is_email($email) ||
        filter_var($email, FILTER_VALIDATE_EMAIL) ) {
        $valid = "y ";
    } 
    echo $valid . $string . " -> " . $email  . "\n";
}

// Using parse_url and filter_var
// y foo@snar.com -> foo@snar.com
// y foo+dir@snar.com -> foo+dir@snar.com
// y mailto:foo@snar.com -> foo@snar.com
// y mailto:foo+dir@snar.com -> foo+dir@snar.com
// n snar.com -> snar.com
// n com -> com
// n https://snar.com/path/to/email/form -> /path/to/email/form

// Using wp_parse_url and is_email
// y foo@snar.com -> foo@snar.com
// y foo+dir@snar.com -> foo+dir@snar.com
// y mailto:foo@snar.com -> foo@snar.com
// y mailto:foo+dir@snar.com -> foo+dir@snar.com
// n snar.com -> snar.com
// n com -> com
// n https://snar.com/path/to/email/form -> /path/to/email/form

@dshanske
Copy link
Collaborator

We can use filter_var, I just think we should start validating urls and emails properly.

@dougbeal
Copy link
Author

I didn't look at filter_var details. What should the behavior be when it's an invalid email?

@dshanske
Copy link
Collaborator

It should not save the parameter

Douglas Beal added 2 commits October 19, 2019 09:44
unicode emails non available until PHP 7.1.0
requiresFILTER_FLAG_EMAIL_UNICODE (integer)
Accepts Unicode characters in the local part in "validate_email" filter. (Available as of PHP 7.1.0)
Copy link
Author

@dougbeal dougbeal left a comment

Choose a reason for hiding this comment

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

validate email with filter_var FILTER_VALIDATE_EMAIL. unicode emails will fail validation (requires PHP 7.1.0 to turn it on)

@dougbeal
Copy link
Author

I'm not convinced this is working right... do the tests cover any of this code?

@stale
Copy link

stale bot commented Apr 1, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Apr 1, 2022
@stale stale bot closed this Apr 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants