File Uploads and Server-Side Requests
An attachment can arrive as uploaded bytes or through an import feature. Uploads introduce untrusted files into storage. URL imports also give the application a reason to open a network connection.
On this page
Validate, isolate, then publish an attachment
Check permission and size before expensive parsing. The filename extension and declared MIME type are hints. Verify expected content with a maintained parser and apply scanning or re-encoding as appropriate. Generate a storage key, keep pending files private outside the web root, and recheck access on download. A failed scan must leave the file unavailable.
Upload received Private quarantine, generated storage key
Checks passed Mark available to authorized document members
Check failed Keep unavailable; record the reason internally
Constrain outbound connections to known destinations
Server-side request forgery (SSRF) is a risk when an input influences where the backend connects. For a known provider, accept a file ID and construct a URL from a fixed origin. Restrict network egress, disable redirects or validate every hop, and set time and byte limits. Require access to the requested remote object.
function providerFileUrl(fileId) {
if (!/^[a-zA-Z0-9_-]{1,64}$/.test(fileId)) {
throw new Error("Invalid file ID");
}
return new URL("/files/" + fileId, "https://files.example");
}