Skip to content
This repository has been archived by the owner on Dec 2, 2021. It is now read-only.

Added exception for localhost domain #57

Merged
merged 1 commit into from Jul 26, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion Security/TwoFactor/Trusted/TrustedCookieManager.php
Expand Up @@ -101,8 +101,14 @@ public function createTrustedCookie(Request $request, $user)
// Add token to user entity
$this->trustedComputerManager->addTrustedComputer($user, $token, $validUntil);

$domain = null;
$requestHost = $request->getHost();
if ($requestHost !== 'localhost') {
$domain = '.' . $requestHost;
}

// Create cookie
return new Cookie($this->cookieName, $tokenList, $validUntil, '/', '.' . $request->getHost(), $this->cookieSecure);
return new Cookie($this->cookieName, $tokenList, $validUntil, '/', $domain, $this->cookieSecure);
}

/**
Expand Down
14 changes: 14 additions & 0 deletions Tests/Security/TwoFactor/Trusted/TrustedCookieManagerTest.php
Expand Up @@ -5,6 +5,7 @@
use Scheb\TwoFactorBundle\Security\TwoFactor\Trusted\TrustedCookieManager;
use Symfony\Component\HttpFoundation\Cookie;
use Scheb\TwoFactorBundle\Tests\TestCase;
use Symfony\Component\HttpFoundation\Request;

class TrustedCookieManagerTest extends TestCase
{
Expand Down Expand Up @@ -186,6 +187,19 @@ public function createTrustedCookie_newTrustedToken_persistUserEntity()

$this->cookieManager->createTrustedCookie($request, $user);
}

/**
* @test
*/
public function createTrustedCookie_localhostSkippedInCookie()
{
$request = Request::create('');
$user = $this->createMock('Scheb\TwoFactorBundle\Model\TrustedComputerInterface');

$cookie = $this->cookieManager->createTrustedCookie($request, $user);

$this->assertNull($cookie->getDomain());
}
}

/**
Expand Down