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

Laminas-http mishandles multiple headers causing failure #43

Open
crscheid opened this issue Oct 25, 2021 · 2 comments
Open

Laminas-http mishandles multiple headers causing failure #43

crscheid opened this issue Oct 25, 2021 · 2 comments
Labels
Bug Something isn't working

Comments

@crscheid
Copy link

Bug Report

Q A
Version(s) 2.15.0

Summary

Header handling in the dependency for laminas/laminas-http has an error when it receives a header that it treats as a single string first followed by an array type header with the same data. Because the header has already been set like a string, the call to set it as an array fails.

I am fully aware that laminas/laminas-http is in security only support now which is why I'm posting the bug report to laminas-feed where the issue is manifesting. Laminas-Feed should be updated to use PSR-7 or the bug should be fixed.

Current behavior

When sending a request to an RSS feed that delivers the header twice, first as a string, then as an array, Laminas reports

PHP Error: [] operator not supported for strings in /var/www/vendor/laminas/laminas-http/src/Headers.php on line 454

How to reproduce

This occurs specifically when utilizing Google's news search to RSS feed approach. It returns two sets of Content-Security-Policy headers.

When set in the order of

require-trusted-types-for 'script';report-uri /_/DotsSplashUi/cspreport

followed by

script-src 'report-sample' 'nonce-e2kBBs8/LEHElepgO1hnkA' 'unsafe-inline'; object-src 'none'; base-uri 'self'; report-uri /_/DotsSplashUi/cspreport; worker-src 'self';

Laminas-http fails.

However, it does so inconsisently because the responding server does not always send the headers back in the same order. If the headers are sent back in the reverse order, the process succeeds, but actually overwrites the array header with the string header.

To reproduce, run this multiple times.

$url = 'https://news.google.com/rss/search?q=%22ecommerce%22+when%3A7d&hl=en-US&gl=US&ceid=US%3Aen';
$feed_result = \Laminas\Feed\Reader\Reader::import($feed_url);

Expected behavior

We should expect the headers to be assembled even if an array type is passed to the client after a string type.

@crscheid crscheid added the Bug Something isn't working label Oct 25, 2021
@crscheid crscheid changed the title PHP Error: [] operator not supported for strings in /var/www/vendor/laminas/laminas-http/src/Headers.php on line 454 Laminas-http mishandles multiple headers causing failure Oct 25, 2021
@froschdesign
Copy link
Member

@crscheid

Laminas-Feed should be updated to use PSR-7…

You can already use a PSR-7 client. Example:

Laminas\Feed\Reader\Reader::setHttpClient(
    new class implements Laminas\Feed\Reader\Http\ClientInterface {
        public function get($uri)
        {
            return new Laminas\Feed\Reader\Http\Psr7ResponseDecorator(
                (new GuzzleHttp\Client())->request('GET', $uri)
            );
        }
    }
);

$url  = 'https://news.google.com/rss/search?q=%22ecommerce%22+when%3A7d&hl=en-US&gl=US&ceid=US%3Aen';
$feed = Laminas\Feed\Reader\Reader::import($url);

echo $feed->getDescription(); // Google News

https://docs.laminas.dev/laminas-feed/psr7-clients/

When sending a request to an RSS feed that delivers the header twice, first as a string, then as an array, Laminas reports

PHP Error: [] operator not supported for strings in /var/www/vendor/laminas/laminas-http/src/Headers.php on line 454

Can you create a test and send it as a pull request? It seems that not all PHP versions are affected.
Thanks in advance! 👍

@crscheid
Copy link
Author

@froschdesign: Thanks for the feedback, I will check using PSR-7 ... more than happy to move beyond the deprecated dependency. Once I do so, let me see if this occurs further. If not, I will close this issue. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants