Mitigation Strategy: Restrict Search Scope
Description:
- Identify the Target Directory: Before running
fd
, pinpoint the most specific directory that contains the files you need. - Use Absolute or Relative Paths: When specifying the directory as an argument to
fd
, use either an absolute path (e.g.,fd . /home/user/project/data
) or a relative path (e.g.,fd . data/
) that clearly defines the starting point. - Avoid Defaulting to Broad Searches: Do not rely on
fd
's default behavior of searching the current directory if no path is provided, unless you are absolutely certain. Explicitly provide a path argument.
List of Threats Mitigated:
- Unintentional Exposure of Sensitive Files/Directories (Severity: High): Reduces the likelihood of
fd
accessing and revealing confidential data. - Denial of Service (DoS) via Resource Exhaustion (Severity: Medium): Limits the amount of data
fd
needs to process.
Impact:
- Unintentional Exposure: Significantly reduces the risk.
- DoS: Moderately reduces the risk.
Currently Implemented: (Example - Replace with your project's specifics)
Missing Implementation: (Example - Replace with your project's specifics)
Mitigation Strategy: Precise Wildcards and Regular Expressions
Description:
- Understand
fd
's Pattern Matching: Usefd
's glob patterns (default) or regular expressions (-e
or--regex
) consciously. - Avoid Overly Broad Patterns: Refrain from using
*
or.*
at the beginning of a pattern passed tofd
unless absolutely necessary. - Use Specific File Extensions: Include file extensions in the pattern (e.g.,
fd '*.txt'
,fd -e '^config\.yaml$'
). - Anchor Regular Expressions: When using
-e
, use anchors (^
and$
) to prevent unintended matches. - Escape Special Characters: Escape characters with special meaning in patterns passed to
fd
. - Prefer Glob Patterns: If possible, use glob patterns instead of regular expressions with
fd
.
List of Threats Mitigated:
- Unintentional Exposure of Sensitive Files/Directories (Severity: High):
- Denial of Service (DoS) via Resource Exhaustion (Severity: Medium):
Impact:
- Unintentional Exposure: High impact.
- DoS: Medium impact.
Currently Implemented: (Example)
Missing Implementation: (Example)
Mitigation Strategy: Explicitly Exclude Sensitive Directories
Description:
- Identify Sensitive Directories: Create a list of directories to exclude.
- Use
-E
or--exclude
: Use the-E
or--exclude
option withfd
to explicitly exclude these directories. Example:fd . -E .git -E .ssh
. - Multiple Exclusions: Use multiple
-E
options or comma-separated values.
List of Threats Mitigated:
- Unintentional Exposure of Sensitive Files/Directories (Severity: High):
Impact:
- Unintentional Exposure: High impact.
Currently Implemented: (Example)
Missing Implementation: (Example)
Mitigation Strategy: Avoid -H
and -I
Unless Necessary
Description:
- Understand the Risks:
-H
(or--hidden
) and-I
(or--no-ignore
) bypass ignore files. - Justify Use: Only use these
fd
options when strictly required. - Double-Check: If using
-H
or-I
, re-evaluate the search scope and exclusions.
List of Threats Mitigated:
- Unintentional Exposure of Sensitive Files/Directories (Severity: High):
Impact:
- Unintentional Exposure: High impact.
Currently Implemented: (Example)
Missing Implementation: (Example)
Mitigation Strategy: Avoid -x
and -X
with Untrusted Input
Description:
- Strongly Discourage: Avoid using
-x
or--exec
and-X
or--exec-batch
fd
options with untrusted input. - Explore Alternatives: Consider alternatives to these
fd
options.
List of Threats Mitigated:
- Command Injection via
fd
's-x
/--exec
and-X
/--exec-batch
Options (Severity: Critical):
Impact:
- Command Injection: Eliminates the risk (if untrusted input is avoided).
Currently Implemented: (Example)
Missing Implementation: (Example)
Mitigation Strategy: Use a Whitelist of Allowed Commands (for -x
and -X
)
Description:
- Define Allowed Commands: Create a whitelist for commands used with
fd
's-x
or-X
options. - Validate: Check if the command passed to
-x
or-X
is in the whitelist.
List of Threats Mitigated:
- Command Injection via
fd
's-x
/--exec
and-X
/--exec-batch
Options (Severity: Critical):
Impact:
- Command Injection: Significantly reduces the risk.
Currently Implemented: (Example)
Missing Implementation: (Example)
Mitigation Strategy: Parameterize Commands (for -x
and -X
)
Description:
- Use Placeholders: Use placeholders (like
{}
) within the command string passed tofd
's-x
or-X
. - Let
fd
Handle Substitution: Rely onfd
to substitute placeholders. Example:fd -x mycommand {}
. - Avoid String Concatenation: Do not build the command string manually.
List of Threats Mitigated:
- Command Injection via
fd
's-x
/--exec
and-X
/--exec-batch
Options (Severity: Critical):
Impact:
- Command Injection: Significantly reduces the risk.
Currently Implemented: (Example)
Missing Implementation: (Example)
Mitigation Strategy: Limit Search Depth
Description:
- Assess Maximum Depth: Determine the maximum directory depth needed.
- Use
-d
or--max-depth
: Use the-d
or--max-depth
fd
option. Example:fd -d 3 .
.
List of Threats Mitigated:
- Denial of Service (DoS) via Resource Exhaustion (Severity: Medium):
- Unintentional Exposure of Sensitive Files/Directories (Severity: Low):
Impact:
- DoS: Medium impact.
- Unintentional Exposure: Low impact.
Currently Implemented: (Example)
Missing Implementation: (Example)
Mitigation Strategy: Disable Symlink Following When Unnecessary
Description:
- Assess Need: Determine if symlink following is required.
- Use
-L
or--no-follow-symlinks
: Use the-L
or--no-follow-symlinks
fd
option to disable it.
List of Threats Mitigated:
- Symlink Following Issues (Severity: Medium):
- Unintentional Exposure of Sensitive Files/Directories (Severity: Medium):
Impact:
- Symlink Following Issues: High impact.
- Unintentional Exposure: Medium impact.
Currently Implemented: (Example)
Missing Implementation: (Example)