📄 readme
字号:
kses 0.2.1 README [kses strips evil scripts!]=================* INTRODUCTION *Welcome to kses - an HTML/XHTML filter written in PHP. It removes all unwantedHTML elements and attributes, no matter how malformed HTML input you give it.It also does several checks on attribute values. kses can be used to avoidCross-Site Scripting (XSS), Buffer Overflows and Denial of Service attacks,among other things.The program is released under the terms of the GNU General Public License. Youshould look into what that means, before using kses in your programs. You canfind the full text of the license in the file COPYING.* FEATURES *Some of kses' current features are:* It will only allow the HTML elements and attributes that it was explicitlytold to allow.* Element and attribute names are case-insensitive (a href vs A HREF).* It will understand and process whitespace correctly.* Attribute values can be surrounded with quotes, apostrophes or nothing.* It will accept valueless attributes with just names and no values (selected).* It will accept XHTML's closing " /" marks.* Attribute values that are surrounded with nothing will get quotes to avoidproducing non-W3C conforming HTML(<a href=http://sourceforge.net/projects/kses> works but isn't valid HTML).* It handles lots of types of malformed HTML, by interpreting the existingcode the best it can and then rebuilding new code from it. That's a betterapproach than trying to process existing code, as you're bound to forget aboutsome weird special case somewhere. It handles problems like never-endingquotes and tags gracefully.* It will remove additional "<" and ">" characters that people may try tosneak in somewhere.* It supports checking attribute values for minimum/maximum length andminimum/maximum value, to protect against Buffer Overflows and Denial ofService attacks against WWW clients and various servers. You can stop<iframe src= width= height=> from having too high values for width and height,for instance.* It has got a system for whitelisting URL protocols. You can say thatattribute values may only start with http:, https:, ftp: and gopher:, but noother URL protocols (javascript:, java:, about:, telnet:..). The functions thatdo this work handle whitespace, upper/lower case, HTML entities("javascript:") and repeated entries ("javascript:javascript:alert(57)").It also normalizes HTML entities as a nice side effect.* It removes Netscape 4's JavaScript entities ("&{alert(57)};").* It handles NULL bytes and Opera's chr(173) whitespace characters.* There is both a procedural version and an object-oriented version of kses.* USE IT *It's very easy to use kses in your own PHP web application! Basic usage lookslike this:<?phpinclude 'kses.php';$allowed = array('b' => array(), 'i' => array(), 'a' => array('href' => 1, 'title' => 1), 'p' => array('align' => 1), 'br' => array());$val = $_POST['val'];if (get_magic_quotes_gpc()) $val = stripslashes($val);# You must strip slashes from magic quotes, or kses will get confused.$val = kses($val, $allowed); # The filtering takes place here.# Do something with $val.?>This definition of $allowed means that only the elements B, I, A, P and BR areallowed (along with their closing tags /B, /I, /A, /P and /BR). B, I and BRmay not have any attributes. A may only have the attributes HREF and TITLE,while P may only have the attribute ALIGN. You can list the elements andattributes in the array in any mixture of upper and lower case. kses will alsorecognize HTML code that uses both lower and upper case.It's important to select the right allowed attributes, so you won't open upan XSS hole by mistake. Some important attributes that you mustn't allowinclude but are not limited to: 1) style, and 2) all intrinsic eventsattributes (onMouseOver and so on, on* really). I'll write more about this inthe documentation that will be distributed with future versions of kses.It's also important to note that kses' HTML input must be cleaned of allslashes coming from magic quotes. If the rest of your code requires theseslashes to be present, you can always add them again after calling kses witha simple addslashes() call.You should take a look at the documentation in the docs/ directory and theexamples in the examples/ directory, to get more information on how to usekses. The object-oriented version of kses is also worth checking out, and it'sincluded in the oop/ directory.* UPGRADING FROM 0.1.0 OR 0.2.0 TO 0.2.1 *kses 0.2.1 is backwards compatible with 0.1.0 and 0.2.0, so upgrading shouldjust be a matter of using a new version of kses.php instead of an old one!When you're ready to start using 0.2.1's new features, you can read about themin the files in the docs/ directory. The ChangeLog also summarizes the newfeatures in this release.* NEW VERSIONS, MAILING LISTS AND BUG REPORTS *If you want to download new versions, subscribe to the kses-general mailinglist or even take part in the development of kses, we refer you to itshomepage at http://sourceforge.net/projects/kses . New developers and betatesters are more than welcome!If you have any bug reports, suggestions for improvement or simply want to tellus that you use kses for some project, feel free to post to the kses-generalmailing list. If you have found any security problems (particularly XSS,naturally) in kses, please contact Ulf privately at metaur at users dotsourceforge dot net so he can correct it before you or someone else tells thepublic about it.(No, it's not a security problem in kses if some program that uses it allows abad attribute, silly. If kses is told to accept the element body with theattributes style and onLoad, it will accept them, even if that's a really badidea, securitywise.)* OTHER HTML FILTERS *Here are the other stand-alone, open source HTML filters that we currently knowof:* XSS filter for PHP4 - the filter from Squirrelmail PHP Konstantin Riabitsev http://www.mricon.com/html/phpfilter.html* HTML::StripScripts and related CPAN modules Perl Nick Cleaton http://search.cpan.org/perldoc?HTML%3A%3AStripScriptsThere are also a lot of HTML filters that were written specifically for someprogram. Some of them are better than others.Please write to the kses-general mailing list if you know of any otherstand-alone, open-source filters.* DEDICATION *kses 0.2.1 is dedicated to Mischa the cat.* MISC *The kses code is based on an HTML filter that Ulf wrote on his own back in 2002for the open-source project Gnuheter ( http://savannah.nongnu.org/projects/gnuheter ). Gnuheter is a fork from PHP-Nuke. The HTML filter has beenimproved a lot since then.To stop people from having sleepless nights, we feel the urgent need to statethat kses doesn't have anything to do with the KDE project, despite having aname that starts with a K.In case someone was wondering, Ulf is available for kses-related consulting.Finally, the name kses comes from the terms XSS and access. It's also arecursive acronym (every open-source project should have one!) for "ksesstrips evil scripts".// Ulf and the kses gang, September 2003
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -