04. marts 2007 - 00:39
Der er
5 kommentarer
Tagwall beskyttes mod scripthacks
Hejsa jeg arbejder på en tagwall, som virker efter hensigten, men har opdaget at folk kan smide javascripts ol. som redirecter til en anden side når tags indlæses og vises. hvordan beskytter jeg min tagwall imod at eksekvere scripts ol. i beskeder osv.? skal det fanges før save i DB eller forhindres i indlæsningen?
Annonceindlæg fra SoftwareOne
04. marts 2007 - 00:43
#1
her er min tagwall.php kode: <html> <head> <meta http-equiv="Content-Language" content="da"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Tagwall</title> <link rel="stylesheet" type="text/css" href="../style.css"> </head> <body topmargin="1" leftmargin="1" rightmargin="1" bottommargin="1" marginwidth="1" marginheight="1"> <?php session_start(); $ANTAL_POSTER = 5; $DB_NAVN = "*******"; $DB_PASS = "********"; $COUNTquery = "SELECT count(*) FROM `tagwall`"; $GETquery = "SELECT * FROM `tagwall` ORDER BY ID DESC"; if ( !( $database = mysql_connect( "localhost",$DB_NAVN,$DB_PASS))) die( "Could not connect to database"); if ( !mysql_select_db( "grothconsult_dk", $database )) die( "Could not open Guestbook database"); if ( !($tags_COUNT = mysql_query( $COUNTquery, $database ))){ print( "Could not execute query! fejl i count... <br />"); die( mysql_error() ); } if ( !( $tags = mysql_query( $GETquery, $database ))){ print( "Could not execute query! ikke fundet nogen tags... <br />"); die( mysql_error() ); } if(!mysql_close()) { print( "Kunne ikke lukke forbindelsen til MySQL!"); } $GUIcount = mysql_num_rows($tags); ?> <div align="center"> <table width="100%" id="table2" cellspacing="1" style="border-collapse: collapse"> <tr> <td> <form method="POST" action="index.php?side=5"> <p align="center"> <select name="SIDE" style="font-family: Arial; color: #000000; font-weight: bold; font-size: 10pt" size="1" > <? $valgtSide = $HTTP_POST_VARS['SIDE']; if($valgtSide < 1){ $valgtSide = 1; } $boxItem = 1; while($GUIcount>0){ if($boxItem==1){ $boxNumber = 1; } else{ $boxNumber++; } if($valgtSIDE == $boxItem){ echo '<option selected value="'.$boxItem.'">'.$boxNumber.'</option>'; } else{ echo '<option value="'.$boxItem.'">'.$boxNumber.'</option>'; } $GUIcount = $GUIcount-$ANTAL_POSTER; $boxItem++; } ?> </select><input type="image" src="sider/PHPtagwall/taggui/side.gif" value="Vis.." name="B1" width="100" height="20"> <a target="_self" href="index.php?side=8"><img border="0" src="sider/PHPtagwall/taggui/opret.gif" width="100" height="20"></a></font></a></p> </form> </td> </tr> </table> <p></div> <? $gui_counter = 0; if($valgtSide==1){ $tal_1 = 0; $tal_2 = $tal_1+$ANTAL_POSTER-1; } else{ $tal_1 = $valgtSide*$ANTAL_POSTER-$ANTAL_POSTER; $tal_2 = $tal_1+$ANTAL_POSTER-1; } $tal2_1 = $tal_1+1; $tal2_2 = $tal_2+1; echo '<div align="center"><b><font size="2">Side '.$valgtSide.'</font></b><div/>'; while($row = mysql_fetch_row( $tags )){ if($gui_counter>=$tal_1&&$gui_counter<=$tal_2){ $txt = $row[6]; $txt = ereg_replace(':D', '<img src="sider/PHPtagwall/smileys/bigsmile.gif">', $txt); $txt = ereg_replace('B-)', '<img src="sider/PHPtagwall/smileys/angry.jpg">', $txt); $txt = ereg_replace('9-P', '<img src="sider/PHPtagwall/smileys/arrgh.jpg">', $txt); $txt = ereg_replace('blush', '<img src="sider/PHPtagwall/smileys/blush.gif">', $txt); $txt = ereg_replace('\?D', '<img src="sider/PHPtagwall/smileys/boy.gif">', $txt); $txt = ereg_replace(';S', '<img src="sider/PHPtagwall/smileys/diss.jpg">', $txt); $txt = ereg_replace('DOH', '<img src="sider/PHPtagwall/smileys/doh.gif">', $txt); $txt = ereg_replace(':\)', '<img src="sider/PHPtagwall/smileys/ey.jpg">', $txt); $txt = ereg_replace('F-U', '<img src="sider/PHPtagwall/smileys/fuck.bmp">', $txt); $txt = ereg_replace('B\(', '<img src="sider/PHPtagwall/smileys/gal.jpg">', $txt); $txt = ereg_replace('hmmmm', '<img src="sider/PHPtagwall/smileys/hmm.jpg">', $txt); $txt = ereg_replace('J\?', '<img src="sider/PHPtagwall/smileys/jay.gif">', $txt); $txt = ereg_replace(':x', '<img src="sider/PHPtagwall/smileys/kiss.jpg">', $txt); $txt = ereg_replace(':L', '<img src="sider/PHPtagwall/smileys/loser.bmp">', $txt); $txt = ereg_replace('LOL', '<img src="sider/PHPtagwall/smileys/lol.gif">', $txt); $txt = ereg_replace('<3', '<img src="sider/PHPtagwall/smileys/love.gif">', $txt); $txt = ereg_replace('KK', '<img src="sider/PHPtagwall/smileys/ok.bmp">', $txt); $txt = ereg_replace(':\?', '<img src="sider/PHPtagwall/smileys/smokin.jpg">', $txt); $txt = ereg_replace(':\(', '<img src="sider/PHPtagwall/smileys/trist.gif">', $txt); $txt = ereg_replace('X-P', '<img src="sider/PHPtagwall/smileys/uii.jpg">', $txt); $txt = ereg_replace('ASS', '<img src="sider/PHPtagwall/smileys/ass.gif">', $txt); echo ' <div align="center">'; echo ' <table border="0" width="461" id="table5" style="border-collapse: collapse">'; echo ' <tr>'; echo ' <td height="51" background="sider/PHPtagwall/taggui/tag-top.jpg" valign="bottom" style="padding-left: 32">'; echo ' <table border="0" width="100%" id="table6" style="border-collapse: collapse" >'; echo ' <tr>'; echo ' <td width="320"><b>#'.$row[0].' - '.$row[2].' | '.$row[5].'</b></td>'; echo ' <td>'; echo ' <p align="right" style="padding-right: 10"><b><a target ="_blank" href="'.$row[4].'" >WWW</a> | <a href="mailto:'.$row[3].'">@</a></b></td>'; echo ' </tr>'; echo ' </table>'; echo ' </td>'; echo ' </tr>'; echo ' <tr>'; echo ' <td background="sider/PHPtagwall/taggui/tag-mid.jpg" height="24" style="padding-left: 32">'; echo ' <font color="#FF0000"><b>'.$row[1].'</b></font><br> '.$txt.'</td>'; echo ' </tr>'; echo ' <tr>'; echo ' <td background="sider/PHPtagwall/taggui/tag-bund.jpg" height="19"> </td>'; echo ' </tr>'; echo ' </table>'; echo ' </div>'; echo ' <br/>'; } $gui_counter++; } ?> </body> </html>
04. marts 2007 - 13:21
#2
Du kan godt fange det før du gememr, men som standard mener jeg man skal gemme alt i DB, og først ved output formatere/sortere Brug htmlentities(), f.eks. $txt = htmlentities($row[6]);