HTML Injection

Importance of Front-End Validation

HTML Injection Overview

Risks of HTML Injection

Example: Basic Web Page Without Input Sanitization

HTML Source Code

<!DOCTYPE html>
<html>
<body>
    <button onclick="inputFunction()">Click to enter your name</button>
    <p id="output"></p>

    <script>
        function inputFunction() {
            var input = prompt("Please enter your name", "");
            
            if (input != null) {
                document.getElementById("output").innerHTML = "Your name is " + input;
            }
        }
    </script>
</body>
</html>

Pasted image 20250924140055.png|500

HTML Injection Payload Example

Payload

<style> body { background-image: url('https://academy.hackthebox.com/images/logo.svg'); } </style>

Effect

Mitigation Strategies


Exercise

Target: 94.237.122.123:39738

What text would be displayed on the page if we use the following payload as our input: <a href="http://www.hackthebox.com">Click Me</a>

Pasted image 20250924140456.png|500

flag: Your name is Click Me