ingress
azure_bootstrap.ingress
¶
Tier 2 attachment / file-upload hardening.
Four gates, fixed order: extension → MIME → size → magic-byte. Use
:class:AttachmentClassifier to run the whole pipeline; each gate is
also independently usable for projects that need finer control.
Modules:
| Name | Description |
|---|---|
classifier |
Attachment classifier — runs the four gates in fixed order. |
extensions |
Extension allowlist gate (cheapest, runs first in the classifier pipeline). |
magic_bytes |
Magic-byte classifier (authoritative — final gate in the pipeline). |
mime |
MIME allowlist gate (advisory — magic-byte gate is the real authority). |
size |
Size-cap gate. Raises |
zip_safety |
Zip-bomb defense. Inspect |
Functions:
| Name | Description |
|---|---|
classify_bytes |
Match the leading bytes against the signature table. |
extension_matches_kind |
Audit helper — is the filename's extension consistent with the bytes? |
enforce_size_cap |
Raise :class: |
enforce_zip_safety_limits |
Raise :class: |
classify_bytes
¶
classify_bytes(content: bytes, *, allowed: tuple[ClassifiedKind, ...] = ('pdf', 'zip')) -> ClassifiedKind
Match the leading bytes against the signature table.
Returns the first matched kind that's in allowed; otherwise "reject".
Source code in azure_bootstrap/ingress/magic_bytes.py
extension_matches_kind
¶
Audit helper — is the filename's extension consistent with the bytes?
Source code in azure_bootstrap/ingress/magic_bytes.py
enforce_size_cap
¶
enforce_size_cap(*, size_bytes: int, cap_bytes: int, filename: str, counter_name: str | None = None) -> None
Raise :class:OversizedAttachmentError when size_bytes > cap_bytes.
Source code in azure_bootstrap/ingress/size.py
enforce_zip_safety_limits
¶
enforce_zip_safety_limits(zf: ZipFile, *, filename: str, max_entries: int = MAX_ZIP_ENTRIES, max_uncompressed_bytes: int = MAX_ZIP_UNCOMPRESSED_BYTES, counter_name: str | None = None) -> None
Raise :class:ZipBombError when the archive metadata exceeds limits.
Inspects zf.infolist() only — does NOT call zf.read() (which
would allocate the uncompressed bytes). The whole point is to gate on
the declared metadata BEFORE any expansion.