Backtestshugorun-20261009-153657#15367

Issue #15367 Merged fix PR #15368 Run 9 Oct 2026 · run-20261009-153657 gohugoio/hugo

Allow symlinks for mount source for the main project

Better

Our patch was judged better than the merged fix.

In this judgment, Patch A = our agent, Patch B = the merged fix.

The production code change is effectively identical in both patches: each wraps the `isSymlinkOrHasSymlinkParent` check in `if !rm.IsProject`, so main-project mount roots may be symlinks while theme/module mounts are still dropped. Correctness is equal, and the difference lies in tests and comments. Patch A's tests are more thorough and track the issue more closely. It adds a content mount whose source is a symlinked directory (`projectcontentlink` -> `projectcontentsrc`, mounted at `content/project-a`), which is the exact scenario in the issue, and asserts the page `p1/` is built. It also adds a nested symlink inside the symlinked project mount root (`rootdir/subdir/nestedsymlink.txt`) and verifies it is still excluded, both via `resources.Get` and via a `resources.Match` count of 3. This confirms the exemption only covers the mount root and does not weaken the per-file symlink filtering. Patch B covers only the assets mount root and parent cases, and does not test that nested symlinks remain blocked. A's code comment also states the security boundary more accurately ('Symlinks below the mount root are still dropped, see statRoot'). B's rationale, that absolute mount sources mean a symlink gains nothing, is reasonable but says less about what remains protected. Neither patch adds unrelated churn. A wins on test quality and clarity.

The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.

Solve

19m 44s

Wall-clock time in the container

Full test suite

No new failures

1,788 passed · 79 skipped · 1,867 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

51vs 31 merged

Changed lines, ours vs merged

Hugo 0.166.0 introduced commit https://github.com/gohugoio/hugo/commit/938c820626bd0a524dc1482cbe83b6c2e1171d20 (hugofs: Drop symlinked mount roots) that breaks a legit use-case of symlinks.

In my case, I mount a directory in my hugo.yaml:

module:
  mounts:
    - source: "content"
      target: "content"
    # Mount content generated in another repository
    - source: "_build/includes/project-a"
      target: "content/project-a"

_build/includes/project-a itself can be a symlink to another local directory, e.g. ../../../project-a, which allows quick local debugging. In production, a CI workflow may clone the Git repo of project-a to this destination which does not trigger the problem.

I am not familiar with the internals of hugofs and the security concept, but would appreciate if users could trust certain mounts, and therefore bypass the newly introduced hard drop of symlinks.

The two patches

Our patch+42 −9
hugofs/rootmapping_fs.goindex 4b123bf21..56a44b0b9 100644@@ -63,12 +63,16 @@ func NewRootMappingFs(fs afero.Fs, rms ...*RootMapping) (*RootMappingFs, error)  		// Don't allow a symlinked mount root (or any directory between it and 		// the module root) to escape the module.-		symlink, err := isSymlinkOrHasSymlinkParent(fs, rm.ToBase, rm.To)-		if err != nil {-			return nil, err-		}-		if symlink {-			continue+		// The main project is trusted, so its mount roots may be symlinks.+		// Symlinks below the mount root are still dropped, see statRoot.+		if !rm.IsProject {+			symlink, err := isSymlinkOrHasSymlinkParent(fs, rm.ToBase, rm.To)+			if err != nil {+				return nil, err+			}+			if symlink {+				continue+			} 		}  		fi, err := fs.Stat(rm.To)testscripts/commands/no_symlinks.txtindex f62e608d9..37ac43604 100644@@ -5,6 +5,9 @@ ln ./rootfile.txt ./themes/mytheme/static/modstaticsymlink.txt ln ./README.md ./content/pagesymlink.md ln ./rootdir ./assets/myassets/symlinkdir ln ./rootdir ./projectmountroot+ln ./rootdir ./projectmountparent+ln ./projectcontentsrc ./projectcontentlink+ln ./rootfile.txt ./rootdir/subdir/nestedsymlink.txt ln ./rootdir ./themes/mytheme/thememountroot ln ./rootdir ./themes/mytheme/thememountparent @@ -21,7 +24,16 @@ stdout 'modstatictok' ! stdout 'modstaticsymlink' stdout pageok ! stdout pagesymlink-! stdout rootdirfile+stdout 'projectmountroot/'+stdout 'rootdirfile1.txt'+stdout 'projectmountparent/'+stdout 'rootdirfile3.txt'+stdout 'project-a/'+stdout 'p1/'+! stdout 'nestedsymlink'+! stdout 'thememountroot'+! stdout 'thememountparent'+! stdout 'symlinkdir'  -- hugo.toml -- disableKinds = ["taxonomy", "term", "rss"]@@ -33,6 +45,15 @@ target = 'assets' [[module.mounts]] source = 'projectmountroot' target = 'assets/projectmountroot'+[[module.mounts]]+source = 'projectmountparent/subdir'+target = 'assets/projectmountparent'+[[module.mounts]]+source = 'content'+target = 'content'+[[module.mounts]]+source = 'projectcontentlink'+target = 'content/project-a' -- themes/mytheme/hugo.toml -- [[module.mounts]] source = 'assets'@@ -54,10 +75,14 @@ Read me. {{ with resources.GetMatch "modassetsymlink.txt"}}FAIL {{ .Publish }}{{ else }}OK{{ end }} {{ with resources.GetMatch "myassets/symlinkdir/**"}}FAIL {{ .Publish }}{{ else }}OK{{ end }} {{ with resources.Get "myassets/symlinkdir/rootdirfile1.txt"}}FAIL {{ .Publish }}{{ else }}OK{{ end }}-{{ with resources.Get "projectmountroot/rootdirfile1.txt"}}FAIL {{ .Publish }}{{ else }}OK{{ end }}+{{ with resources.Get "projectmountroot/rootdirfile1.txt"}}OK {{ .Publish }}{{ else }}FAIL{{ end }}+{{ with resources.Get "projectmountroot/subdir/rootdirfile3.txt"}}OK {{ .Publish }}{{ else }}FAIL{{ end }}+{{ with resources.Get "projectmountroot/subdir/nestedsymlink.txt"}}FAIL {{ .Publish }}{{ else }}OK{{ end }}+{{ with resources.Get "projectmountparent/rootdirfile3.txt"}}OK {{ .Publish }}{{ else }}FAIL{{ end }}+{{ with resources.Match "projectmountroot/**"}}{{ if eq (len .) 3 }}OK{{ else }}FAIL {{ len . }}{{ end }}{{ else }}FAIL{{ end }} {{ with resources.Get "thememountroot/rootdirfile1.txt"}}FAIL {{ .Publish }}{{ else }}OK{{ end }} {{ with resources.Get "thememountparent/rootdirfile3.txt"}}FAIL {{ .Publish }}{{ else }}OK{{ end }}-{{ with resources.GetMatch "*mountroot/**"}}FAIL {{ .Publish }}{{ else }}OK{{ end }}+{{ with resources.GetMatch "thememount*/**"}}FAIL {{ .Publish }}{{ else }}OK{{ end }} Page: {{ .RelPermalink }}|{{ .Content }}|  {{/* os template package. */}}@@ -77,6 +102,10 @@ Page: {{ .RelPermalink }}|{{ .Content }}| {{ end }}  -- content/pageok.md --+-- projectcontentsrc/p1.md --+---+title: P1+--- -- themes/mytheme/assets/modassetok.txt -- Content. -- themes/mytheme/static/modstatictok.txt -- 
Merged fix · PR #15368+21 −10
hugofs/rootmapping_fs.goindex 4b123bf21..e8c8e2804 100644@@ -62,13 +62,16 @@ func NewRootMappingFs(fs afero.Fs, rms ...*RootMapping) (*RootMappingFs, error) 		}  		// Don't allow a symlinked mount root (or any directory between it and-		// the module root) to escape the module.-		symlink, err := isSymlinkOrHasSymlinkParent(fs, rm.ToBase, rm.To)-		if err != nil {-			return nil, err-		}-		if symlink {-			continue+		// the module root) to escape the module. The main project is exempt;+		// its mount sources may be absolute, so a symlink gains nothing.+		if !rm.IsProject {+			symlink, err := isSymlinkOrHasSymlinkParent(fs, rm.ToBase, rm.To)+			if err != nil {+				return nil, err+			}+			if symlink {+				continue+			} 		}  		fi, err := fs.Stat(rm.To)testscripts/commands/no_symlinks.txtindex f62e608d9..cf8904d3e 100644@@ -5,6 +5,7 @@ ln ./rootfile.txt ./themes/mytheme/static/modstaticsymlink.txt ln ./README.md ./content/pagesymlink.md ln ./rootdir ./assets/myassets/symlinkdir ln ./rootdir ./projectmountroot+ln ./rootdir ./projectmountparent ln ./rootdir ./themes/mytheme/thememountroot ln ./rootdir ./themes/mytheme/thememountparent @@ -19,9 +20,11 @@ stdout modassetok ! stdout modassetsymlink stdout 'modstatictok' ! stdout 'modstaticsymlink'+stdout projectmountroot+stdout projectmountparent stdout pageok ! stdout pagesymlink-! stdout rootdirfile+! stdout thememount  -- hugo.toml -- disableKinds = ["taxonomy", "term", "rss"]@@ -33,6 +36,9 @@ target = 'assets' [[module.mounts]] source = 'projectmountroot' target = 'assets/projectmountroot'+[[module.mounts]]+source = 'projectmountparent/subdir'+target = 'assets/projectmountparent' -- themes/mytheme/hugo.toml -- [[module.mounts]] source = 'assets'@@ -54,10 +60,12 @@ Read me. {{ with resources.GetMatch "modassetsymlink.txt"}}FAIL {{ .Publish }}{{ else }}OK{{ end }} {{ with resources.GetMatch "myassets/symlinkdir/**"}}FAIL {{ .Publish }}{{ else }}OK{{ end }} {{ with resources.Get "myassets/symlinkdir/rootdirfile1.txt"}}FAIL {{ .Publish }}{{ else }}OK{{ end }}-{{ with resources.Get "projectmountroot/rootdirfile1.txt"}}FAIL {{ .Publish }}{{ else }}OK{{ end }}+{{ with resources.Get "projectmountroot/rootdirfile1.txt"}}OK {{ .Publish }}{{ else }}FAIL{{ end }}+{{ with resources.Get "projectmountparent/rootdirfile3.txt"}}OK {{ .Publish }}{{ else }}FAIL{{ end }}+{{ with resources.Get "projectmountroot/subdir/rootdirfile3.txt"}}OK {{ .Publish }}{{ else }}FAIL{{ end }} {{ with resources.Get "thememountroot/rootdirfile1.txt"}}FAIL {{ .Publish }}{{ else }}OK{{ end }} {{ with resources.Get "thememountparent/rootdirfile3.txt"}}FAIL {{ .Publish }}{{ else }}OK{{ end }}-{{ with resources.GetMatch "*mountroot/**"}}FAIL {{ .Publish }}{{ else }}OK{{ end }}+{{ with resources.GetMatch "thememount*/**"}}FAIL {{ .Publish }}{{ else }}OK{{ end }} Page: {{ .RelPermalink }}|{{ .Content }}|  {{/* os template package. */}}