Backtestshugorun-20261013-011256#15367

Issue #15367 Merged fix PR #15368 Run 13 Oct 2026 · run-20261013-011256 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 changes are the same. Both wrap the `isSymlinkOrHasSymlinkParent` check in `if !rm.IsProject`, so the main project's mount roots and their parent directories may be symlinks while theme and module mounts are still filtered. This fixes the root cause in the issue: commit 938c820 dropped every symlinked mount root without exempting the trusted main project. Neither patch differs in correctness or scope. B's code comment gives a slightly better rationale (the project can already use absolute sources, so a symlink adds no new risk), but that is minor.

The tests decide it. Patch A reproduces the issue's exact scenario. It mounts `_build/includes/project-a` to `content/project-a`, where `project-a` is a symlink to an external directory sitting under a real parent directory. It then checks that the external page is resolved (`site.GetPage "/project-a/extpage"` returns the title) and published (`project-a/` and `extpage` appear in the public tree). It correctly re-adds the `content` mount, because user mounts replace the defaults. It also covers a symlinked root and a symlinked parent for asset mounts, checking actual file content. It narrows the negative glob to `theme*/**`, so the theme-symlink rejection is still tested. It keeps `! stdout rootdirfile` valid by using `.Content` instead of `.Publish`.

Patch B tests only asset mounts (a symlinked root, a symlinked parent, and a subdir via the root). It keeps the theme negatives with `thememount*/**` and `! stdout thememount`. It is adequate, but it never exercises the content-mount case from the issue. It also drops the `! stdout rootdirfile` guard and replaces it with a weaker check.

Both test sets would fail before the change and pass after it, but A's coverage maps directly to the reported use case, so A is better.

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

32m 50s

Wall-clock time in the container

Full test suite

No new failures

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

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

42vs 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+34 −8
hugofs/rootmapping_fs.goindex 4b123bf21..8e635dca4 100644@@ -63,12 +63,15 @@ 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.+		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..5fa2c4a66 100644@@ -5,6 +5,8 @@ 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 ./externalproject ./_build/includes/project-a ln ./rootdir ./themes/mytheme/thememountroot ln ./rootdir ./themes/mytheme/thememountparent @@ -12,6 +14,9 @@ hugo  grep 'OK' public/index.html ! grep 'FAIL' public/index.html+grep 'OK Rootdirfile1 content' public/index.html+grep 'OK Rootdirfile3 content' public/index.html+grep 'OK External Page' public/index.html  tree public @@ -20,6 +25,8 @@ stdout modassetok stdout 'modstatictok' ! stdout 'modstaticsymlink' stdout pageok+stdout 'project-a/'+stdout extpage ! stdout pagesymlink ! stdout rootdirfile @@ -31,8 +38,17 @@ path = 'mytheme' source = 'assets' target = 'assets' [[module.mounts]]+source = 'content'+target = 'content'+[[module.mounts]] source = 'projectmountroot' target = 'assets/projectmountroot'+[[module.mounts]]+source = 'projectmountparent/subdir'+target = 'assets/projectmountparent'+[[module.mounts]]+source = '_build/includes/project-a'+target = 'content/project-a' -- themes/mytheme/hugo.toml -- [[module.mounts]] source = 'assets'@@ -54,10 +70,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 {{ .Content }}{{ else }}FAIL{{ end }}+{{ with resources.Get "projectmountparent/rootdirfile3.txt"}}OK {{ .Content }}{{ else }}FAIL{{ end }}+{{ with site.GetPage "/project-a/extpage" }}OK {{ .Title }}{{ 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 "theme*/**"}}FAIL {{ .Publish }}{{ else }}OK{{ end }} Page: {{ .RelPermalink }}|{{ .Content }}|  {{/* os template package. */}}@@ -85,6 +103,11 @@ Content. Root Content. -- assets/myassets/myfile.txt -- My file.+-- _build/includes/.keep --+-- externalproject/extpage.md --+---+title: External Page+--- -- rootdir/rootdirfile1.txt -- Rootdirfile1 content. -- rootdir/rootdirfile2.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. */}}