Test files › Security and validation › polyglot-gif-html.gif

GIF/HTML polyglot test file

A file that is simultaneously a valid GIF (correct GIF89a header and dimensions) and valid HTML containing an inert script. Renders as an image to an image parser and as a page to a browser.

↓ Download polyglot-gif-html.gif
Filenamepolyglot-gif-html.gif
FormatGIF + HTML polyglot
Size192 bytes (192 bytes)
MIME typeimage/gif
SHA-256c965bb91779eaa8bbf8a03cca8ea28223de282237a38b736541b8f14eb724b5f
What this file catchesContent-type sniffing. If your server serves user uploads without X-Content-Type-Options: nosniff, a browser may sniff this as HTML and execute it from your origin, even though it passed image validation on upload.

Handle it in code

Each snippet below was run against this exact file with Python 3.14.4 and Node 24.15.0 when this page was built, and the output shown is what it printed.

Python

A valid image can also contain HTML. Browsers that sniff content may render it as a page, running its script on your domain. Serve uploads with their stored Content-Type and X-Content-Type-Options: nosniff, ideally from a separate domain; this check flags files worth a closer look.

MARKERS = (b"<html", b"<script", b"<body", b"<iframe", b"<svg", b"<!doctype html")

with open("polyglot-gif-html.gif", "rb") as f:
    head = f.read(1024)
kind = {b"GIF8": "GIF", b"\x89PNG": "PNG", b"\xff\xd8\xff\xe0": "JPEG"}.get(head[:4], "unknown")
found = [m.decode() for m in MARKERS if m in head.lower()]
if found:
    print(f"starts as {kind}, but the first 1 KB also contains {', '.join(found)}: a sniffing browser may render it as HTML")
else:
    print(f"{kind}: no HTML markers in the first 1 KB")

Run against this file, it prints: starts as GIF, but the first 1 KB also contains <html, <script: a sniffing browser may render it as HTML

Related guides and tools

Sample image filesUpload validation checklistQA test stringsCheck a file's real typeVerify its SHA-256

Download & verify

curl -fsSL -o "polyglot-gif-html.gif" "https://flagged.hexaqa.com/security/polyglot-gif-html.gif"
curl -fsSL "https://flagged.hexaqa.com/security/polyglot-gif-html.gif" | sha256sum # expect: c965bb91779eaa8bbf8a03cca8ea28223de282237a38b736541b8f14eb724b5f

More security and validation test files

eicar.com.txtgtube-spam.txthtml-xss-payloads.htmlpath-traversal-payloads.txtshell-script.shsql-injection-payloads.txtwindows-batch.bat

← All Security and validation files