Script Problem!

Sn00pY
So nun frag ich hier auch an weil noch keine funktionierte lösung gibt hierfür:

php:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
<?php
$allowedTags = array('<h1>','<b>','<i>','<a>','<ul>','<li>','<pre>','<hr>','<blockquote>','<img>');
$stripAttrib = array('javascript','onclick','ondblclick','onmousedown','onmouseup','onmouseover','onmousemove','onmouseout','onkeypress','onkeydown','onkeyup','test');

function removeEvilTags($source)
{
   global $allowedTags,$stripAttrib;
   $source strip_tags($source$allowedTags);
   
    foreach($stripAttrib as $temp_stripAttrib){
            $source=preg_replace('/<(.*?)>/''<'.preg_replace('#a#is''forbidden','\\1').'>'$source);
        print "1 - $temp_stripAttrib, $source;<br>\n";
    }
   
   return $source;
}

echo removeEvilTags('<div align="center"><a href="javascript:alert(1);" target="_blank" onMouseOver = "alert(1)">test</a></div>');
?>


kann jemand helfen?

gruß
Lenox
Zitat:
Original von Sn00pY
So nun frag ich hier auch an weil noch keine funktionierte lösung gibt hierfür:

php:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
<?php
$allowedTags = array('<h1>','<b>','<i>','<a>','<ul>','<li>','<pre>','<hr>','<blockquote>','<img>');
$stripAttrib = array('javascript','onclick','ondblclick','onmousedown','onmouseup','onmouseover','onmousemove','onmouseout','onkeypress','onkeydown','onkeyup','test');

function removeEvilTags($source)
{
   global $allowedTags,$stripAttrib;
   $source strip_tags($source$allowedTags);
   
    foreach($stripAttrib as $temp_stripAttrib){
            $source=preg_replace('/<(.*?)>/''<'.preg_replace('#a#is''forbidden','\\1').'>'$source);
        print "1 - $temp_stripAttrib, $source;<br>\n";
    }
   
   return $source;
}

echo removeEvilTags('<div align="center"><a href="javascript:alert(1);" target="_blank" onMouseOver = "alert(1)">test</a></div>');
?>


kann jemand helfen?

gruß


Versuch das mal:

php:
1:
$allowedTags = array("<h1>","<b>","<i>","<a>","<ul>","<li>","<pre>","<hr>","<blockquote>","<img>");
Sn00pY
Parse error: syntax error, unexpected ',' in /www/htdocs/xxxx/beziehungskiste/text.php on line 7

zeile 7:
foreach($source, $allowedTags as $temp_allowedTags){

hab das jetzt mal gemacht:

php:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
<?php
$allowedTags "<h1> <b> <i> <a> <ul> <li> <pre> <hr> <blockquote> <img>";
$stripAttrib = array('javascript','onclick','ondblclick','onmousedown','onmouseup','onmouseover','onmousemove','onmouseout','onkeypress','onkeydown','onkeyup','test');

function removeEvilTags($source)
{
   global $allowedTags,$stripAttrib;
   $source strip_tags($source$allowedTags);
   
    foreach($stripAttrib as $temp_stripAttrib){
            $source=preg_replace('/<(.*?)>/''<forbidden>'$source);
        print "1 - ".$temp_stripAttrib."<u></u>, ".$source.";<br>\n";
    }
   
   return $source;
}

echo removeEvilTags('<div align="center"><a href="javascript:alert(1);" target="_blank" onMouseOver = "alert(1)">test</a></div>');
?>


folgendes kommt dabei raus:

1 - javascript, test;
1 - onclick, test;
1 - ondblclick, test;
1 - onmousedown, test;
1 - onmouseup, test;
1 - onmouseover, test;
1 - onmousemove, test;
1 - onmouseout, test;
1 - onkeypress, test;
1 - onkeydown, test;
1 - onkeyup, test;
1 - test, test;
test

Quelltext:

code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
1 - javascript<u></u>, <forbidden>test<forbidden>;<br>
1 - onclick<u></u>, <forbidden>test<forbidden>;<br>
1 - ondblclick<u></u>, <forbidden>test<forbidden>;<br>
1 - onmousedown<u></u>, <forbidden>test<forbidden>;<br>

1 - onmouseup<u></u>, <forbidden>test<forbidden>;<br>
1 - onmouseover<u></u>, <forbidden>test<forbidden>;<br>
1 - onmousemove<u></u>, <forbidden>test<forbidden>;<br>
1 - onmouseout<u></u>, <forbidden>test<forbidden>;<br>

1 - onkeypress<u></u>, <forbidden>test<forbidden>;<br>
1 - onkeydown<u></u>, <forbidden>test<forbidden>;<br>
1 - onkeyup<u></u>, <forbidden>test<forbidden>;<br>
1 - test<u></u>, <forbidden>test<forbidden>;<br>

<forbidden>test<forbidden>
xundy
Was hättest du denn gerne was da raus kommt?

mfg
Sn00pY
haben es hinbekommen smile
xundy
Zitat:
Original von Sn00pY
haben es hinbekommen smile


Na das wird wohl allen anderen nix helfen unglücklich

mfg