Skip to content

Security hardening: path validation and test coverage#1

Merged
danieljhkim merged 6 commits intomainfrom
copilot/analyze-codebase-improvements
Feb 1, 2026
Merged

Security hardening: path validation and test coverage#1
danieljhkim merged 6 commits intomainfrom
copilot/analyze-codebase-improvements

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 1, 2026

Proactive security analysis revealed path traversal vulnerabilities and missing input validation. Added defensive checks throughout the codebase and comprehensive test coverage for previously untested core packages.

Security Fixes

Path Traversal Protection

Added validation to prevent directory traversal attacks:

// Before: vulnerable to path traversal
sourcePath := filepath.Join(overlayRoot, relPath)  // relPath could be "../../../etc/passwd"

// After: validated before use
if err := fs.ValidateRelPath(relPath); err != nil {
    return nil, fmt.Errorf("invalid tracked path: %w", err)
}
sourcePath := filepath.Join(overlayRoot, relPath)

Store ID Injection Prevention

Store IDs now validated across all operations (Create, LoadMeta, SaveMeta, LoadTrack, SaveTrack, Delete, OverlayRoot):

func (r *FileStoreRepo) LoadMeta(id string) (*StoreMeta, error) {
    if err := r.fs.ValidateIdentifier(id); err != nil {
        return nil, fmt.Errorf("invalid store ID: %w", err)
    }
    // Prevents: id = "../../../etc" from escaping stores directory
}

Silent Error Handling

Fixed ignored filesystem errors in diff.go that could mask permission issues:

// Before
workspaceExists, _ := e.fs.Exists(workspaceDir)  // error silently dropped

// After
workspaceExists, err := e.fs.Exists(workspaceDir)
if err != nil {
    return nil, fmt.Errorf("failed to check workspace directory: %w", err)
}

Test Coverage

Added 22 unit tests (670 LOC) for previously untested packages:

  • fsops: Path validation (ValidateRelPath, ValidateIdentifier), file operations, edge cases
  • config: Path initialization, MONODEV_ROOT handling, nested directory creation
  • hash: SHA256 consistency, empty files, FakeHasher behavior

Documentation

Added package-level documentation for 7 internal packages (engine, planner, state, stores, fsops, hash, config).

Verification

  • All existing tests pass
  • CodeQL security scan: 0 alerts
  • 856 lines added, 17 files changed

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 5 commits February 1, 2026 04:39
Co-authored-by: danieljhkim <33708658+danieljhkim@users.noreply.github.com>
Co-authored-by: danieljhkim <33708658+danieljhkim@users.noreply.github.com>
Co-authored-by: danieljhkim <33708658+danieljhkim@users.noreply.github.com>
Co-authored-by: danieljhkim <33708658+danieljhkim@users.noreply.github.com>
Co-authored-by: danieljhkim <33708658+danieljhkim@users.noreply.github.com>
Copilot AI changed the title [WIP] Analyze codebase for potential improvements Security hardening: path validation and test coverage Feb 1, 2026
Copilot AI requested a review from danieljhkim February 1, 2026 04:48
@danieljhkim danieljhkim marked this pull request as ready for review February 1, 2026 04:48
Copy link
Copy Markdown
Owner

@danieljhkim danieljhkim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@danieljhkim danieljhkim merged commit cff9c54 into main Feb 1, 2026
1 check passed
@danieljhkim danieljhkim deleted the copilot/analyze-codebase-improvements branch February 1, 2026 04:50
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.

2 participants