matthewchivers / dodl

A cli tool that automates the creation and organisation of structured documents using custom templates; Focus on writing, not setup.
MIT License
1 stars 0 forks source link

[Feature] Validate directory patterns #29

Closed matthewchivers closed 2 weeks ago

matthewchivers commented 2 weeks ago

Summary

Add validation for directory patterns to detect and prevent invalid or potentially dangerous path characters. This feature would provide error-checking for paths specified in configuration files, reducing the risk of errors or security vulnerabilities due to special characters in paths.

Motivation

Currently, directory patterns allow users to specify paths without validation. This leaves room for potential issues, such as unintentional relative paths (..), forward or backward slashes (/, \), and other special characters that may cause errors or introduce security concerns. Adding path validation will:

Proposed Solution

Implement a validation function within the path-handling logic that checks directory patterns for the following characters:

When an invalid character is detected, the program should:

  1. Display an error message specifying the character and location in the pattern.
  2. Suggest allowed characters to help the user correct the pattern? (maybe)

Example Configuration Check:

Given the following configuration:

directory_pattern: "../{{ .Now | date \"2006\" }}/{{ .Now | date \"01\" }}/scrum"

The program would output:

Error: Invalid character .. found in directory pattern. Relative paths are not allowed

Alternatives Considered

  1. Allowing All Characters with Warnings:

    • Pros: Provides flexibility for advanced users.
    • Cons: Still allows potential security issues; may be confusing if users miss warnings.

Additional Context

Checklist

matthewchivers commented 2 weeks ago

PR #35 closes this issue as it adds path validation 👍