Skip to content

Commit f5103f0

Browse files
Andrew KharookAndrew Kharook
Andrew Kharook
authored and
Andrew Kharook
committed
#62 Adjust security check
1 parent 8a2dd2b commit f5103f0

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

spec/Plugin/CookiePluginSpec.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,25 @@ function it_does_not_load_cookie_if_domain_does_not_match(RequestInterface $requ
8484

8585
function it_does_not_load_cookie_on_hackish_domains(RequestInterface $request, UriInterface $uri, Promise $promise)
8686
{
87+
$hackishDomains = [
88+
'hacktest.com',
89+
'test.com.hacked.org',
90+
];
8791
$cookie = new Cookie('name', 'value', 86400, 'test.com');
8892
$this->cookieJar->addCookie($cookie);
8993

90-
$request->getUri()->willReturn($uri);
91-
$uri->getHost()->willReturn('hacktest.com');
94+
foreach ($hackishDomains as $domain) {
95+
$request->getUri()->willReturn($uri);
96+
$uri->getHost()->willReturn($domain);
9297

93-
$request->withAddedHeader('Cookie', 'name=value')->shouldNotBeCalled();
98+
$request->withAddedHeader('Cookie', 'name=value')->shouldNotBeCalled();
9499

95-
$this->handleRequest($request, function (RequestInterface $requestReceived) use ($request, $promise) {
96-
if (Argument::is($requestReceived)->scoreArgument($request->getWrappedObject())) {
97-
return $promise->getWrappedObject();
98-
}
99-
}, function () {});
100+
$this->handleRequest($request, function (RequestInterface $requestReceived) use ($request, $promise) {
101+
if (Argument::is($requestReceived)->scoreArgument($request->getWrappedObject())) {
102+
return $promise->getWrappedObject();
103+
}
104+
}, function () {});
105+
}
100106
}
101107

102108
function it_loads_cookie_on_subdomains(RequestInterface $request, UriInterface $uri, Promise $promise)

src/Plugin/CookiePlugin.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
6969
}
7070

7171
// Restrict setting cookie from another domain
72-
if (false === strpos(
73-
'.'.$request->getUri()->getHost(),
74-
'.'.$cookie->getDomain()
75-
)
76-
) {
72+
if (!preg_match("/\.{$cookie->getDomain()}$/", '.'.$request->getUri()->getHost())) {
7773
continue;
7874
}
7975

0 commit comments

Comments
 (0)