1
我的一個朋友發佈了一個關於如何防止使用DOM的xss攻擊的代碼。DOM並刪除標籤againnst xss攻擊的方式來優化它?
你對這段代碼有什麼看法? 我們可以優化它嗎?
<?php
function parseDoc(DOMDocument $codeHtml){
$forbiddenTag=array('script');
$forbiddenAttr=array('onmouseover','onmouseup','onclick');
foreach($forbiddenTag as $tag){
$liste=$codeHtml->getElementsByTagName($tag);
foreach($liste as $element){
$codeHtml->removeChild($element);
}
}
stripAttr($codeHtml,$forbiddenAttr);
}
function stripAttr(DOMNode $root, array $forbiddenAttr){
foreach($rootl->childNodes as $child){
foreach($forbiddenAttr as $attr){
if($child->hasAttribute($attr)) $child->removeAttribute($attr);
}.
if($child->hasChildNodes())strippAttr($child,$forbiddenAttr);
}
}
我們可以使用Dom_event()嗎? – Zeroth
@Zothoth我不知道這個名字的任何PHP函數。你能提供一個鏈接嗎? – phihag
對不起,它在這裏晚了,我沒有想好: http://en.wikipedia.org/wiki/DOM_Events – Zeroth