WASM
application/wasm
Magic Bytes
Offset: 0
00 61 73 6D
WebAssembly (WASM) is a binary instruction format for a stack-based virtual machine, maintained as an open standard by the World Wide Web Consortium. It enables high-performance applications on the web, allowing languages like C++, Rust, and Go to run at near-native speeds within browsers. While considered safe due to its sandboxed execution environment, rigorous validation is required to mitigate potential side-channel vulnerabilities or memory exploits.
Validation Code
How to validate .wasm files in Python
Python
def is_wasm(file_path: str) -> bool:
"""Check if file is a valid WASM by magic bytes."""
signature = bytes([0x00, 0x61, 0x73, 0x6D])
with open(file_path, "rb") as f:
return f.read(4) == signature
How to validate .wasm files in Node.js
Node.js
function isWASM(buffer: Buffer): boolean {
const signature = Buffer.from([0x00, 0x61, 0x73, 0x6D]);
return buffer.subarray(0, 4).equals(signature);
}
Go
func IsWASM(data []byte) bool {
signature := []byte{0x00, 0x61, 0x73, 0x6D}
if len(data) < 4 {
return false
}
return bytes.Equal(data[:4], signature)
}
API Endpoint
GET
/api/v1/wasm
curl https://filesignature.org/api/v1/wasm