The Concept of Binary Polyglots
A "polyglot" in computer security is a single file that can be parsed as two or more completely different file formats simultaneously, with each parser treating the file as 100% valid according to its specification.
For example, a JPEG-JAR polyglot functions as a valid JPEG image when loaded in a web browser, but when executed by the Java Virtual Machine (`java -jar image.jpg`), it executes malicious Java bytecode.
Polyglots exploit architectural differences in how file parsers validate headers. Image parsers validate magic bytes at offset 0 (like `FF D8` for JPEG or `89 50 4E 47` for PNG), while archive parsers (like ZIP/JAR) scan backward from the end of the file for the central directory record.
Polyglots satisfy multiple file format parsers simultaneously, allowing malicious executables to bypass restrictive image upload validators.
The Anatomy of a GIFAR and HTML-Image Polyglot
1. GIFAR (GIF + JAR): Pioneered in 2008, combining a GIF header with a Java Archive. The GIF parser reads the image dimensions and terminates; Java reads the embedded manifest and executes code.
2. Image-HTML/SVG XSS Polyglot: Embedding `<script>` tags inside image comments or EXIF fields. If a web application serves the image with a `Content-Type: text/html` header, the browser executes the embedded script.
Detecting and Disarming Polyglots with OverlayCheck
OverlayCheck parses complete file structures from both offset 0 and reverse offsets, detecting secondary valid file headers embedded within image bodies and warning security auditors of potential polyglot risks.
Polyglot Defense: File Verification Approaches
Evaluating protection against polyglot file execution attacks.
| Feature / Dimension | OverlayCheck (Client-Side) | MIME-Type & Extension Checking | True Content Re-Encoding (Canvas/WASM) |
|---|---|---|---|
| Polyglot Attack Neutralization | 100% Neutralized (Re-encodes pixel raster) | Fails Completely (Polyglot passes MIME checks) | Neutralized (Strips non-pixel payloads) |
Command-Line Automation & CLI Workflows
For security engineers and forensic examiners automating pipelines or conducting terminal audits, the equivalent low-level commands can be executed natively:
file -k suspect_polyglot.jpgFrequently Asked Technical Questions
Q1:How do web applications defend against polyglot uploads?
The definitive defense is re-encoding uploaded images through a graphics library (like Canvas or libvips), which strips extraneous binary data and writes a clean, single-format image.