diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-07-25 00:12:40 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-07-25 11:27:25 +0200 |
commit | e5f229974166402f51e4ee0695ffb4d1e09fa174 (patch) | |
tree | 44dc7adc4fd02cb563583afaff6ddaa781821e2f /hugofs/fileinfo.go | |
parent | 87a07282a2f01779e098cde0aaee1bae34dc32e6 (diff) |
Block symlink dir traversal for /static
This is in line with how it behaved before, but it was lifted a little for the project mount for Hugo Modules,
but that could create hard-to-detect loops.
Diffstat (limited to 'hugofs/fileinfo.go')
-rw-r--r-- | hugofs/fileinfo.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/hugofs/fileinfo.go b/hugofs/fileinfo.go index a2f12c429..5a0fc2363 100644 --- a/hugofs/fileinfo.go +++ b/hugofs/fileinfo.go @@ -180,9 +180,20 @@ type FileMetaInfo interface { type fileInfoMeta struct { os.FileInfo + m FileMeta } +// Name returns the file's name. Note that we follow symlinks, +// if supported by the file system, and the Name given here will be the +// name of the symlink, which is what Hugo needs in all situations. +func (fi *fileInfoMeta) Name() string { + if name := fi.m.Name(); name != "" { + return name + } + return fi.FileInfo.Name() +} + func (fi *fileInfoMeta) Meta() FileMeta { return fi.m } @@ -295,3 +306,11 @@ func normalizeFilename(filename string) string { } return filename } + +func fileInfosToNames(fis []os.FileInfo) []string { + names := make([]string, len(fis)) + for i, d := range fis { + names[i] = d.Name() + } + return names +} |