Skip to content

Cookies from subdomains are ignored by the CookiePlugin #62

Closed
@andrewkharook

Description

@andrewkharook
Q A
Bug? yes
New Feature? no
Version 1.4.1

Actual Behavior

Cookie coming from the same domain but different subdomain is ignored.

Expected Behavior

The cookie for subdomain should be caught and saved to cookie jar (unless current behavior is what you have initially planned).
Or, at least we should provide a way for developer to choose if he wants to restrict cookies to single domain.

Steps to Reproduce

Imagine that initial request is made to www.example.com which tries to set cookie for all subdomains:
.example.com

Lines 71-74 will ignore that cookie, since strpos('.example.com', 'www.example.com') will return false:

// Restrict setting cookie from another domain
if (false === strpos($cookie->getDomain(), $request->getUri()->getHost())) {
    continue;
}

Possible Solutions

A quick and dirty solution would be to simply switch the arguments inside strpos(), like this:

// Restrict setting cookie from another domain
if (false === strpos($request->getUri()->getHost(), $cookie->getDomain())) {
    continue;
}

I can make a pull request with that change if you find it appropriate.

However, as I have said earlier, it would be better to let the developer decide whether to accept different domain cookies or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions