Skip to content

TypeError when Forwarded header is missing #42300

@infomaniac50

Description

@infomaniac50

Symfony version(s) affected: 5.3.5

Stack Trace

TypeError:
Argument 1 passed to str_contains() must be of the type string, null given, called in [REDACTED]/vendor/symfony/security-http/Firewall/ChannelListener.php on line 52

  at vendor/symfony/polyfill-php80/bootstrap.php:29
  at str_contains(null, 'proto=https')
     (vendor/symfony/security-http/Firewall/ChannelListener.php:52)
  at Symfony\Component\Security\Http\Firewall\ChannelListener->supports(object(Request))
     (vendor/symfony/security-bundle/Debug/WrappedLazyListener.php:38)
  at Symfony\Bundle\SecurityBundle\Debug\WrappedLazyListener->supports(object(Request))
     (vendor/symfony/security-bundle/Security/LazyFirewallContext.php:52)
  at Symfony\Bundle\SecurityBundle\Security\LazyFirewallContext->__invoke(object(RequestEvent))
     (vendor/symfony/security-bundle/Debug/TraceableFirewallListener.php:59)
  at Symfony\Bundle\SecurityBundle\Debug\TraceableFirewallListener->callListeners(object(RequestEvent), object(Generator))
     (vendor/symfony/security-http/Firewall.php:86)
  at Symfony\Component\Security\Http\Firewall->onKernelRequest(object(RequestEvent), 'kernel.request', object(TraceableEventDispatcher))
     (vendor/symfony/event-dispatcher/Debug/WrappedListener.php:117)
  at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(RequestEvent), 'kernel.request', object(TraceableEventDispatcher))
     (vendor/symfony/event-dispatcher/EventDispatcher.php:230)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.request', object(RequestEvent))
     (vendor/symfony/event-dispatcher/EventDispatcher.php:59)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch(object(RequestEvent), 'kernel.request')
     (vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:151)
  at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch(object(RequestEvent), 'kernel.request')
     (vendor/symfony/http-kernel/HttpKernel.php:133)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:79)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:199)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:37)
  at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run()
     (vendor/autoload_runtime.php:35)
  at require_once('[REDACTED]/vendor/autoload_runtime.php')
     (public/index.php:5)

Description
The PHP 8 polyfill for str_contains does not accept null in it's arguments. This problem has shown up in more than one place. e.g. #42290 and in

} elseif (str_contains($request->headers->get('Forwarded'), 'proto=https')) {

DumpDataCollector.php avoids the issue by checking for the existence of the header.

|| ($response->headers->has('Content-Type') && !str_contains($response->headers->get('Content-Type'), 'html'))

The solution is probably the same as #42290.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions