getsentry / sentry-laravel

The official Laravel SDK for Sentry (sentry.io)
https://sentry.io
MIT License
1.25k stars 189 forks source link

reporting exceptions crashes on empty file inputs #701

Closed ddevigne closed 1 year ago

ddevigne commented 1 year ago

Environment

sentry 3.3 laravel 10.8

Steps to Reproduce

1) Create a form containing a file input 2) Create a controller that receives the form data 3) In the controller, throw an exception 4) Send you form with no file attached

Expected Result

Sentry should render and report the exception properly.

Actual Result

Sentry crashes when formatting the report.

The error is causes by the global $_FILES that contains empty "full_path".

RuntimeException:
Path cannot be empty

  at /var/www/html/project/vendor/nyholm/psr7/src/Factory/Psr17Factory.php:41
  at Nyholm\Psr7\Factory\Psr17Factory->createStreamFromFile()
     (/var/www/html/project/vendor/php-http/discovery/src/Psr17Factory.php:124)
  at Http\Discovery\Psr17Factory->createStreamFromFile()
     (/var/www/html/project/vendor/php-http/discovery/src/Psr17Factory.php:271)
  at Http\Discovery\Psr17Factory->normalizeFiles()
     (/var/www/html/project/vendor/php-http/discovery/src/Psr17Factory.php:184)
  at Http\Discovery\Psr17Factory->buildServerRequestFromGlobals()
     (/var/www/html/project/vendor/php-http/discovery/src/Psr17Factory.php:106)
  at Http\Discovery\Psr17Factory->createServerRequestFromGlobals()
     (/var/www/html/project/vendor/sentry/sentry/src/Integration/RequestFetcher.php:25)
  at Sentry\Integration\RequestFetcher->fetchRequest()
     (/var/www/html/project/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/LaravelRequestFetcher.php:32)
  at Sentry\Laravel\Http\LaravelRequestFetcher->fetchRequest()
     (/var/www/html/project/vendor/sentry/sentry/src/Integration/RequestIntegration.php:125)
  at Sentry\Integration\RequestIntegration->processEvent()
     (/var/www/html/project/vendor/sentry/sentry/src/Integration/RequestIntegration.php:117)
  at Sentry\Integration\RequestIntegration->Sentry\Integration\{closure}()
     (/var/www/html/project/vendor/sentry/sentry/src/State/Scope.php:378)
  at Sentry\State\Scope->applyToEvent()
     (/var/www/html/project/vendor/sentry/sentry/src/Client.php:292)
  at Sentry\Client->prepareEvent()
     (/var/www/html/project/vendor/sentry/sentry/src/Client.php:169)
  at Sentry\Client->captureEvent()
     (/var/www/html/project/vendor/sentry/sentry/src/Client.php:161)
  at Sentry\Client->captureException()
     (/var/www/html/project/vendor/sentry/sentry/src/State/Hub.php:138)
  at Sentry\State\Hub->captureException()
     (/var/www/html/project/vendor/sentry/sentry-laravel/src/Sentry/Laravel/SentryHandler.php:221)
  at Sentry\Laravel\SentryHandler->Sentry\Laravel\{closure}()
     (/var/www/html/project/vendor/sentry/sentry/src/State/Hub.php:93)
  at Sentry\State\Hub->withScope()
     (/var/www/html/project/vendor/sentry/sentry-laravel/src/Sentry/Laravel/SentryHandler.php:229)
  at Sentry\Laravel\SentryHandler->doWrite()
     (/var/www/html/project/vendor/sentry/sentry/src/Monolog/CompatibilityProcessingHandlerTrait.php:30)
  at Sentry\Laravel\SentryHandler->write()
     (/var/www/html/project/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php:44)
  at Monolog\Handler\AbstractProcessingHandler->handle()
     (/var/www/html/project/vendor/monolog/monolog/src/Monolog/Logger.php:379)
  at Monolog\Logger->addRecord()
     (/var/www/html/project/vendor/monolog/monolog/src/Monolog/Logger.php:632)
  at Monolog\Logger->error()
     (/var/www/html/project/vendor/laravel/framework/src/Illuminate/Log/Logger.php:186)
  at Illuminate\Log\Logger->writeLog()
     (/var/www/html/project/vendor/laravel/framework/src/Illuminate/Log/Logger.php:97)
  at Illuminate\Log\Logger->error()
     (/var/www/html/project/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:667)
  at Illuminate\Log\LogManager->error()
     (/var/www/html/project/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php:274)
  at Illuminate\Foundation\Exceptions\Handler->report()
     (/var/www/html/project/app/Exceptions/Handler.php:66)
  at App\Exceptions\Handler->report()
     (/var/www/html/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:491)
  at Illuminate\Foundation\Http\Kernel->reportException()
     (/var/www/html/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:146)
  at Illuminate\Foundation\Http\Kernel->handle()
     (/var/www/html/project/public/index.php:59)
cleptric commented 1 year ago

Can you please give the complete list of the dependencies you use? Via composer info.

ddevigne commented 1 year ago
# composer info
aws/aws-crt-php                      v1.2.1             AWS Common Runtime for PHP
aws/aws-sdk-php                      3.269.5            AWS SDK for PHP - Use Amazon Web Services in your PHP project
brick/math                           0.11.0             Arbitrary-precision arithmetic library
clue/stream-filter                   v1.6.0             A simple and modern approach to stream filtering in PHP
dflydev/dot-access-data              v3.0.2             Given a deep data structure, access data by dot notation.
doctrine/cache                       2.2.0              PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb ...
doctrine/dbal                        3.6.2              Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
doctrine/deprecations                v1.0.0             A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for pa...
doctrine/event-manager               2.0.0              The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.
doctrine/inflector                   2.0.6              PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms...
doctrine/lexer                       3.0.0              PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
dragonmantank/cron-expression        v3.3.2             CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due
egulias/email-validator              4.0.1              A library for validating emails against several RFCs
filp/whoops                          2.15.2             php error handling for cool kids
fruitcake/php-cors                   v1.2.0             Cross-origin resource sharing library for the Symfony HttpFoundation
fzaninotto/faker                     v1.5.0             Faker is a PHP library that generates fake data for you.
graham-campbell/result-type          v1.1.1             An Implementation Of The Result Type
guzzlehttp/guzzle                    7.5.1              Guzzle is a PHP HTTP client library
guzzlehttp/promises                  1.5.2              Guzzle promises library
guzzlehttp/psr7                      2.5.0              PSR-7 message implementation that also provides common utility methods
guzzlehttp/uri-template              v1.0.1             A polyfill class for uri_template of PHP
hamcrest/hamcrest-php                v2.0.1             This is the PHP port of Hamcrest Matchers
http-interop/http-factory-guzzle     1.2.0              An HTTP Factory using Guzzle PSR7
jean85/pretty-package-versions       2.0.5              A library to get pretty versions strings of installed dependencies
laravel/framework                    v10.8.0            The Laravel Framework.
laravel/serializable-closure         v1.3.0             Laravel Serializable Closure provides an easy and secure way to serialize closures in PHP.
laravel/tinker                       v2.8.1             Powerful REPL for the Laravel framework.
laravel/ui                           v4.2.1             Laravel UI utilities and presets.
league/commonmark                    2.4.0              Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and GitHub-Flavored Markdown (GFM)
league/config                        v1.2.0             Define configuration arrays with strict schemas and access values with dot notation
league/flysystem                     3.14.0             File storage abstraction for PHP
league/flysystem-aws-s3-v3           3.15.0             AWS S3 filesystem adapter for Flysystem.
league/flysystem-path-prefixing      3.15.0             Path prefixing filesystem adapter for Flysystem.
league/mime-type-detection           1.11.0             Mime-type detection for Flysystem
mockery/mockery                      1.5.1              Mockery is a simple yet flexible PHP mock object framework
monolog/monolog                      3.3.1              Sends your logs to files, sockets, inboxes, databases and various web services
mtdowling/jmespath.php               2.6.1              Declaratively specify how to extract elements from a JSON document
myclabs/deep-copy                    1.11.1             Create deep copies (clones) of your objects
nesbot/carbon                        2.66.0             An API extension for DateTime that supports 281 different languages.
nette/schema                         v1.2.3             📐 Nette Schema: validating data structures against a given Schema.
nette/utils                          v4.0.0             🛠  Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug ...
nikic/php-parser                     v4.15.4            A PHP parser written in PHP
nunomaduro/termwind                  v1.15.1            Its like Tailwind CSS, but for the console.
nyholm/psr7                          1.7.0              A fast PHP7 implementation of PSR-7
phar-io/manifest                     2.0.3              Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                      3.2.1              Library for handling version information and constraints
php-http/client-common               2.6.1              Common HTTP Client implementations and tools for HTTPlug
php-http/discovery                   1.15.3             Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations
php-http/httplug                     2.4.0              HTTPlug, the HTTP client abstraction for PHP
php-http/message                     1.14.0             HTTP Message related tools
php-http/message-factory             1.1.0              Factory interfaces for PSR-7 HTTP Message
php-http/promise                     1.1.0              Promise used for asynchronous HTTP requests
phpoption/phpoption                  1.9.1              Option Type for PHP
phpunit/php-code-coverage            10.1.1             Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator            4.0.1              FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-invoker                  4.0.0              Invoke callables with a timeout
phpunit/php-text-template            3.0.0              Simple template engine.
phpunit/php-timer                    6.0.0              Utility class for timing
phpunit/phpunit                      10.1.1             The PHP Unit Testing framework.
prestashop/prestashop-webservice-lib dev-master 94feb5f PrestaShop Webservice access library
psr/cache                            3.0.0              Common interface for caching libraries
psr/container                        2.0.2              Common Container Interface (PHP FIG PSR-11)
psr/event-dispatcher                 1.0.0              Standard interfaces for event handling.
psr/http-client                      1.0.2              Common interface for HTTP clients
psr/http-factory                     1.0.2              Common interfaces for PSR-7 HTTP message factories
psr/http-message                     1.1                Common interface for HTTP messages
psr/log                              3.0.0              Common interface for logging libraries
psr/simple-cache                     3.0.0              Common interfaces for simple caching
psy/psysh                            v0.11.15           An interactive shell for modern PHP.
ralouphie/getallheaders              3.0.3              A polyfill for getallheaders.
ramsey/collection                    2.0.0              A PHP library for representing and manipulating collections.
ramsey/uuid                          4.7.4              A PHP library for generating and working with universally unique identifiers (UUIDs).
sebastian/cli-parser                 2.0.0              Library for parsing CLI options
sebastian/code-unit                  2.0.0              Collection of value objects that represent the PHP code units
sebastian/code-unit-reverse-lookup   3.0.0              Looks up which function or method a line of code belongs to
sebastian/comparator                 5.0.0              Provides the functionality to compare PHP values for equality
sebastian/complexity                 3.0.0              Library for calculating the complexity of PHP code units
sebastian/diff                       5.0.1              Diff implementation
sebastian/environment                6.0.1              Provides functionality to handle HHVM/PHP environments
sebastian/exporter                   5.0.0              Provides the functionality to export PHP variables for visualization
sebastian/global-state               6.0.0              Snapshotting of global state
sebastian/lines-of-code              2.0.0              Library for counting the lines of code in PHP source code
sebastian/object-enumerator          5.0.0              Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector           3.0.0              Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context          5.0.0              Provides functionality to recursively process PHP variables
sebastian/type                       4.0.0              Collection of value objects that represent the types of the PHP type system
sebastian/version                    4.0.1              Library that helps with managing the version number of Git-hosted PHP projects
sentry/sdk                           3.3.0              This is a metapackage shipping sentry/sentry with a recommended HTTP client.
sentry/sentry                        3.17.0             A PHP SDK for Sentry (http://sentry.io)
sentry/sentry-laravel                3.3.3              Laravel SDK for Sentry (https://sentry.io)
symfony/console                      v6.2.8             Eases the creation of beautiful and testable command line interfaces
symfony/css-selector                 v6.2.7             Converts CSS selectors to XPath expressions
symfony/deprecation-contracts        v3.2.1             A generic function and convention to trigger deprecation notices
symfony/error-handler                v6.2.9             Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher             v6.2.8             Provides tools that allow your application components to communicate with each other by dispatching events and listening to them
symfony/event-dispatcher-contracts   v3.2.1             Generic abstractions related to dispatching event
symfony/finder                       v6.2.7             Finds files and directories via an intuitive fluent interface
symfony/http-client                  v6.2.9             Provides powerful methods to fetch HTTP resources synchronously or asynchronously
symfony/http-client-contracts        v3.2.1             Generic abstractions related to HTTP clients
symfony/http-foundation              v6.2.8             Defines an object-oriented layer for the HTTP specification
symfony/http-kernel                  v6.2.9             Provides a structured process for converting a Request into a Response
symfony/mailer                       v6.2.8             Helps sending emails
symfony/mime                         v6.2.7             Allows manipulating MIME messages
symfony/options-resolver             v6.2.7             Provides an improved replacement for the array_replace PHP function
symfony/polyfill-ctype               v1.27.0            Symfony polyfill for ctype functions
symfony/polyfill-intl-grapheme       v1.27.0            Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-idn            v1.27.0            Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer     v1.27.0            Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring            v1.27.0            Symfony polyfill for the Mbstring extension
symfony/polyfill-php72               v1.27.0            Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php80               v1.27.0            Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/polyfill-uuid                v1.27.0            Symfony polyfill for uuid functions
symfony/process                      v6.2.8             Executes commands in sub-processes
symfony/psr-http-message-bridge      v2.1.4             PSR HTTP message bridge
symfony/routing                      v6.2.8             Maps an HTTP request to a set of configuration variables
symfony/service-contracts            v3.2.1             Generic abstractions related to writing services
symfony/string                       v6.2.8             Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way
symfony/thanks                       v1.2.10            Encourages sending ⭐ and 💵 to fellow PHP package maintainers (not limited to Symfony components)!
symfony/translation                  v6.2.8             Provides tools to internationalize your application
symfony/translation-contracts        v3.2.1             Generic abstractions related to translation
symfony/uid                          v6.2.7             Provides an object-oriented API to generate and represent UIDs
symfony/var-dumper                   v6.2.8             Provides mechanisms for walking through any arbitrary PHP variable
theseer/tokenizer                    1.2.1              A small library for converting tokenized PHP source code into XML and potentially other formats
tijsverkoyen/css-to-inline-styles    2.2.6              CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful ...
vlucas/phpdotenv                     v5.5.0             Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.
voku/portable-ascii                  2.0.1              Portable ASCII library - performance optimized (ascii) string functions for php.
webmozart/assert                     1.11.0             Assertions to validate method input/output with nice error messages.
cleptric commented 1 year ago

Please run composer update sentry/sentry-laravel -W to update all underlying dependencies of the SDK. php-http/discovery, for example, had a fix in 1.17.0 concerning file uploads.

ddevigne commented 1 year ago

It works indeed. 👍 Thanks a lot.

cleptric commented 1 year ago

Glad to hear that, thanks! 🚀