Looking for the vulnerability index of Invicti's legacy products?
HTML Injection - Vulnerability Database

HTML Injection

Description

HTML Injection occurs when an application fails to properly sanitize user-supplied input before rendering it in a web page, allowing attackers to inject arbitrary HTML markup. Unlike Cross-Site Scripting (XSS), which enables JavaScript execution, HTML Injection is limited to inserting HTML tags and content. Attackers typically exploit this vulnerability through URL parameters or form inputs, combining it with social engineering techniques to deceive users. For example, an attacker might inject a fake login form into a trusted website to harvest credentials, or modify page content to spread misinformation while appearing to originate from a legitimate source.

Remediation

Implement comprehensive input validation and output encoding to prevent HTML Injection:

1. Output Encoding (Primary Defense):
Always encode user-supplied data before rendering it in HTML contexts. Use context-appropriate encoding functions:

// Java example using OWASP Java Encoder
import org.owasp.encoder.Encode;
String safe = Encode.forHtml(userInput);

// PHP example
$safe = htmlspecialchars($userInput, ENT_QUOTES, 'UTF-8');

// JavaScript example
function encodeHTML(str) {
  return str.replace(/[&"']/g, function(match) {
    const escape = {
      '&': '&',
      '': '>',
      '"': '"',
      "'": '''
    };
    return escape[match];
  });
}

2. Input Validation:
Validate all user input against strict allowlists. Reject or sanitize input containing HTML metacharacters (<, >, ", ', &) unless explicitly required.

3. Content Security Policy (CSP):
Implement CSP headers to provide defense-in-depth and limit the impact of successful injection attacks.

4. Framework-Level Protection:
Use modern web frameworks with automatic output encoding (e.g., React, Angular, Vue.js) and ensure auto-escaping features are enabled in templating engines.

5. Security Testing:
Regularly test all user input fields and URL parameters for HTML injection vulnerabilities using both automated scanners and manual testing.

Related Vulnerabilities