@marcel91200 / caddy Mirror · read-only / commits / 39c9a85f
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 11, 08:30 UTC

fileserver: append repeated `hide` subdirectives instead of overwriting (#7817)

Multiple `hide` subdirectives in a file_server Caddyfile block silently overwrote each other, so only the last one took effect. Append to the list instead, so repeated entries accumulate and imported snippets can compose with site-specific hides.

Luccin Masirika committed Jun 13, 2026 at 14:44 UTC 39c9a85f80a3a2b1aff710c6cbd1190b2aab1b83
2 files changed +41 -2
caddytest/integration/caddyfile_adapt/file_server_hide_repeated.caddyfiletest new
+35
@@ -0,0 +1,35 @@
1 +:80
2 +
3 +file_server {
4 + hide first.txt
5 + hide second.txt third.txt
6 +}
7 +----------
8 +{
9 + "apps": {
10 + "http": {
11 + "servers": {
12 + "srv0": {
13 + "listen": [
14 + ":80"
15 + ],
16 + "routes": [
17 + {
18 + "handle": [
19 + {
20 + "handler": "file_server",
21 + "hide": [
22 + "first.txt",
23 + "second.txt",
24 + "third.txt",
25 + "./Caddyfile"
26 + ]
27 + }
28 + ]
29 + }
30 + ]
31 + }
32 + }
33 + }
34 + }
35 +}
modules/caddyhttp/fileserver/caddyfile.go
+6 -2
@@ -91,10 +91,14 @@ func (fsrv *FileServer) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
91 fsrv.FileSystem = d.Val()
92
93 case "hide":
94 - fsrv.Hide = d.RemainingArgs()
95 - if len(fsrv.Hide) == 0 {
94 + hide := d.RemainingArgs()
95 + if len(hide) == 0 {
96 return d.ArgErr()
97 }
98 + // Append so that repeated "hide" subdirectives accumulate
99 + // instead of overwriting, which also lets imported snippets
100 + // compose with site-specific hides.
101 + fsrv.Hide = append(fsrv.Hide, hide...)
102
103 case "index":
104 fsrv.IndexNames = d.RemainingArgs()