普通网友 2013-06-26 20:34
浏览 118
已采纳

所有POST请求上的Laravel 4 CSRF

Been looking into laravel lately, and trying to figure out the CSRF protection that they have. However, i can't get it work. Is there any way i can validate all post request submitted, with the CSRF filter? I've seen that the laravel system has:

    App::before(function($request)
{
    //
});

How would i be able to use this with the CSRF filter? Been trying a few different things like

App::before(function($request)
{
    Route::filter('csrf','post');
});

But i'm probably way off here.. how would this work? or is it even possible doing it this way?

  • 写回答

7条回答 默认 最新

  • douwen1313 2013-06-27 00:02
    关注

    You can use route groups. This will apply the specified options to any routes defined in a group:

    Route::group(array('before' => 'csrf'), function()
    {
        Route::post('/', function()
        {
        // Has CSRF Filter
        });
    
        Route::post('user/profile', function()
        {
        // Has CSRF Filter
        });
    
        Route::post(....);
    });
    

    For certain routes, or if grouping isn't what you want, you can also use a pattern filter:

    //all routes beginning with admin, sent via a post http request will use the csrf filter
    Route::when('admin/*', 'csrf', array('post'));
    

    NOTE: this code would go in your routes.php file

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥15 cplex运行后参数报错是为什么
  • ¥15 之前不小心删了pycharm的文件,后面重新安装之后软件打不开了
  • ¥15 vue3获取动态宽度,刷新后动态宽度值为0
  • ¥15 升腾威讯云桌面V2.0.0摄像头问题
  • ¥15 关于Python的会计设计
  • ¥15 聚类分析 设计k-均值算法分类器,对一组二维模式向量进行分类。
  • ¥15 stm32c8t6工程,使用hal库
  • ¥15 找能接spark如图片的,可议价
  • ¥15 关于#单片机#的问题,请各位专家解答!
  • ¥15 博通raid 的写入速度很高也很低