sanitization

Are Cookies a Security Risk?

谁说胖子不能爱 提交于 2019-12-04 14:43:44
Assume we have a website that asks the user for his name. The website then stores this value in a cookie, and on the next page, retrieves it via PHP and uses it somehow (perhaps the page displays the name as text). Could a user modify the cookie data to inject malicious code? Should cookie data be sanitized as it's retrieved by the script? (This is a hypothetical scenario. Obviously a cookie wouldn't be necessary here.) Could a user modify the cookie data to inject malicious code? Should cookies be sanitized as they're retrieved by the script? Inject malicious code? Not PHP code, but you are

This regex to strip punctuation also incorrectly makes the word Báenou into Benou

旧街凉风 提交于 2019-12-04 11:07:03
The goal of this regex is to remove punctuation characters: var myTxt = "Welcome, Visitor: The Royal Kingdom Of Báenou"; myTxt = myTxt.replace(/[^a-zA-Z0-9 ]+/g, '').replace('/ {2,}/',' '); alert(myTxt); So the text above should become this: Welcome Visitor The Royal Kingdom Of Báenou But instead it incorrectly drops the á in Báenou to produce this: Welcome Visitor The Royal Kingdom Of Benou What's the simplest change I could make to the regex to make it work as intended? Your problem is that you are dropping anything that is not in a "whitelist" which you define as all (non-accented) letters,

CakePHP: h() vs. Sanitize::html()

懵懂的女人 提交于 2019-12-04 09:57:14
CakePHP has a global function called h . It's a convenience method for htmlspecialchars . CakePHP also has a utility called Sanitize , which has a method called html . Here is part of its description: This method prepares user-submitted data for display inside HTML. This is especially useful if you don’t want users to be able to break your layouts or insert images or scripts inside of your HTML pages. When should each be used? Is one better than the other? Costa Sanitize::html() is more versatile: it lets you strip the HTML completely (via remove option), and lets you specify the how it

Sanitize sentence in php

混江龙づ霸主 提交于 2019-12-04 08:50:09
问题 The title may sound odd, but im kind of trying to set up this preg_replace that takes care of messy writers for a textarea. It has to: if there is an exclamation sign, there should not be another one in a row. if there is a ., the comma wins and it has to be , when there is one+ spaces before a coma, it should be reduced to nothing. the sentence cannot start or end with a comma. there should never be more than 2 of the same letters joined together. a space must be always present after a comma

Can i manipulate an external HTML document with JQuery?

别来无恙 提交于 2019-12-04 06:32:37
问题 I would like to sanitize a HTML document (created in google docs) so I can publish it on my CMS. I have the source document in a string, from to , with header, style, body etc. I would like to extract the body content and replace/eliminate a few tags. If I could do this using jQuery I think it would be easier than with more sophisticated html parsers. But when I try to get the body of the document, I don't get usable results. I tried: var gdoc = "<html>...google document...</html>" $(gdoc) /

Data Sanitization in PHP [closed]

混江龙づ霸主 提交于 2019-12-04 05:40:18
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Can someone recommend an up to date library for data Sanitization in PHP ? I am looking for a library that proposes a set of functions for data sanitization. Email validation/sanitization (remove those %0A, \r...), strip htlm

Is there a better way to sanitize input with javascript?

隐身守侯 提交于 2019-12-04 04:58:35
I wanted to write a javascript function to sanitize user input and remove any unwanted and dangerous characters. It must allow only the following characters: Alfanumeric characters (case insentitive): [a-z][0-9]. Inner whitespace, like "word1 word2". Spanish characters (case insentitive): [áéíóúñü]. Underscore and hyphen [_-]. Dot and comma [.,]. Finally, the string must be trimmed with trim(). My first attempt was: function sanitizeString(str){ str = str.replace(/[^a-z0-9áéíóúñü_-\s\.,]/gim,""); return str.trim(); } But if I did: sanitizeString("word1\nword2") it returns: "word1 word2" So I

What is the correct way to make web form input safe for a variety of contexts?

旧时模样 提交于 2019-12-04 03:18:35
What do you all think is the correct (read: most flexible, loosely coupled, most robust, etc.) way to make user input from the web safe for use in various parts of a web application? Obviously we can just use the respective sanitization functions for each context (database, display on screen, save on disk, etc.), but is there some general "pattern" for handling unsafe data and making it safe? Is there an established way to enforce treating it as unsafe unless it is properly made safe? Like it's already been said, there are several things to take into account when you are concerned about web

Cleaning all inline events from HTML tags

扶醉桌前 提交于 2019-12-03 17:23:57
For HTML input, I want to neutralize all HTML elements that have inline js (onclick="..", onmouseout=".." etc). I am thinking, isn't it enough to encode the following chars? =,(,) So onclick="location.href='ggg.com'" will become onclick%3D"location.href%3D'ggg.com'" What am I missing here? Edit: I do need to accept active HTML (I can't escape it all or entities is it). Kornel There's no simple method to accept HTML, but not scripts. You have to parse HTML to DOM, remove all unwanted elements and attributes in DOM and generate new HTML. It can't be done reliably with regular expressions . on *

Sanitizing a Date

柔情痞子 提交于 2019-12-03 16:14:22
I am using a javascript date picker that allows the user to select a date. However, I would like to also sanitize the posted date data before entering into the database. I am not seeing any sanitize filter here: http://us2.php.net/manual/en/filter.filters.sanitize.php What would be the best method to sanitize a date before entering into a database? This would be the original value from the post: $datepick = $_POST['date']; // wich is 04/12/2014 Then I convert it for the database: $date = date("Y-m-d", strtotime($datepick)); Thanks! If your date is like "03/02/2014" then you can simply clean