Skip to content

Harden local image reading - #75

Merged
mapitman merged 1 commit into
mainfrom
bugfix/harden-image-reading
Oct 14, 2026
Merged

mapitman merged 1 commit into
mainfrom
bugfix/harden-image-reading

Conversation

@mapitman

Copy link
Copy Markdown
Owner
  • Only allowlisted image extensions are opened. Other files, such as keys and configs, are never read.
  • Symlinks are resolved before the path check.
  • The parent-directory check uses filepath.Rel (fixes the docs vs docs-secret prefix match).
  • Only regular files are read, and the 10MB cap applies during the read.
  • The 3-level .. allowance stays, so images in a sibling directory still work.
  • Behavior change: content sniffing is removed, so extensionless images are no longer embedded.
  • Updates CLAUDE.md.

Tests cover traversal limits, symlinks, non-image files, directories and the size cap.

Closes #66

Only files with an allowlisted image extension are opened, so a reference such as ../../.ssh/id_rsa is no longer embedded. Symlinks are resolved before the path check, so a link cannot reach outside the allowed area. The parent-directory check now uses filepath.Rel instead of a string prefix, which also removes the sibling-directory prefix match. Only regular files are read, and the size cap applies while reading, not only to the stat result.

The 3-level parent allowance stays, because markdown repos often keep images in a sibling directory.

Content sniffing for unknown extensions is gone: extensionless images are no longer embedded.

Closes #66
@mapitman
mapitman merged commit 320e325 into main Oct 14, 2026
2 checks passed
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.

Harden local image reading

1 participant