Skip to content

Fix symlink validation for canonical project roots - #177

Open
Akimbo92i wants to merge 1 commit into
git-pkgs:mainfrom
Akimbo92i:fix/175-canonicalize-symlink-root
Open

Fix symlink validation for canonical project roots#177
Akimbo92i wants to merge 1 commit into
git-pkgs:mainfrom
Akimbo92i:fix/175-canonicalize-symlink-root

Conversation

@Akimbo92i

Copy link
Copy Markdown

Summary

Allow safeReadFile to read internal file symlinks when the project root path itself contains symlinks, while preserving rejection of targets outside the project root.

Changes

  • Canonicalize both the candidate path and project root before comparing them.
  • Use filepath.Rel path semantics for the containment check and propagate path-resolution errors.
  • Add regression coverage for absolute and relative symlinked roots, external targets, and regular files.

Testing

Verified during the approved review:

  • go test -run '^TestSafeReadFileSymlinks$' -count=1 -v ./detect
  • go test -race -count=1 ./...
  • go build ./...
  • go vet ./...
  • golangci-lint run
  • git diff --check origin/main

Related Issue

Fixes #175

@Akimbo92i
Akimbo92i marked this pull request as ready for review September 7, 2026 21:17

@abhinavgautam01 abhinavgautam01 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and tested locally. This correctly fixes #175 for both absolute and relative symlinked roots while preserving rejection of external targets. The regression tests fail before the fix and pass afterward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

safeReadFile rejects internal symlinks when the project root path contains symlinks

2 participants