Skip to content

Commit 1299ae0

Browse files
committed
HostedDomainException adjustments
- Use static constructor to preserve default constructors - Don't include user's hd/domain incase it contains XSS'able data
1 parent dbf1478 commit 1299ae0

File tree

2 files changed

+4
-32
lines changed

2 files changed

+4
-32
lines changed

src/Exception/HostedDomainException.php

+2-30
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,9 @@
77
*/
88
class HostedDomainException extends \Exception
99
{
10-
private $hostedDomainConfigured;
1110

12-
private $hostedDomainOfUser;
13-
14-
/**
15-
* HostedDomainException constructor.
16-
* @param string $hostedDomainConfigured
17-
* @param string|null $hostedDomainOfUser
18-
*/
19-
public function __construct($hostedDomainConfigured, $hostedDomainOfUser)
20-
{
21-
parent::__construct("Hosted domain mismatch '$hostedDomainOfUser' !== '$hostedDomainConfigured'");
22-
$this->hostedDomainConfigured = $hostedDomainConfigured;
23-
$this->hostedDomainOfUser = $hostedDomainOfUser;
24-
}
25-
26-
/**
27-
* The hosted domain configured for this provider.
28-
* @return string
29-
*/
30-
public function getHostedDomainConfigured()
31-
{
32-
return $this->hostedDomainConfigured;
33-
}
34-
35-
/**
36-
* The hosted domain of the user. Non G-Suite users do not have hosted domains
37-
* @return string|null
38-
*/
39-
public function getHostedDomainOfUser()
11+
public static function notMatchingDomain($configuredDomain)
4012
{
41-
return $this->hostedDomainOfUser;
13+
return new static("User is not part of domain '$configuredDomain''");
4214
}
4315
}

src/Provider/Google.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ protected function createResourceOwner(array $response, AccessToken $token)
127127
// Validate hosted domain incase the user edited the initial authorization code grant request
128128
if ($this->hostedDomain === '*') {
129129
if (empty($user->getHostedDomain())) {
130-
throw new HostedDomainException($this->hostedDomain, $user->getHostedDomain());
130+
throw HostedDomainException::notMatchingDomain($this->hostedDomain);
131131
}
132132
} elseif (!empty($this->hostedDomain) && $this->hostedDomain !== $user->getHostedDomain()) {
133-
throw new HostedDomainException($this->hostedDomain, $user->getHostedDomain());
133+
throw HostedDomainException::notMatchingDomain($this->hostedDomain);
134134
}
135135

136136
return $user;

0 commit comments

Comments
 (0)