fix(14.2): WR-04 validate storage.uploads.public_path_prefix at boot
The prefix was only trimmed. Without a leading slash ServeMux read its first segment as a host pattern, so every upload silently answered 404, and a CDN URL panicked in ServeMux and surfaced as a misleading route conflict. With storage.uploads.serve on, BuildRouter now refuses a prefix that is not an absolute URL path (scheme, host, query, fragment, whitespace, wildcard braces, empty, . or .. segments, or a bare /) with an error naming the key.
This commit is contained in:
@@ -57,6 +57,8 @@ The route serves originals and thumbnails and answers 404 for a missing file, an
|
||||
- Every response carries `Content-Security-Policy: default-src 'none'; img-src 'self'; media-src 'self'; sandbox`. A file opened as a page runs no script and gets an opaque origin, so it cannot read the application's cookies or storage. The policy does not affect an `<img>` or `<video>` that embeds the file.
|
||||
- A file whose type is not a raster image (`image/jpeg`, `image/png`, `image/gif`, `image/webp` or `image/avif`) is sent with `Content-Disposition: attachment`, so the browser downloads it instead of showing it. That includes HTML, SVG, PDF and plain text.
|
||||
|
||||
With `serve` on, `public_path_prefix` must be an absolute URL path such as `/storage/uploads`: a leading slash, no scheme or host, no query, no empty, `.` or `..` segment and no `{` or `}`. Start-up fails with an error naming the key otherwise, for example for the WinterCMS disk path `storage/app/uploads/public` or a CDN URL. With `serve` off the key only builds file URLs, so a CDN origin is fine there.
|
||||
|
||||
The route looks up the bucket and the database on each request: `route:list` lists it without opening either, and it answers 404 until `serve` has published them. The route owns the whole prefix, so start-up fails when a plugin registers a route at or under it.
|
||||
|
||||
Without the key, the application decides where files are served: mount `attach.StaticHandlerPublic` itself, or put a web server or CDN in front of the bucket directory. Either way, serve uploads from a separate origin when you can; the [Attachments](../database/attachments.md) page explains why. The built-in route is meant for development and for deployments that cannot split the origin yet.
|
||||
|
||||
Reference in New Issue
Block a user