K093 / Encoding and decoding
HTML entities
Character sequences in HTML documents used to represent reserved or special characters.
CRYPTOGRAPHY LAB / K093
Cryptography Lab · HTML entities
Run real computations and inspect intermediate states step by step.
Educational only. Never enter real passwords or secret keys. Computation stays in your browser; input and trace values are not sent to a server. Do not use this implementation in production.
HTML entities (five-character text escaping)
See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.Output
Previous state
- Definition and overview
- Character sequences in HTML documents used to represent reserved or special characters. Source document ↗
- Classification and reversibility
- Reversible encoding, not encryption or hashing; browsers substitute entities with original characters. Source document ↗
- Key or secret requirements
- Not confirmed in the survey
- Operating principle and structure
- Named, decimal and hexadecimal forms; case-sensitive. Source document ↗
- Key size, block size and parameters
- Not confirmed in the survey
- Security strength and recommendation
- Recommended output encoding for safely displaying user input. Source document ↗
- Known attacks and vulnerabilities
- Some entity decoders omit named entities, potentially permitting filter bypasses. Source document ↗
- Standards and certification
- WHATWG HTML named character reference list distinguishes amp and amp; entries. Source document ↗
- Typical uses
- Context-appropriate HTML output encoding to mitigate XSS. Source document ↗
- Implementations, libraries and tools
- JavaScript he and other entity encoders/decoders. Source document ↗
- Decryption or decoding
- Decode with specified text/attribute context, semicolon and error policies. Source document ↗
- Advantages
- Safely represents invisible, ambiguous or code-conflicting characters. Source document ↗
- Limitations and cautions
- Semicolon omission rules vary by version/implementation and may be unsafe. Source document ↗
- Distinguishing encryption, encoding and hashing
- Contextual escaping to prevent data being interpreted as code, not encryption/hashing. Source document ↗
Practical examples
Example
When displaying Tom & Jerry <3 in HTML text, encode it as Tom & Jerry <3; the browser displays the original characters.
Procedure
Identify HTML text, attribute, URL or JS context; escape dangerous characters such as &, <, > and quotes with the appropriate context-specific function. Decode only when needed using explicit context/semicolon policy. No secret key.
Scenario
Encode forum comments before rendering rather than inserting raw input. Security inspection systems should support standard named references and semicolon variants when decoding.
Pitfalls and alternatives
Missing semicolons, incomplete named-entity decoders and wrong output contexts may cause bypasses and XSS. Use vetted libraries and context-specific output encoding instead of relying only on input filters.
References
- HTML | Entities | Codecademy ↗
- Cross Site Scripting Prevention - OWASP Cheat Sheet Series ↗
- HTML decoder missing entities, leading to evasion · Advisory · owasp-modsecurity/ModSecurity · GitHub ↗
- - The Go Programming Language ↗
- Encode & Decode HTML Entities in JS, PHP & Python ↗
- mathiasbynens/he ↗
- html-entity-codec ↗
- Using character escapes in markup and CSS ↗
- HTML character references - Just Solve the File Format Problem ↗