Skip to content

Instantly share code, notes, and snippets.

@LIttleAncientForestKami
Created December 8, 2023 14:30
Show Gist options
  • Save LIttleAncientForestKami/6c1d140f987d4ae0fb39ddd28dd94ff5 to your computer and use it in GitHub Desktop.
Save LIttleAncientForestKami/6c1d140f987d4ae0fb39ddd28dd94ff5 to your computer and use it in GitHub Desktop.
Content Security Policy demo with XSS attack
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>XSS Demo</title>
<meta http-equiv="Content-Security-Policy" content="" />
</head>
<body>
<h1>XSS Demo</h1>
<form>
<label for="input">Enter your name:</label>
<input type="text" id="input" name="input" placeholder="<script>alert(1)</script>">
<button type="button" onclick="displayGreeting();">Submit</button>
</form>
<script>
function displayGreeting() {
var userInput = document.getElementById('input').value;
var greeting = 'Hello, ' + userInput + '!';
document.write('<p>' + greeting + '</p>');
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment