Skip to content
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

CorsService.php is appending 'Origin' to first vary header and chopping of rest of the vary header #105

Open
SunainaDutta14 opened this issue Sep 4, 2024 · 3 comments

Comments

@SunainaDutta14
Copy link

public function varyHeader(Response $response, $header): Response
    {
        if (!$response->headers->has('Vary')) {
            $response->headers->set('Vary', $header);
        } elseif (!in_array($header, explode(', ', $response->headers->get('Vary')))) {
            $response->headers->set('Vary', $response->headers->get('Vary') . ', ' . $header);
        }

        return $response;
    }
My response object has two vary header 'Cookie', 'Referer' but instead of appending 'Origin' at the end ,above code is adding  'Origin' after first vary header and rest of the vary headers are chopped off.

image
image
image

Sending third parameter 'FALSE' to set function will resolves the issue.
$response->headers->set('Vary', $header, FALSE);
Can someone please look into it and provide proper way to fix?
https://www.drupal.org/project/drupal/issues/3471642
I have raised an issue in Drupal as well.

@dpagini
Copy link

dpagini commented Sep 12, 2024

It appears to me that this is best demonstrated in the 2nd screenshot. Calling $response->headers->get('Vary') is returning ONLY the first header, "Cookie", and completely dropping "Referer". Line 216 is appending a new value. The expected headers at the end of this call are "Cookie,Referer,Origin", but instead the end result is "Cookie,Origin" (dropped Referer).

@dpagini
Copy link

dpagini commented Oct 11, 2024

I think that line 215 of CorsService.php assumes that $response->headers->get('Vary') returns a string, but it seems like it can return a string or an array.

@dpagini
Copy link

dpagini commented Oct 11, 2024

Ok, looking at this more... can this code just use the $response->setVary() method instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants