Back to skill

Security audit

Freqtrade Tools

Security checks for vulnerabilities and agentic risk

Overview

This Freqtrade helper skill is mostly purpose-aligned, but its Windows batch examples include unsafe command construction and its trading-bot control shortcuts can affect live services without built-in safeguards.

Review before installing, especially on Windows. Prefer the PowerShell functions over the cmd .bat examples, add strict numeric validation for DAYS if you use batch files, and add confirmations or separate dry-run/live commands before using ftstart, ftstop, or ftrestart with a live trading bot.

Vulnerability Patterns
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (2)

T09 · Insecure Skill Coding Practices

Error
Location
references/windows-equivalents.md:147
Finding

PowerShell Command Injection Through Unvalidated DAYS in ftdata.bat

Content
View full analysis

Vulnerability Details

File Location: references/windows-equivalents.md, lines 147–166
Vulnerability Type: PowerShell command injection through unsafe batch-variable interpolation
Risk Level: High

Vulnerable Code

batch
REM Parameters: ftdata.bat PAIR DAYS TIMEFRAME [--erase]
set PAIR=%~1
if "%PAIR%"=="" set PAIR=BTC/USDT
set DAYS=%~2
if "%DAYS%"=="" set DAYS=30
set TIMEFRAME=%~3
if "%TIMEFRAME%"=="" set TIMEFRAME=5m
set ERASE=%~4

REM NOTE: Windows cmd/PowerShell lack bash regex. Validate in PowerShell before calling batch,
REM or add whitelist checks: verify PAIR contains only alphanumeric/slash,
REM TIMEFRAME matches ^\d+(m|h|d)$, and ERASE is empty or "--erase".
REM To prevent injection, always quote variables: "%PAIR%", "%TIMEFRAME%", etc.

REM Calculate start date (DAYS ago)
for /f %%A in ('powershell -Command "(Get-Date).AddDays(-!DAYS!).ToString('yyyyMMdd')"') do (
  set START_DATE=%%A
)

Technical Analysis

The second command-line argument is assigned to DAYS without validating that it is a bounded integer. Because delayed expansion is enabled, !DAYS! is expanded directly into the source text passed to PowerShell -Command.

The variable is therefore interpreted as PowerShell syntax rather than as an isolated data value. An attacker who can influence the second argument can provide PowerShell metacharacters or expression syntax that changes the intended AddDays expression and introduces additional commands.

The comments recommend validating other parameters and quoting Docker arguments, but they neither validate DAYS nor protect the PowerShell source construction. Quoting the overall -Command argument does not make interpolation safe because the resulting content is deliberately parsed by PowerShell.

Attack Path

  1. A user copies the documented ftdata.bat implementation and invokes it in a Command Prompt session.
  2. An attacker, untrusted wrapper ...[truncated 950 chars]
Remediation
View remediation

Remediation Suggestions

  • Validate DAYS before it reaches PowerShell and reject any value containing non-decimal characters.
  • Apply a reasonable positive range, such as 1 through an explicitly documented maximum, to prevent abusive or accidental date ranges.
  • Avoid constructing PowerShell source code by concatenating user input. Pass the value as a separately validated argument and convert it with a strict integer parser.
  • Terminate execution with a nonzero exit code when validation fails.
  • Add security tests covering shell metacharacters, parentheses, quotes, whitespace, negative values, excessively large values, and empty input.

A minimum batch-side validation should ensure the value contains digits only before invocation. A safer design is to perform strict conversion in a dedicated PowerShell script using an integer-typed parameter and invoke that script with an argument rather than embedding the value in -Command.

T09 · Insecure Skill Coding Practices

Error
Location
references/windows-equivalents.md:194
Finding

PowerShell Command Injection Through Unvalidated DAYS in ftback.bat

Content
View full analysis

Vulnerability Details

File Location: references/windows-equivalents.md, lines 194–208
Vulnerability Type: PowerShell command injection through unsafe batch-variable interpolation
Risk Level: High

Vulnerable Code

batch
REM Parameters: ftback.bat STRATEGY DAYS TIMEFRAME [PAIRS]
set STRATEGY=%~1
if "%STRATEGY%"=="" set STRATEGY=SampleStrategy
set DAYS=%~2
if "%DAYS%"=="" set DAYS=30
set TIMEFRAME=%~3
if "%TIMEFRAME%"=="" set TIMEFRAME=5m
set PAIRS=%~4

REM NOTE: Windows cmd/PowerShell lack bash regex. Validate in PowerShell before calling batch,
REM or add whitelist checks: verify STRATEGY contains only alphanumeric/hyphen/underscore,
REM TIMEFRAME matches ^\d+(m|h|d)$, and PAIRS (if present) contains only alphanumeric/slash/comma.
REM To prevent injection, always quote variables: "%STRATEGY%", "%TIMEFRAME%", "%PAIRS%", etc.

for /f %%A in ('powershell -Command "(Get-Date).AddDays(-!DAYS!).ToString('yyyyMMdd')"') do (
  set START_DATE=%%A
)

Technical Analysis

The ftback.bat example repeats the unsafe date-calculation pattern. User-controlled DAYS content is expanded directly inside a PowerShell program supplied through -Command, without first enforcing an integer type or a numeric allowlist.

PowerShell evaluates the expanded value as code within the AddDays expression. Input capable of modifying or terminating that expression can introduce additional executable statements. The quoted Docker arguments later in the batch file do not mitigate this earlier injection point.

Attack Path

  1. A user installs the documented ftback.bat helper.
  2. An attacker or untrusted automation source supplies a crafted second argument.
  3. The batch script assigns that argument to DAYS without validation.
  4. Delayed expansion inserts it into the PowerShell command text used to calculate START_DATE.
  5. PowerShell parses the injected syntax during the for /f command.
  6. A ...[truncated 643 chars]
Remediation
View remediation

Remediation Suggestions

  • Enforce that DAYS is a positive decimal integer before constructing or invoking any PowerShell command.
  • Define and enforce an upper bound appropriate for backtesting.
  • Replace inline PowerShell -Command interpolation with a dedicated PowerShell script that declares DAYS as an integer parameter.
  • Abort with a nonzero status when conversion or range validation fails.
  • Test the helper against metacharacters, expression delimiters, quotes, whitespace, negative values, integer overflow, and unusually large values.
  • Apply the same hardened date-calculation implementation consistently to both ftdata.bat and ftback.bat.
Vulnerability Patterns
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
Findings (2)

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

ftdata accepts --erase and passes it through to freqtrade download-data, enabling deletion of previously stored market data without any extra confirmation or explicit warning during execution. While not code-execution dangerous, this is a destructive operation that can cause loss of local datasets and disrupt backtesting or analysis workflows if invoked accidentally.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The aliases directly invoke docker-compose stop, start, and restart with no confirmation, environment check, or warning at the point of execution. In a live trading context, accidental use can interrupt or resume an active trading bot, potentially causing missed trades, unmanaged positions, or unintended market exposure.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.