Skip to content

Cross subdomain cookie sharing issue #63

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

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Fixed

- `CookiePlugin` allows main domain cookies to be sent/stored for subdomains
- `DecoderPlugin` uses the right `FilteredStream` to handle `deflate` content encoding

## 1.4.1 - 2017-02-20
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/CookiePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
}

// Restrict setting cookie from another domain
if (false === strpos($cookie->getDomain(), $request->getUri()->getHost())) {
if (false === strpos($request->getUri()->getHost(), $cookie->getDomain())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this correct. what about symfony.slack.com setting the cookie and then we do a request to hacksymfony.slack.com? its an edge case, but i think we should be correct about this.

Copy link
Member

Choose a reason for hiding this comment

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

On the other hand, hack.symfony.slack.com should be correct again. Cookies.... 😕

Copy link
Contributor Author

@andrewkharook andrewkharook Mar 21, 2017

Choose a reason for hiding this comment

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

@dbu, @sagikazarmark:
What if we add a dot . to both cookie domain and request domain before the comparison?

strpos(
    '.'.$request->getUri()->getHost(),
    '.'.$cookie->getDomain()
)

Here's what's happening in this case:

strpos(
    '.hacksymfony.slack.com',
    '.symfony.slack.com'
); // no match, cookie ignored.

strpos(
    '.hack.symfony.slack.com',
    '.symfony.slack.com'
); // match, cookie used.

strpos(
    '.symfony.slack.com',
    '.symfony.slack.com'
); // match, cookie used.

I wonder if this workaround is appropriate and not counted as dirty code.

Copy link
Contributor

Choose a reason for hiding this comment

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

i think that is the right approach. afaik the server could send the leading . already, we should handle that properly as well, not that we end up with "..symfony.slack.com".

are you sure that cookies should propagate down several levels? like test.com cookie being sent to foo.bar.baz.test.com ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

afaik the server could send the leading . already, we should handle that properly as well, not that we end up with "..symfony.slack.com".

This is already handled by Http\Message\Cookie::normalizeDomain(), so we shouldn't care about it.

are you sure that cookies should propagate down several levels? like test.com cookie being sent to foo.bar.baz.test.com ?

Yes, that's what is said in RFC 6265. If Domain attribute is not specified, it defaults to the host portion of the current document location (but not including subdomains). If a domain is specified, subdomains are always included.

continue;
}

Expand Down