GoogleWebP image file
image/webp
Magic Bytes
Offset: 0
52 49 46 46 2E 2E 2E 2E 57 45 42 50
The WebP image format is a raster graphics standard developed by Google to provide efficient data compression for web imagery. It supports both lossy and lossless compression, including transparency and animation, making it a standardized alternative to the JPEG, PNG, and GIF formats. Although generally considered safe, vulnerabilities in the underlying libwebp library have historically required security updates across web browsers, image viewers, and various operating systems.
Validation Code
How to validate .webp files in Python
Python
def is_webp(file_path: str) -> bool:
"""Check if file is a valid WEBP by magic bytes."""
signature = bytes([0x52, 0x49, 0x46, 0x46, 0x2E, 0x2E, 0x2E, 0x2E, 0x57, 0x45, 0x42, 0x50])
with open(file_path, "rb") as f:
return f.read(12) == signature
How to validate .webp files in Node.js
Node.js
function isWEBP(buffer: Buffer): boolean {
const signature = Buffer.from([0x52, 0x49, 0x46, 0x46, 0x2E, 0x2E, 0x2E, 0x2E, 0x57, 0x45, 0x42, 0x50]);
return buffer.subarray(0, 12).equals(signature);
}
Go
func IsWEBP(data []byte) bool {
signature := []byte{0x52, 0x49, 0x46, 0x46, 0x2E, 0x2E, 0x2E, 0x2E, 0x57, 0x45, 0x42, 0x50}
if len(data) < 12 {
return false
}
return bytes.Equal(data[:12], signature)
}
API Endpoint
GET
/api/v1/webp
curl https://filesignature.org/api/v1/webp