sanitization

PHP: Is there any kind of sanitization I need for using _GET data?

人走茶凉 提交于 2019-12-01 13:04:40
For just regular use in my PHP code, that is. Not like I'm going to pass it to my queries or anything. If you pass them to SQL queries, you get an SQL injection If you use them to form file names, you get an arbitrary file reading vulnerability If you output them as-is to the user as a part of HTML page, you get an XSS vulnerability If you output them to a file, you may get a malformed file if it has some predetermined formatting If you're just comparing the value with a set of predefined values, you're fine. If you're converting it to a number, you're fine as long as any number works for you

How to sanitize form params for use with Searchlogic? [Rails]

三世轮回 提交于 2019-12-01 09:21:19
问题 Example form <% form_for @search do |f| %> <ul> <li> <%= f.label :item_number_equals, "Item number" %><br /> <%= f.text_field :item_number_equals %> </li> <li> <%= f.label :description_keywords, "Description" %><br /> <%= f.text_field :description_keywords %> </li> <li> <%= f.check_box :in_stock %> <%= f.label :in_stock, "In Stock?" %> </li> <li> <%= f.label :price_gte, "Price Min" %> <%= f.text_field :price_gte, :size => 3 %> <%= f.label :price_lte, "Max" %> <%= f.text_field :price_lte,

Sanitize <script> element contents

喜你入骨 提交于 2019-12-01 08:51:38
Say that I want to provide some data to my client (in the first response, with no latency) via a dynamic <script> element. <script><%= payload %></script> Say that payload is the string var data = '</script><script>alert("Muahahaha!")';</script> . An end tag ( </script> ) will allow users to inject arbitrary scripts into my page. How do I properly sanitize the contents of my script element? I figure I could change </script> to <\/script> and <!-- to <\!-- . Are there any other dangerous strings I need to escape? Is there a better way to provide this "cold start" data? Cody Gustafson Edited for

How do I make sure a file path is within a given subdirectory?

本小妞迷上赌 提交于 2019-12-01 07:35:30
I want to make sure a file path set via query string does not go outside of the desired subdirectory. Right now, I am checking that: The path does not start with " / ", to prevent the user from giving an absolute path. The path does not contain " .. ", to prevent the user from giving a path that is outside of the desired subdirectory. The path does not contain " : ", to prevent the use of a url (i.e. " http:// ", " ftp:// ", etc.). Should I ever run this script on a Windows server (not likely), this will also prevent absolute paths beginning with a drive specifier (i.e. " C:\ "). Note: I'm

Sanitize <script> element contents

余生颓废 提交于 2019-12-01 06:49:05
问题 Say that I want to provide some data to my client (in the first response, with no latency) via a dynamic <script> element. <script><%= payload %></script> Say that payload is the string var data = '</script><script>alert("Muahahaha!")';</script> . An end tag ( </script> ) will allow users to inject arbitrary scripts into my page. How do I properly sanitize the contents of my script element? I figure I could change </script> to <\/script> and <!-- to <\!-- . Are there any other dangerous

How do I make sure a file path is within a given subdirectory?

喜夏-厌秋 提交于 2019-12-01 05:35:28
问题 I want to make sure a file path set via query string does not go outside of the desired subdirectory. Right now, I am checking that: The path does not start with " / ", to prevent the user from giving an absolute path. The path does not contain " .. ", to prevent the user from giving a path that is outside of the desired subdirectory. The path does not contain " : ", to prevent the use of a url (i.e. " http:// ", " ftp:// ", etc.). Should I ever run this script on a Windows server (not likely

Why call mb_convert_encoding to sanitize text?

北战南征 提交于 2019-12-01 04:44:43
This is in reference to this (excellent) answer . He states that the best solution for escaping input in PHP is to call mb_convert_encoding followed by html_entities . But why exactly would you call mb_convert_encoding with the same to and from parameters (UTF8)? Excerpt from the original answer: Even if you use htmlspecialchars($string) outside of HTML tags, you are still vulnerable to multi-byte charset attack vectors. The most effective you can be is to use the a combination of mb_convert_encoding and htmlentities as follows. $str = mb_convert_encoding($str, 'UTF-8', 'UTF-8'); $str =

Modify input before validation on Laravel 5.1

穿精又带淫゛_ 提交于 2019-12-01 02:31:25
I'm trying to modify an user submitted input before validation success. I've followed this easy instructions , but when I test it on Laravel 5.1, It's not working. Am I doing something wrong? This is my Request class on SSHAM\Http\Requests\UserCreateRequest.php <?php namespace SSHAM\Http\Requests; use SSHAM\Http\Requests\Request; class UserCreateRequest extends Request { // Some stuff not related with this problem /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { // Only for debug $prova = $this->all(); echo "<pre>Inside Request - Before

PHP input sanitizer?

纵饮孤独 提交于 2019-11-30 23:05:11
What are some good PHP html (input) sanitizers? Preferably, if something is built in - I'd like to us that. UPDATE : Per the request, via comments, input should not allow HTML (and obviously prevent XSS & SQL Injection, etc). html purifier -> http://htmlpurifier.org/ I've always used PHP's addslashes() and stripslashes() functions, but I also just saw the built-in filter_var() function ( link ). Looks like there are quite a few built-in filters . If you want to run a query that use let's say $_GET['user'] a nice solution would be to do something like this using mysql_real_escape_string() : <

Sanitizing MySQL user parameters

匆匆过客 提交于 2019-11-30 22:13:13
What are the dangerous characters that should be replaced in user input when the users' input will be inserted in a MySQL query? I know about quotes, double quotes, \r and \n. Are there others? (I don't have the option of using a smart connector that accepts parameters so I have to build the query myself and this will be implemented in multiple programming languages, including some obscure ones so solutions such as mysql_real_escape_string in PHP are not valid) mysql_real_escape_string() from mysql.com docs: The string in from is encoded to an escaped SQL string, taking into account the