fix(obsidian): prevent path traversal in exporter file path construction#423
Merged
Conversation
Sanitize project and type path components before filepath.Join to strip separators and dot-dot sequences, and add a post-join containment check that rejects any resolved path escaping the vault/engram root (issue #180).
There was a problem hiding this comment.
Pull request overview
This PR hardens the Obsidian exporter against path traversal when constructing observation export paths under {vault}/engram.
Changes:
- Adds
sanitizePathComponent()for project/type path components. - Applies sanitized project/type values when building observation file paths.
- Adds traversal-prevention tests covering malicious project/type values.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
internal/obsidian/exporter.go |
Sanitizes observation export path components and adds containment validation. |
internal/obsidian/exporter_test.go |
Adds security regression coverage for traversal-style project/type inputs. |
internal/obsidian/testhelpers_test.go |
Adds test helpers for walking files and checking path containment. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+231
to
+235
| // Containment check: reject any path that escapes engRoot after cleaning. | ||
| cleanRoot := filepath.Clean(engRoot) | ||
| cleanPath := filepath.Clean(absPath) | ||
| if !strings.HasPrefix(cleanPath, cleanRoot+string(filepath.Separator)) { | ||
| result.Errors = append(result.Errors, fmt.Errorf("unsafe path rejected (would escape export root): %s", cleanPath)) |
rubenqc
added a commit
to cloudopstudio/engram
that referenced
this pull request
Jun 11, 2026
…ogramming#423, Gentleman-Programming#429, Gentleman-Programming#428, Gentleman-Programming#451, Gentleman-Programming#453) Conflict resolution: - schema_pg.go: RLS global-scope migration renumbered v10 -> v12 (master already had v10 memory_relations and v11 decay columns) - server.go: kept GET /sessions/{id} and GET /project/current routes, applied requireAuth to DELETE /sessions/{id} and POST /projects/migrate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
internal/obsidian/exporter.gobuilt output paths by passing*obs.Projectandobs.Typedirectly tofilepath.Joinwith no sanitization, allowing values like../../etcor/etcto write files outside the intended{vault}/engram/export root.Adds
sanitizePathComponent()which replaces path separators and..sequences before the join, followed by afilepath.Clean+ prefix containment check that rejects any path that still escapes the root. Minimal change, no behavior difference for well-formed project/type values.Closes #180
Test plan
go test ./internal/obsidian/ -run TestPathTraversalPrevention -v— 6 subtests (dotdot in project/type/both, absolute path in project/type, nested traversal), all passgo test ./... && go vet ./... && go build ./...— clean