Skip to content

fix(export): block path traversal in resourceResolver#462

Merged
xiaolai merged 1 commit intomainfrom
fix/path-traversal-resource-resolver
Mar 18, 2026
Merged

fix(export): block path traversal in resourceResolver#462
xiaolai merged 1 commit intomainfrom
fix/path-traversal-resource-resolver

Conversation

@claude
Copy link
Contributor

@claude claude bot commented Mar 18, 2026

Summary

  • Sanitize relative image src paths in resolveRelativePath() to prevent path traversal (../) from exfiltrating files outside the document directory during export
  • After joining and normalizing the resolved path, verify it stays within baseDir; return null (treated as missing) when traversal is detected
  • Decode percent-encoded sequences (%2F) before joining to block encoded traversal variants

Closes #455

Test plan

  • New unit tests: resolveRelativePath blocks ../../.ssh/id_rsa, blocks encoded ..%2F..%2F, allows subdir/../photo.png (stays within base)
  • New integration test: resolveResources treats traversal images as missing, never calls copyFile
  • pnpm check:all passes (lint + coverage + build)

🤖 Generated with Claude Code

Sanitize relative image paths during export to prevent file exfiltration
outside the document directory. Resolves and normalizes paths before use,
rejecting any that escape the base directory.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude claude bot enabled auto-merge (squash) March 18, 2026 09:45
@xiaolai xiaolai merged commit 4622646 into main Mar 18, 2026
3 checks passed
@xiaolai xiaolai deleted the fix/path-traversal-resource-resolver branch March 20, 2026 22:13
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.

[audit] export: path traversal in resourceResolver allows file exfiltration outside document directory

1 participant