lukeraymonddowning / honey

A spam prevention package for Laravel, providing honeypot techniques, ip blocking and beautifully simple Recaptcha integration. Stop spam. Use Honey.
MIT License
409 stars 23 forks source link

fix: Handling DecryptException in JavascriptInputValue #65

Closed mohamedary closed 9 months ago

mohamedary commented 1 year ago

Sometimes a Illuminate\Contracts\Encryption\DecryptException is being thrown when trying to decrypt the $value being passed to checkValue.

Therefore, I have handled the exception. Nothing special just returning false if that exception is thrown so that we don't crash the application for no reason.

Here is the stack trace of the error

Illuminate\Contracts\Encryption\DecryptException The payload is invalid. 
    vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:214 Illuminate\Encryption\Encrypter::getJsonPayload
    vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:151 Illuminate\Encryption\Encrypter::decrypt
    vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:353 Illuminate\Support\Facades\Facade::__callStatic
    vendor/lukeraymonddowning/honey/src/InputValues/JavascriptInputValue.php:18 Lukeraymonddowning\Honey\InputValues\JavascriptInputValue::checkValue
    vendor/lukeraymonddowning/honey/src/Checks/JavascriptInputFilledCheck.php:32 Lukeraymonddowning\Honey\Checks\JavascriptInputFilledCheck::Lukeraymonddowning\Honey\Checks\{closure}
    vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:738 rescue
    vendor/lukeraymonddowning/honey/src/Checks/JavascriptInputFilledCheck.php:32 Lukeraymonddowning\Honey\Checks\JavascriptInputFilledCheck::hasExpectedValue
    vendor/lukeraymonddowning/honey/src/Checks/JavascriptInputFilledCheck.php:21 Lukeraymonddowning\Honey\Checks\JavascriptInputFilledCheck::passes
    vendor/laravel/framework/src/Illuminate/Collections/HigherOrderCollectionProxy.php:60 Illuminate\Support\HigherOrderCollectionProxy::Illuminate\Support\{closure}
    [internal] array_map
    vendor/laravel/framework/src/Illuminate/Collections/Arr.php:558 Illuminate\Support\Arr::map
    vendor/laravel/framework/src/Illuminate/Collections/Collection.php:777 Illuminate\Support\Collection::map
    vendor/laravel/framework/src/Illuminate/Collections/HigherOrderCollectionProxy.php:61 Illuminate\Support\HigherOrderCollectionProxy::__call
    vendor/lukeraymonddowning/honey/src/Honey.php:61 Lukeraymonddowning\Honey\Honey::check
    vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:353 Illuminate\Support\Facades\Facade::__callStatic
    vendor/lukeraymonddowning/honey/src/Http/Middleware/PreventSpam.php:14 Lukeraymonddowning\Honey\Http\Middleware\PreventSpam::handle

Also, mentioned here https://github.com/lukeraymonddowning/honey/issues/39

lukeraymonddowning commented 9 months ago

Sorry for the delay on this.