Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix maskEmail to handle subdomains correctly #301

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dockerbuild/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ set -e

./vendor/bin/phpunit -v tests/AnnouncementTest.php
./vendor/bin/phpunit -v vendor/simplesamlphp/simplesamlphp/modules/sildisco/tests/
./vendor/bin/phpunit -v vendor/simplesamlphp/simplesamlphp/modules/mfa/tests/

/data/run-integration-tests.sh
16 changes: 9 additions & 7 deletions modules/mfa/src/Auth/Process/Mfa.php
Original file line number Diff line number Diff line change
Expand Up @@ -912,14 +912,16 @@ public static function maskEmail(string $email): string
* Add an '*' for each of the characters of the domain, except
* for the first character of each part and the .
*/
list($domainA, $domainB) = explode('.', $domain);
$domainParts = explode('.', $domain);
$maskedDomain = '';

$newEmail .= substr($domainA, 0, 1);
$newEmail .= str_repeat('*', strlen($domainA) - 1);
$newEmail .= '.';

$newEmail .= substr($domainB, 0, 1);
$newEmail .= str_repeat('*', strlen($domainB) - 1);
foreach ($domainParts as $part) {
$firstCharacter = substr($part, 0, 1);
$maskedPart = $firstCharacter . str_repeat('*', max(strlen($part) - 1, 0));
$maskedDomain .= $maskedPart . '.';
}
$maskedDomain = rtrim($maskedDomain, '.');
$newEmail .= $maskedDomain;
return $newEmail;
}

Expand Down
25 changes: 25 additions & 0 deletions modules/mfa/tests/MfaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php


use PHPUnit\Framework\TestCase;
use SimpleSAML\Module\mfa\Auth\Process\Mfa;

class MfaTest extends TestCase
{
public static function setUpBeforeClass(): void
{
}

public function testMaskEmail()
{
$this->assertEquals("j**n@e******.c**", Mfa::maskEmail("[email protected]"));
$this->assertEquals("j***_s***h@e******.c**", Mfa::maskEmail("[email protected]"));
$this->assertEquals("t**t@t***.e******.c**", Mfa::maskEmail("[email protected]"));
$this->assertEquals("[email protected]*", Mfa::maskEmail("[email protected]"));

// just to be sure it doesn't throw an exception...
$this->assertEquals("t**t@e******..c**", Mfa::maskEmail("[email protected]"));
$this->assertEquals("@", Mfa::maskEmail("@"));
}

}
Loading