Documentation
¶
Overview ¶
Package filemagic does magic-byte detection for archive identification and polyglot detection — examining the first bytes of a response body to catch archives disguised as safe types and Content-Type/content mismatches. It is a self-contained leaf (stdlib only) extracted from package main per ADR-0002.
This complements extension-based blocking — magic bytes can't be faked by renaming a file or manipulating the URL path. (The glue that consults the file blocker, IsBlockedArchive, stays in package main since it needs the fileBlocker singleton.)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckVsContentType ¶
CheckVsContentType detects polyglot files by comparing the Content-Type header against the actual content's magic bytes. Returns a non-empty reason when a mismatch indicates a potentially disguised file (e.g., a PE served as image/png).
Types ¶
type Sig ¶
type Sig struct {
Offset int // byte offset where the magic starts
Magic []byte // expected bytes at that offset
Type string // detected file type (e.g., "PE", "ZIP")
Ext string // canonical extension (e.g., ".exe", ".zip")
Archive bool // true if this is an archive/container format
}
Sig describes a file type signature (magic bytes).