【问题标题】:Laravel 5 route get parameters SQLinjectionLaravel 5路由获取参数SQL注入
【发布时间】:2016-04-27 04:09:18
【问题描述】:

我有这样的路线

Route::get('/car-{travelType}/{cityFrom}-{cityTo}-{id}.html','ArticleController@getDetail')->name('articles_detail');

在我的控制器中,我捕获了这样的参数

public function getDetail($cityFrom, $cityTo, $id, Request $request)
{
    $article_detail = DB::select("CALL article_detail(?,?,?)", [$cityFrom,$cityTo,$id]);
    return $article_detail;
}

这可以正常工作,但是由于路由发送了原始参数,因此该查询会出现 sqlinjection 问题。

在 post 请求中,我可以捕获像 $request->input('some_fields') 这样的请求,laravel 会在屏幕后面保护我,但不能在 get 请求中。

我该如何解决这个问题?

【问题讨论】:

  • @LoganBailey 哦,这是真的。非常感谢,对不起,我在问之前没有测试过代码:(
  • 那些不是查询字符串变量它们是路由参数

标签: php laravel-5


【解决方案1】:

您也可以在 Get 请求中使用 $request->get('somefield')

www.site.com/page?somefield=value

在这种情况下,当你接受 $request->get('somefield') 它应该给你“价值”

所以在你的情况下:

www.site.com/page?travel-type=foo&city-from=berlin&city-to=munich&id=1

$request->get('travel-type'); // foo
$request->get('city-from');   // berlin
$request->get('city-to');     // munich
$request->get('id');          // 1

【讨论】:

  • 感谢您的帮助,但我的网址不是您的性能参数,就像site.com/some-thing/some-thing-1352.html$request->get('id') 不起作用
猜你喜欢
  • 1970-01-01
  • 2021-08-07
  • 2014-05-29
  • 2015-06-25
  • 1970-01-01
  • 2021-06-30
  • 2015-04-17
  • 2018-04-07
  • 2015-07-26
相关资源
最近更新 更多