Skip Navigation
StructureStructure

StaticFileHandler

Handler for serving static files from a directory.

struct StaticFileHandler

Overview

This type provides secure file serving with path sanitisation to prevent directory traversal attacks. It supports automatic index file resolution for directory requests.

Overview

StaticFileHandler validates and sanitises all incoming request paths, ensuring they remain within the configured root directory. Directory requests are automatically redirected to index.html if present.

Security

The handler implements several security measures:

  • Path normalisation to prevent .. traversal

  • Verification that resolved paths stay within the root directory

  • URL decoding with malformed input rejection

  • Query string stripping

Relationships

  • Swift.Sendable
  • Swift.SendableMetatype