Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laminas Diactoros Laravel Package

laminas/laminas-diactoros

PSR-7 HTTP message implementation (ServerRequest, Request, Response, Stream, UploadedFile, Uri) for PHP. Includes factories and utilities for creating and normalizing requests/responses, with strong type coverage and interoperability with PSR-17/PSR-15.

View on GitHub
Deep Wiki
Context7

Security Features

ServerRequestFilterInterface defaults

Laminas\Diactoros\ServerRequestFilter\FilterServerRequestInterface is used by ServerRequestFactory::fromGlobals() to allow modifying the generated ServerRequest instance prior to returning it. The primary use case is to allow modifying the generated URI based on the presence of headers such as X-Forwarded-Host. When operating behind a reverse proxy, the Host header is often rewritten to the name of the node to which the request is being forwarded, and an X-Forwarded-Host header is generated with the original Host value to allow the server to determine the original host the request was intended for. We also similarly examine the X-Forwarded-Port header.

To accommodate this use case, we provide Laminas\Diactoros\ServerRequestFilter\FilterUsingXForwardedHeaders.

Due to potential security issues, it is generally best to only accept these headers if you trust the reverse proxy that has initiated the request. (This value is found in $_SERVER['REMOTE_ADDR'], which is present as $request->getServerParams()['REMOTE_ADDR'] within PSR-7 implementations.) FilterUsingXForwardedHeaders provides named constructors to allow you to trust these headers from any source (which has been the default behavior of Diactoros since the beginning), or to specify specific IP addresses or CIDR subnets to trust, along with which headers are trusted. We use this filter by default, marked to trust only proxies on private subnets.

If you do not need the functionality, we recommend specifying Laminas\Diactoros\ServerRequestFilter\DoNotFilter as the configured FilterServerRequestInterface in your application.

Filtering of integer header names

PSR-7 targets RFC 7230. RFC-7230 defines an ABNF pattern for header field names that allows the possibility of using an integer as a header field; e.g.,

1234: header value

The PSR-7, Psr\Http\MessageInterface::getHeaders() method requires implementations to return an associative array, where the key is the header field name. This triggers an interesting quirk in PHP: when adding an element to an array with a string key that consists of an integer value, PHP will convert this key to an integer (see PHP bug 80309 for more details). This presents several issues:

  • First, it means that consumers cannot depend on the header field name returned being a string.
  • Second, our own validation of header field name will fail, as it will not see a string.

Normally, this will not present an issue, as the way to add headers to a message is via the MessageInterface::withHeader() and MessageInterface::withAddedHeader() methods, which both require a string name argument. However, when using Laminas\Diactoros\ServerRequestFactory::fromGlobals(), it can present a problem if any discovered headers have field names that evaluate to integers.

To prevent issues, as of version 3.0.0, the ServerRequestFactory implementation in Diactoros filters out any headers that evaluate to integers. If you wish to accept these anyways, we strongly recommend that you modify your web server to rewrite the incoming header field name to add a prefix or suffix string (e.g., X-Digit-1, 1-Digit).

NOTE: Integer keys can still be returned from getHeaders() While withHeader() and withHeaderLine() require string name values, please be aware that these can be presented as string integers. These names will be considered valid, and that means that when you call getHeaders(), any such names will become integers at this time.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport