Skip to main content

html_entity_encode

Function html_entity_encode 

Source
pub fn html_entity_encode(input: &str) -> String
Expand description

Encodes text using various HTML entity formats.

Randomly encodes characters using plain text, decimal entities (&#...;), hexadecimal entities (&#x...;), or named entities (<, >, etc.). This mixed approach tests HTML parser robustness and can bypass filters.

§Use Cases

  • XSS Testing: Bypass HTML sanitizers with entity encoding
  • Red Team: Evade WAF rules that look for literal characters
  • Blue Team: Test HTML entity decoder implementations
  • Web Scraping: Handle various entity encoding formats

§Examples

use redstr::html_entity_encode;

let result = html_entity_encode("<script>");
// Example: "&lt;&#115;&#x63;r&#105;pt&gt;" (varies each run)

// XSS payload with entity encoding
let xss = html_entity_encode("<img src=x onerror=alert(1)>");
// Bypasses filters looking for literal "<" and ">"

// Special character encoding
let special = html_entity_encode("A&B<C>D");
// Example: "A&amp;B&lt;C&gt;D"