php 我需要清理用户输入 Laravel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26202682/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 18:13:51  来源:igfitidea点击:

Do I need to sanitize the user input Laravel

phplaraveleloquentxsssql-injection

提问by Fylux

I am using Laravel 4 with Eloquent. When I get the user input I just use $name=Input::get('name')and then I do $a->name=$name;

我正在将 Laravel 4 与 Eloquent 一起使用。当我得到用户输入时,我只是使用$name=Input::get('name')然后我做$a->name=$name;

I don't know if the function Input::getprotect me from SQL Injection and XSS. If it does not, what do I have to do to sanitize the input?

我不知道该功能是否可以Input::get保护我免受 SQL 注入和 XSS 的侵害。如果没有,我该怎么做才能清理输入?

And, when I show the value in my view, shall I use {{$a}}or {{{$a}}}

而且,当我在我看来显示价值时,我应该使用{{$a}}还是{{{$a}}}

Greetings and thanks.

问候和感谢。

回答by cha-cha

Laravel uses PDO's parameter binding, so SQL injection is not something you should worry about. You should read thisthough.

Laravel 使用 PDO 的参数绑定,所以 SQL 注入不是你应该担心的。你应该阅读这个

Input::get() does not filter anything.

Input::get() 不过滤任何东西。

Triple curly braces do the same as e() and HTML::entities(). All of them call htmlentities with UTF-8 support:

三花括号的作用与 e() 和 HTML::entities() 相同。它们都调用支持 UTF-8 的 htmlentities:

htmlentities($your_string, ENT_QUOTES, 'UTF-8', false);

回答by Marcin Nabia?ek

You should use {{{$a}}}because for example Input can has HTML tag. Laravel won't filter it.

您应该使用, {{{$a}}}因为例如 Input 可以有 HTML 标签。Laravel 不会过滤它。

To avoid SQL injection you should use bind your parameters running queries like:

为避免 SQL 注入,您应该使用绑定运行查询的参数,例如:

$var = 1;
$results = DB::select('select * from users where id = ?', array($var));

and not:

并不是:

$results = DB::select('select * from users where id = '.$var);

回答by M_R_K

You can use

您可以使用

https://github.com/Waavi/Sanitizer

https://github.com/Waavi/Sanitizer

It is vary solid easy to use library.

它是各种可靠的易于使用的库。