I have a Laravel app that is getting a reasonable amount of traffic.
To more gracefully handle exceptions of the TokenMismatchException type (which tend to get thrown when the session lifetime expires and then a user submits a form), I have altered the render() method of the exception handler, as follows:
/**
* Render an exception into an HTTP response.
*
* #param \Illuminate\Http\Request $request
* #param \Exception $e
* #return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof \Illuminate\Session\TokenMismatchException){
return redirect($request->fullUrl())->with('error',"Sorry your session has expired please resubmit your request.");
}
return parent::render($request, $e);
}
This is working fine for normal requests, and instead of throwing the exception, it sets a session flash message and redirects back to the requested page. However, I'm noticing lots of these exceptions still being thrown for the following request:
/autodiscover/autodiscover.xml
I'm aware the above is something to do with Exchange, so it's probably not malicious.
What I'm confused about is a) why is this unrouted url triggering Laravel's CSRF protection and b) why is my updated handler not catching the exception?
I've tried adding a route for this url, and manually throwing a 404, but this hasn't helped.
What can I do to prevent these exceptions being thrown?
Edit - stack trace as requested:
2015-10-26 11:44:38] production.ERROR: exception 'Illuminate\Session\TokenMismatchException' in /var/www/vhosts/sitedomain.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:53
Stack trace:
#0 [internal function]: Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#1 /var/www/vhosts/sitedomain.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#2 /var/www/vhosts/sitedomain.com/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(54): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#3 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#4 /var/www/vhosts/sitedomain.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#5 /var/www/vhosts/sitedomain.com/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(62): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#6 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#7 /var/www/vhosts/sitedomain.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#8 /var/www/vhosts/sitedomain.com/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#9 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#10 /var/www/vhosts/sitedomain.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#11 /var/www/vhosts/sitedomain.com/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#12 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#13 /var/www/vhosts/sitedomain.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#14 /var/www/vhosts/sitedomain.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(42): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#15 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#16 /var/www/vhosts/sitedomain.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#17 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#18 /var/www/vhosts/sitedomain.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#19 /var/www/vhosts/sitedomain.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(122): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#20 /var/www/vhosts/sitedomain.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(87): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#21 /var/www/vhosts/sitedomain.com/public_html/index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#22 {main}
So, the solution turns out to be relatively simple. It seems like it's Laravel's default behaviour to handle all post (and presumably put and delete...) requests, whether they are defined in a route or not.
So we can add an exception to this in the VerifyCsrfToken middleware $except array:
protected $except = [
'autodiscover/autodiscover.xml'
]
After adding the above, my TokenMismatchException is no longer thrown.
Related
What seems to be the problem:
6 exceptions being logged with each upload (although the file gets uploaded)
Steps to Reproduce:
Follow the documentation page to create simple file upload
Try uploading a file
Check laravel log file
Laravel version: 5.7
Livewire version: 1.3.5
Laravel log sample:
[2021-01-21 11:05:07] local.ERROR: {"userId":47,"email":"user#example.com","exception":"[object] (Exception(code: 0): at /home/ameer/public_html/livewire.local/vendor/livewire/livewire/src/ComponentConcerns/HandlesActions.php:114)
[stacktrace]
#0 /home/ameer/public_html/livewire.local/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(755): Livewire\\Component->Livewire\\ComponentConcerns\\{closure}()
#1 /home/ameer/public_html/livewire.local/vendor/livewire/livewire/src/ComponentConcerns/HandlesActions.php(121): rescue(Object(Closure), Object(Closure), false)
#2 [internal function]: Livewire\\Component->Livewire\\ComponentConcerns\\{closure}(Object(ReflectionParameter), 0)
#3 /home/ameer/public_html/livewire.local/vendor/laravel/framework/src/Illuminate/Support/Collection.php(1034): array_map(Object(Closure), Array, Array)
#4 /home/ameer/public_html/livewire.local/vendor/livewire/livewire/src/ComponentConcerns/HandlesActions.php(122): Illuminate\\Support\\Collection->map(Object(Closure))
#5 /home/ameer/public_html/livewire.local/vendor/livewire/livewire/src/ComponentConcerns/HandlesActions.php(99): Livewire\\Component->resolveActionParameters('startUpload', Array)
#6 /home/ameer/public_html/livewire.local/vendor/livewire/livewire/src/Connection/ConnectionHandler.php(46): Livewire\\Component->callMethod('startUpload', Array)
...
After some debugging I found that the exception is caused by line #111 in vendor/livewire/livewire/src/ComponentConcerns/HandlesActions.php
I was able to work around the issue by overriding the resolveActionParameters method from the livewire component file.
Changed the method to simply return a collection of $params
protected function resolveActionParameters($method, $params)
{
return collect($params);
}
So far this has prevented the excesive logging of exceptions and didn't break any livewire functionality.
I am sending post data on this controller and for the sake of testing
i added die in execution method as you can see below in my code.
But I am getting strange error even I am not using any parameter in constructor
the error
1 exception(s):
Exception #0 (Exception): Recoverable Error: Argument 1 passed to
Magento\Framework\App\Action\Action::__construct() must be an instance of Magento\Framework\App\Action\Context, none given, called in C:\wamp64\www\PG\app\code\Webkul\Marketplace\Controller\Account\Saveareainfo.php on line 30 and defined in C:\wamp64\www\PG\vendor\magento\framework\App\Action\Action.php on line 67
Exception #0 (Exception): Recoverable Error: Argument 1 passed to Magento\Framework\App\Action\Action::__construct() must be an instance of Magento\Framework\App\Action\Context, none given, called in C:\wamp64\www\PG\app\code\Webkul\Marketplace\Controller\Account\Saveareainfo.php on line 30 and defined in C:\wamp64\www\PG\vendor\magento\framework\App\Action\Action.php on line 67
#0 C:\wamp64\www\PG\vendor\magento\framework\App\Action\Action.php(67): Magento\Framework\App\ErrorHandler->handler(4096, 'Argument 1 pass...', 'C:\\wamp64\\www\\P...', 67, Array)
#1 C:\wamp64\www\PG\app\code\Webkul\Marketplace\Controller\Account\Saveareainfo.php(30): Magento\Framework\App\Action\Action->__construct()
#2 C:\wamp64\www\PG\var\generation\Webkul\Marketplace\Controller\Account\Saveareainfo\Interceptor.php(14): Webkul\Marketplace\Controller\Account\Saveareainfo->__construct(Object(Magento\Framework\App\Action\Context))
#3 C:\wamp64\www\PG\vendor\magento\framework\ObjectManager\Factory\AbstractFactory.php(93): Webkul\Marketplace\Controller\Account\Saveareainfo\Interceptor->__construct(Object(Magento\Framework\App\Action\Context))
#4 C:\wamp64\www\PG\vendor\magento\framework\ObjectManager\Factory\Compiled.php(88): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('Webkul\\Marketpl...', Array)
#5 C:\wamp64\www\PG\vendor\magento\framework\ObjectManager\ObjectManager.php(57): Magento\Framework\ObjectManager\Factory\Compiled->create('Webkul\\Marketpl...', Array)
#6 C:\wamp64\www\PG\vendor\magento\framework\App\ActionFactory.php(40): Magento\Framework\ObjectManager\ObjectManager->create('Webkul\\Marketpl...')
#7 C:\wamp64\www\PG\vendor\magento\framework\App\Router\Base.php(300): Magento\Framework\App\ActionFactory->create('Webkul\\Marketpl...')
#8 C:\wamp64\www\PG\vendor\magento\framework\App\Router\Base.php(161): Magento\Framework\App\Router\Base->matchAction(Object(Magento\Framework\App\Request\Http), Array)
#9 C:\wamp64\www\PG\vendor\magento\framework\App\FrontController.php(50): Magento\Framework\App\Router\Base->match(Object(Magento\Framework\App\Request\Http))
#10 C:\wamp64\www\PG\vendor\magento\framework\Interception\Interceptor.php(74): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#11 C:\wamp64\www\PG\vendor\magento\framework\Interception\Chain\Chain.php(70): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#12 C:\wamp64\www\PG\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'requestPreproce...')
#13 C:\wamp64\www\PG\vendor\magento\module-store\App\FrontController\Plugin\RequestPreprocessor.php(94): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#14 C:\wamp64\www\PG\vendor\magento\framework\Interception\Chain\Chain.php(67): Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#15 C:\wamp64\www\PG\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'install')
#16 C:\wamp64\www\PG\vendor\magento\framework\Module\Plugin\DbStatusValidator.php(69): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#17 C:\wamp64\www\PG\vendor\magento\framework\Interception\Chain\Chain.php(67): Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#18 C:\wamp64\www\PG\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'front-controlle...')
#19 C:\wamp64\www\PG\vendor\magento\module-page-cache\Model\App\FrontController\BuiltinPlugin.php(68): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#20 C:\wamp64\www\PG\vendor\magento\framework\Interception\Chain\Chain.php(67): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#21 C:\wamp64\www\PG\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'front-controlle...')
#22 C:\wamp64\www\PG\vendor\magento\module-page-cache\Model\App\FrontController\VarnishPlugin.php(55): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#23 C:\wamp64\www\PG\vendor\magento\framework\Interception\Interceptor.php(142): Magento\PageCache\Model\App\FrontController\VarnishPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#24 C:\wamp64\www\PG\var\generation\Magento\Framework\App\FrontController\Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#25 C:\wamp64\www\PG\vendor\magento\framework\App\Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#26 C:\wamp64\www\PG\vendor\magento\framework\App\Bootstrap.php(258): Magento\Framework\App\Http->launch()
#27 C:\wamp64\www\PG\index.php(40): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#28 {main}
My code
<?php
/**
* Webkul Software.
*
* #category Webkul
* #package Webkul_Marketplace
* #author Webkul
* #copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https://webkul.com)
* #license https://store.webkul.com/license.html
*/
namespace Webkul\Marketplace\Controller\Account;
use Magento\Framework\App\Action\Action;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Data\Form\FormKey\Validator as FormKeyValidator;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Framework\App\RequestInterface;
/**
* Webkul Marketplace Account SaveAreaInfo Controller.
*/
class Saveareainfo extends Action
{
public function __construct()
{
parent::__construct();
}
public function execute()
{
die( " Hello Test .. " );
}
}
__construct() method must be an instance of Magento\Framework\App\Action\Context which was none given. It should be like
/**
* #param Context $context
*/
public function __construct(
Context $context
) {
parent::__construct($context);
}
Note: After deploying the module on remove the var/di and var/generation folders and recompile.
I have installed CRUD application in my CI.I am using Firebird database.The connection is fine while i am testing :
$res= $this->db->query('SELECT * FROM ADMIN_USER');
var_dump($res->row());
this is returning result.
but while i an using crud function:
public function admin()
{
try{
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('ADMIN_USER');
$crud->columns('USERNAME','PASSWORD');
$output = $crud->render();
var_dump($output);
$this->_example_output($output);
}catch(Exception $e){
show_error($e->getMessage().' --- '.$e->getTraceAsString());
}
}
no result is coming..and "500Internal Server Error" is showing in firebug..
The actual error shown:
An Error Was Encountered
The table name does not exist. Please check you database and try again. ---
#0 C:\wamp\www\anuncio\application\libraries\Grocery_CRUD.php(4420): Grocery_CRUD->get_table()
#1 C:\wamp\www\anuncio\application\libraries\Grocery_CRUD.php(4436): Grocery_CRUD->pre_render()
#2 C:\wamp\www\anuncio\application\controllers\examples.php(27): Grocery_CRUD->render()
#3 [internal function]: Examples->admin()
#4 C:\wamp\www\anuncio\system\core\CodeIgniter.php(359): call_user_func_array(Array, Array)
#5 C:\wamp\www\anuncio\index.php(202): require_once('C:\\wamp\\www\\anu...')
#6 {main}
I am new in CI, grocery CRUD and Firebird..Cant solve this error.Please help me.
Quite easy, your table does not exist. To be more specific, the table ADMIN_USER does not exist.
Whenever I am turning on the Developer mode in Magento 1.7 I am getting this warning message
If there is any other warning or error this there it will show that error
But when there is no error this screen is coming.
Once I turn off the developer mode i can use web site.
Warning: get_class() expects parameter 1 to be object, boolean given in >C:\xampp\htdocs\magento\app\code\core\Mage\Core\Model\App.php on line 1340
0 [internal function]: mageCoreErrorHandler(2, 'get_class() exp...', 'C:\xampp\htdocs...', >1340, Array) #1 C:\xampp\htdocs\magento\app\code\core\Mage\Core\Model\App.php(1340): >get_class(false) #2 C:\xampp\htdocs\magento\app\code\core\Mage\Core\Model\App.php(1317): >Mage_Core_Model_App->_callObserverMethod(false, 'check', Object(Varien_Event_Observer)) #3 >C:\xampp\htdocs\magento\app\Mage.php(447): Mage_Core_Model_App->dispatchEvent('controller_fron...', Array) #4 >C:\xampp\htdocs\magento\app\code\core\Mage\Core\Controller\Varien\Front.php(147): ?>Mage::dispatchEvent('controller_fron...', Array) #5 >C:\xampp\htdocs\magento\app\code\core\Mage\Core\Model\App.php(749): ?>Mage_Core_Controller_Varien_Front->init() #6 >C:\xampp\htdocs\magento\app\code\core\Mage\Core\Model\App.php(1094): Mage_Core_Model_App->_initFrontController() #7 >C:\xampp\htdocs\magento\app\code\core\Mage\Core\Model\App.php(354): Mage_Core_Model_App->getFrontController() #8 C:\xampp\htdocs\magento\app\Mage.php(683): Mage_Core_Model_App->run(Array) #9 C:\xampp\htdocs\magento\index.php(87): Mage::run('', 'store') #10 {main}
Any help or guidance would we appreciated.
You have a defunct observer; see Mage_Core_Model_App::_callObserverMethod() (link):
protected function _callObserverMethod($object, $method, $observer)
{
if (method_exists($object, $method)) {
$object->$method($observer);
} elseif (Mage::getIsDeveloperMode()) {
Mage::throwException('Method "'.$method.'" is not defined in "'.get_class($object).'"');
}
return $this;
}
From the rest of the stack trace it's possible to see that the event being observed is controller_front_init_routers (ref. Mage_Core_Controller_Varien_Front::init() (link)). Unless something has gone awry with Mage_Cms_Controller_Router (link), the issue must be with a custom module which is configured to observe this event.
To find the offending configuration, search in app/code for <controller_front_init_routers>.
You could also create a test script which does not invoke the Front Controller and use it to debug:
<?php
ini_set('display_errors',true);
error_reporting(E_ALL | E_STRICT);
include 'app/Mage.php';
Mage::setIsDeveloperMode(true);
Mage::app();
Zend_Debug::dump(
Mage::getConfig()->getXpath('//controller_front_init_routers//class')
);
Stock output would be as follows; anything else is your troublemaker:
array(1) {
[0] => object(Mage_Core_Model_Config_Element)#66 (1) {
[0] => string(26) "Mage_Cms_Controller_Router"
}
}
I am trying to write data to a table in the database. I finally set up my model but I can not write data to it.
I keep getting this error:
Invalid method Turnkeye_Adminform_Model_Mysql4_Iaso::beginTransaction(Array
(
)
)
Trace:
#0 E:\projects\magento\app\code\core\Mage\Core\Model\Abstract.php(313): Varien_Object->__call('beginTransactio...', Array)
#1 E:\projects\magento\app\code\core\Mage\Core\Model\Abstract.php(313): Turnkeye_Adminform_Model_Mysql4_Iaso->beginTransaction()
#2 E:\projects\magento\app\code\community\Turnkeye\Adminform\controllers\Adminhtml\AdminformController.php(47): Mage_Core_Model_Abstract->save()
#3 E:\projects\magento\app\code\core\Mage\Core\Controller\Varien\Action.php(420): Turnkeye_Adminform_Adminhtml_AdminformController->saveAction()
#4 E:\projects\magento\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('save')
#5 E:\projects\magento\app\code\core\Mage\Core\Controller\Varien\Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#6 E:\projects\magento\app\code\core\Mage\Core\Model\App.php(347): Mage_Core_Controller_Varien_Front->dispatch()
#7 E:\projects\magento\app\Mage.php(640): Mage_Core_Model_App->run(Array)
#8 E:\projects\magento\index.php(80): Mage::run('', 'store')
#9 {main}
Because of the amount of code I have posted it to pastebin:
controllers/Adminhtml/AdminformController.php
etc/config.xml
etc/adminhtml.xml
Model/iaso.php
Model/Mysql4/Iaso.php
This does not work because your code defines
Turnkeye_Adminform_Model_Mysql4_Iaso extends Mage_Core_Model_Abstract
which is wrong.
You need to extend from a resource model, that is from a class, which is extending the abstract class Mage_Core_Model_Resource_Abstract. That's where beginTransaction() is defined.
Usually this is done by extending from Mage_Core_Model_Mysql4_Abstract, because there are some more methods standard mySQL resources use in Magento and these are defined thru:
Mage_Core_Model_Mysql4_Abstract extends
Mage_Core_Model_Resource_Db_Abstract extends
Mage_Core_Model_Resource_Abstract
So changing your definition to
Turnkeye_Adminform_Model_Mysql4_Iaso extends Mage_Core_Model_Mysql4_Abstract
should bring you back on the right track.