📄 attribute-value-checks
字号:
kses attribute value checks===========================As you've probably already read in the README file, an $allowed_html arraynormally looks like this:$allowed = array('b' => array(), 'i' => array(), 'a' => array('href' => 1, 'title' => 1), 'p' => array('align' => 1), 'br' => array());This sets what elements and attributes are allowed.From kses 0.2.0, you can also perform some checks on the attribute values. Youdo it like this:$allowed = array('b' => array(), 'i' => array(), 'a' => array('href' => array('maxlen' => 100), 'title' => 1), 'p' => array('align' => 1), 'font' => array('size' => array('maxval' => 20)), 'br' => array());This means that kses should perform the maxlen check with the value 100 on the<a href=> value, as well as the maxval check with the value 20 on the <fontsize=> value.The currently implemented checks (with more to come) are 'maxlen', 'maxval','minlen', 'minval' and 'valueless'.'maxlen' checks that the length of the attribute value is not greater than thegiven value. It is helpful against Buffer Overflows in WWW clients and variousservers on the Internet. In my example above, it would mean that"<a href='ftp://ftp.v1ct1m.com/AAAA..thousands_of_A's...'>" wouldn't beaccepted.Of course, this problem is even worse if you put that long URL in a <frame>tag instead, so the WWW client will fetch it automatically without a userhaving to click it.'maxval' checks that the attribute value is an integer greater than or equal tozero, that it doesn't have an unreasonable amount of zeroes or whitespace (toavoid Buffer Overflows), and that it is not greater than the given value. Inmy example above, it would mean that "<font size='20'>" is accepted but"<font size='21'>" is not. This check helps against Denial of Service attacksagainst WWW clients.One example of this DoS problem is <iframe src="http://some.web.server/"width="20000" height="2000">, which makes some client machines completelyoverloaded.'minlen' and 'minval' works the same as 'maxlen' and 'maxval', except that theycheck for minimum lengths and values instead of maximum ones.'valueless' checks if an attribute has a value (like <a href="blah">) or not(<option selected>). If the given value is a "y" or a "Y", the attribute mustnot have a value to be accepted. If the given value is an "n" or an "N", theattribute must have a value. Note that <a href=""> is considered to have avalue, so there's a difference between valueless attributes and attributevalues with the length zero.You can combine more than one check, by putting one after the other in theinner array.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -