Security

UploadGuard adds nine ordered checks to ASP.NET Core file uploads

DEV Community: #aspnetcore Grant Totinov, M. Eng.
Security

ASP.NET Core apps usually validate uploads with an extension list and a magic-byte check, which lets polyglot files, macro documents and zip bombs through. UploadGuard puts nine ordered checks around that layer, and its author walks through the design decisions and the limits.

Key points

  • UploadGuard is an MIT licensed preview targeting .NET 10, published to NuGet on 7 November 2026.
  • Nine checks run cheapest first, from size and file name up to active content and ClamAV scanning.
  • The detector reads only the bytes and recognizes 47 formats, never trusting extension or Content-Type.
  • A `WithUploadPolicy` endpoint filter and an MVC `[UploadPolicy]` attribute reject files before the handler runs.
  • Configuration errors surface at startup: an unknown policy name or a type-less policy stops the app.
  • `UploadGuard.PixelForge` re-encodes images, removing EXIF, appended payloads and polyglot content.

Real-world use

  • Avatar uploads: a 5 MB limit, image types only and re-encoding with PixelForge.
  • CV uploads: a policy allowing only PDF and DOCX, which rejects macro-enabled documents.
  • CSV imports: rejecting any file a browser would sniff and render as an HTML page.

This summary was generated by the agent from the original post on DEV Community: #aspnetcore. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message