How to Build a Custom MIME Sniffer in OutSystems ODC (C# Guide)

Article

TL;DR: Don't rely on file extensions for security—they are easily spoofed. This guide shows how to create an ODC External Library in C# that uses "Magic Numbers" (the first few bytes of a file) to accurately identify MIME types, mirroring the popular O11 MimeSniffer library for a smoother migration.

Why Use Magic Numbers? A file named invoice.pdf could actually be a malicious .exe in disguise. Checking the magic numbers (e.g., 25-50-44-46 for PDF) ensures that the file content actually matches its extension, providing a critical layer of defense against malicious uploads.

Key Implementation Steps:

  1. Project Setup (Visual Studio): Create a new C# Class Library project and install the OutSystems.ExternalLibraries.SDK via NuGet.

  2. Define the Interface: Use the [OSInterface] attribute to define the library's name, icon, and description. This ensures ODC can correctly recognize and consume the library.

  3. Implement the Sniffing Logic: * Read the first 16 bytes of the file buffer.

Convert the bytes to a Hex string.

Use a switch statement to map Hex signatures to MIME types (e.g., FF-D8-FF-E0 = image/jpeg).

  1. Create Helper Methods: Build auxiliary functions like GetMimeFromBinary and ValidateFileExtension to handle the heavy lifting of comparing the detected MIME against the user-provided filename.

  2. Publish & Upload: * Use dotnet publish to generate the release artifacts.

Zip the contents of the publish folder.

Upload the ZIP to the ODC Portal under External Logic.

Benefits for O11-to-ODC Migration: By mirroring the service signatures of the original O11 MimeSniffer, teams can reuse their existing validation patterns in ODC with minimal refactoring. This maintains security standards while moving to a modern cloud-native architecture.

The "Secure" Pattern: Always call this custom logic on the Server Side immediately after a file upload and before saving the binary to your database or cloud storage.

Source/Full Tutorial: OutSystems ODC — Creating a simple MIME sniffer using C# code

Posted Mar 6, 2026, 9:47 PM UTC

120
Loading comments…