Security Vulnerabilities in glTF Parsing
The GL Transmission Format (glTF) is the standard file format for 3D scenes and models, packaging structured JSON metadata alongside raw binary chunks that store vertex attributes, indices, animations, and textures. When 3D engines, web viewers, or native applications consume untrusted glTF or GLB (binary glTF) files, parsing flaws in either the text or binary layers can introduce severe security risks. Attackers can exploit these flaws to trigger memory corruption, denial of service, arbitrary file reads, server-side request forgery, and potential remote code execution.
Buffer Overflows and Out-of-Bounds Memory Access
The binary portion of glTF relies on an indexing hierarchy consisting
of buffers, bufferViews, and
accessors. Malicious assets can exploit the arithmetic used
to navigate these structures:
- Integer Overflows in Size Calculations: Accessors
declare a
count, acomponentType, and atype(such asVEC3), while buffer views define abyteOffsetandbyteStride. Native parsers written in C or C++ often multiply these fields to compute total memory allocation sizes. If an attacker supplies extremely large integers, the multiplication can wrap around to a small number, causing the engine to allocate an undersized buffer while copying a larger payload, resulting in a heap-based buffer overflow. - Out-of-Bounds Reads and Writes: An accessor can
specify a
byteOffsetor indexcountthat exceeds the physical boundary of its referencedbufferViewor the underlying raw binary chunk. Without strict bounds checking, the renderer reads or writes past allocated memory boundaries, leading to application crashes or arbitrary code execution. - Malformed Sparse Accessors: glTF supports
sparseaccessors, which overwrite specific indices of an existing buffer with custom values. If an engine fails to validate that sparse index arrays point within valid buffer bounds, it can allow an attacker to write arbitrary values to out-of-bounds offsets in memory.
Type Confusion
An accessor defines how raw binary data is cast into typed values for the graphics pipeline (e.g., unsigned bytes, signed shorts, or 32-bit floats). If the parser does not enforce strict alignment and type constraints:
- Misaligned reads can cause hardware exceptions or undefined behavior on strict-alignment architectures.
- Casting mismatches can cause native engines to interpret arbitrary binary data as pointers or internal structural metadata, enabling control-flow hijacking.
Path Traversal and Server-Side Request Forgery (SSRF)
glTF permits referencing assets like textures and buffers via URIs:
- Directory Traversal: If a parser naively resolves
relative paths defined in the
uriproperty (e.g.,../../../../etc/passwdor..\..\Windows\win.ini), an attacker can cause the application to load or leak sensitive local files. - SSRF and Protocol Smuggling: When glTF files are
parsed on a backend server (such as in asset optimization pipelines or
3D model converters), external URIs using protocols like
http://,https://, orfile://can force the host to query internal services, cloud metadata endpoints (e.g.,169.254.169.254), or private network resources.
JSON-Specific Vulnerabilities
The JSON payload defines the scene hierarchy, node transforms, and pipeline descriptions. Processing this text layer introduces specific hazards:
- Denial of Service (DoS) via Deep Nesting: Attackers can craft JSON structures with thousands of nested arrays or objects. Parsers relying on recursive descent can suffer call stack exhaustion, crashing the runtime.
- Prototype Pollution: In WebGL-based parsers
operating within JavaScript environments, untrusted JSON containing keys
such as
__proto__orconstructor.prototypecan modify base object prototypes, potentially bypassing security checks or leading to client-side code execution. - Resource Exhaustion via Massive Allocations: An attacker can declare millions of empty nodes, textures, or materials within valid JSON syntax. If the host environment allocates memory for every declared object before validating its contents or availability in the binary chunk, it can exhaust system RAM and cause an out-of-memory crash.
Extension Parsing Vulnerabilities
glTF features an extensible architecture (extensionsUsed
and extensionsRequired) allowing third-party compression
and rendering techniques:
- Decompression Bombs (Zip Bombs): Extensions like
KHR_draco_mesh_compressionorKHR_texture_basisuprocess compressed geometry and textures. A malformed asset can contain a tiny compressed payload that expands into gigabytes of uncompressed geometric data, leading to decompression loops or memory exhaustion. - Unvalidated Extension Deserialization: Custom extensions processed through dynamic dispatch or reflection can expose the host application to insecure deserialization vulnerabilities if data from the JSON dictionary is passed directly into native system calls.
Mitigation Requirements
Securing a glTF pipeline requires defensive parsing practices across both format layers:
- Enforce strict arithmetic bounds checking before allocating or accessing memory, using safe math libraries that check for integer overflow.
- Disallow external URIs by default, or strictly isolate the parser inside a sandbox where URIs are validated against an allowlist and prohibited from accessing local files or private network spaces.
- Validate all accessor offsets, strides, and counts against the total byte length of the binary chunk prior to executing render or copy calls.
- Restrict maximum JSON recursion depth, total object count, and decompressed buffer dimensions to bounded thresholds.