Structure
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
Topics
Creating a Handler
Creates a new static file handler.
Handling Requests
Handles an HTTP request and returns an appropriate response.
Properties
The root directory for serving files.