When I try to enter
<script type="text/javascript" >
alert("hello");
</script>
in the comment box on my PHP page I do not get an alert box. I see the script in my text file, not on the webpage. For some reason the <script> isn't executing. I have active scripting and javascript enabled on all my browsers.
My PHP code:
<?php //CFPcomments.php
include_once 'CFPheader.php';
if (isset($_POST['content']))
{
$fp = fopen('comments.txt', 'a');
fwrite($fp, $_POST['content'] . "<br />");
fclose($fp);
}
echo nl2br(file_get_contents('comments.txt'));
echo <<<_END
<h3>Post comment</h3>
<form action='CFPcomments.php' method='post'>
<textarea name='content' rows ='3' cols='100'></textarea>
<br/>
<input type='submit' value='Post' />
</form>
_END;
?>
Strange. I got it to work, not sure why.
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
alert("hello");
</script>
</head>
<body>
</body>
</html>
When I type this in it seems to work
Anyone have any idea why???? Very confused.
window.alertis part of jQuery?XSSif you haven't already. Allowing comments to contain Javascript makes you immediately vulnerable to that kind of attack. Depending on the use case you may be okay with that.