which is the preferred approach to disinfect user input?
Thank you!
The best approach is to either use stored procedures or parameterized queries. The white list is an additional technique that allows you to prevent any injection before they reach the server, but should not be used as your main protection. A black ad is usually bad because it is usually not possible to filter out all malicious entries.
, , , sql.
WL - BL, .
: , , , , . , , , !
, - , HTML . , symfony 1.x :
class ContactForm extends sfForm { protected static $subjects = array('Subject A', 'Subject B', 'Subject C'); public function configure() { $this->setWidgets(array( 'name' => new sfWidgetFormInput(), 'email' => new sfWidgetFormInput(), 'subject' => new sfWidgetFormSelect(array('choices' => self::$subjects)), 'message' => new sfWidgetFormTextarea(), )); $this->widgetSchema->setNameFormat('contact[%s]'); $this->setValidators(array( 'name' => new sfValidatorString(array('required' => false)), 'email' => new sfValidatorEmail(), 'subject' => new sfValidatorChoice(array('choices' => array_keys(self::$subjects))), 'message' => new sfValidatorString(array('min_length' => 4)), )); } }
, , . , . . , , , ...
:
class ContactController { /** * @input("name", type = "string", singleLine = true, required = false) * @input("email", type = "email") * @input("subject", type = "string", alternatives = ['Subject A', 'Subject B', 'Subject C']) * @input("message", type = "string", range = [4,]) */ public function post(Inputs $inputs){ //automatically validates inputs //throws error when an input is not on the list //throws error when an input has invalid value } } /** * @controller(ContactController) * @method(post) */ class ContactForm extends sfFormX { public function configure(InputsMeta $inputs) { //automatically binds the form to the input list of the @controller.@method //throws error when the @controller.@method.@input is not defined for a widget $this->addWidgets( new sfWidgetFormInput($inputs->name), new sfWidgetFormInput($inputs->email), new sfWidgetFormSelect($inputs->subject), new sfWidgetFormTextarea($inputs->message) ); $this->widgetSchema->setNameFormat('contact[%s]'); } }
. , , . . , - "", , .
, , , :) @posterBelow
.
VS
. Blacklist XSS SQL Injection . , .
II. " XSS" " SQL-" . / / , .
?
. . , . , , ?
II. - . , , - . , - . - , .
. , , , . , .
, , , , , , , , , - , . , . , , , OWASP "Sanitize with Blacklist":
(, HTML ), "". , . , , , .
, - . XSS "Escape", , , , HTML- , , , , , XSS-. SQL- , , . . , , . , db "", . , , , :
OWASP
OWASP SQL
, , .
(, ) , .
. , , (escape- ..). , - , , .
I think this is just a case of finding a mixture that works for you. I can not come up with a single solution that would work for all the possibilities. It mainly depends on your user base.
Source: https://habr.com/ru/post/1761375/More articles:Php symfony exception handling / error handling - phpHow to enable gzip compression on coldfusion at the directory level? - coldfusionIntegration Testing a ViewModel that invokes WCF services asynchronously in an MVF MVPF application - asynchronousError 109 when stopping Mongo DB running as a service (1.6.1) - mongodbКак определить или определить ориентацию жест щепотки с помощью UIPinchGestureRecognizer? - iphoneif I want to add CSS, where would I paste it? - javascriptImplicit list of all build jobs in SCONS? - c ++HTML5 и CSS - пользовательские теги? - html5Using Service Broker with Sql Server Express 2008 - sql-server-expressIframe css scrollbar - javascriptAll Articles