Skip to content

feat: honor MARKITDOWN_SAFE_DIRS env var for configurable safe directories#39

Closed
kdjkdjkdj wants to merge 1 commit into
trsdn:mainfrom
kdjkdjkdj:feat/safe-dirs-env-var
Closed

feat: honor MARKITDOWN_SAFE_DIRS env var for configurable safe directories#39
kdjkdjkdj wants to merge 1 commit into
trsdn:mainfrom
kdjkdjkdj:feat/safe-dirs-env-var

Conversation

@kdjkdjkdj

Copy link
Copy Markdown

Closes #38.

Adds support for the MARKITDOWN_SAFE_DIRS env variable, an os.pathsep-separated list of absolute paths appended to the safe-directory list. Rationale and security notes in #38.

Behavior

  • Variable unset or empty → no change.
  • Separator: : on Unix, ; on Windows (via os.pathsep).
  • Non-existent entries → logged at WARNING, skipped.
  • All entries go through Path.resolve() so the existing prefix-based safety check continues to handle .. inputs correctly.

Parallel to #37

This branch is cut from main (not from the #37 branch) so the PRs are reviewable independently. The only textual overlap with #37 is inside get_safe_working_directories(); once one of the two lands, the other rebases trivially.

…dn#38)

The hardcoded safe-directory list (Path.cwd, ~/Documents,
~/Downloads, ~/Desktop, ~/tmp, tempdir, tests/fixtures) is too
restrictive for real-world use: OneDrive / SharePoint / Dropbox
sync roots, NAS mounts, and project directories on non-system
drives are all outside it, and there is no way to add them.

Read MARKITDOWN_SAFE_DIRS (os.pathsep separated, so ":" on Unix and
";" on Windows) and append each existing path to the safe-dir list.
Non-existent entries are logged at WARNING so typos don't silently
disappear. Paths are resolved via Path.resolve() so the existing
prefix-based security check continues to work against ".." inputs.

Refs: trsdn#38

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@kdjkdjkdj kdjkdjkdj requested a review from trsdn as a code owner April 19, 2026 17:02
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

trsdn added a commit that referenced this pull request Jun 10, 2026
## Summary
- fix OOXML validation so DOCX/XLSX/PPTX ZIP containers are not sent through XML sanitization
- add `MARKITDOWN_SAFE_DIRS` support and make safe-directory initialization robust when home cannot be resolved
- make `tools/list` schema compatible with Claude/Anthropic clients and stop responding to JSON-RPC notifications
- configure stdio for UTF-8/LF startup behavior and stabilize fragile performance thresholds

## Validation
- `python3 -m ruff check .`
- `PATH="/Library/Frameworks/Python.framework/Versions/3.12/bin:$PATH" python3 -m pytest -q`

Refs #36
Refs #38
Closes #40

## Acknowledgements
Thanks to @kdjkdjkdj for opening #37 and #39 with the Windows/MCP protocol fixes and configurable safe-directory work, and to @pagatino-afk for opening #41 with the Office Open XML corruption fix. Those contributions helped identify and validate the issues consolidated in this PR.
@trsdn

trsdn commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Thanks again @kdjkdjkdj for the MARKITDOWN_SAFE_DIRS work in this PR. We consolidated and merged this via #44, including acknowledgement there, so I'm closing this PR as superseded by #44.

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.

Feature request: configurable safe-directory list via MARKITDOWN_SAFE_DIRS env var

2 participants