Skip to content

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

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

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

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

1 participant