Skip to content

Latest commit

 

History

History
58 lines (47 loc) · 6.71 KB

File metadata and controls

58 lines (47 loc) · 6.71 KB

Threat Model Analysis for httpie/cli

  • Description: An attacker provides a malicious URL containing shell commands as part of the URL. The application directly interpolates this URL into the httpie command string without proper escaping or sanitization. The attacker's injected commands are executed on the system running the application, leveraging the shell execution context that httpie is invoked within. Example: http://example.com; rm -rf /.
  • Impact: Complete system compromise. Arbitrary code execution with the privileges of the application. Potential for data theft, system destruction, or further network compromise.
  • Affected CLI Component: The core command-line parsing and execution mechanism of the calling application. The vulnerability lies in how the application constructs the command string passed to the operating system's shell (e.g., via subprocess.run in Python), not within httpie itself. However, httpie is the vehicle for the injection.
  • Risk Severity: Critical
  • Mitigation Strategies:
    • 1. Argument List: Use the subprocess library's API to pass arguments as a list of strings, never a concatenated string. (e.g., subprocess.run(["http", "http://example.com"], ...)).
    • 2. Input Validation: Rigorously validate the URL using a robust URL parsing library. Ensure it conforms to expected schemes, has a valid hostname, and contains no shell metacharacters.
    • 3. Whitelisting: If feasible, whitelist allowed URLs or URL patterns.
  • Description: The application allows users to specify httpie options. An attacker injects malicious options or option values to alter httpie's behavior. This leverages httpie's features for malicious purposes. Examples include --output /etc/passwd (overwriting a system file), --download (saving a malicious file), or using --form with crafted input to bypass intended data formatting.
  • Impact: Varies. Could include data disclosure (reading arbitrary files), file system modification (overwriting/creating files), denial of service (disk space exhaustion), or potentially elevation of privilege.
  • Affected CLI Component: httpie's option parsing and handling. Specifically, options that control file I/O (--output, --download), request modification (--headers, --form, --auth), and similar features.
  • Risk Severity: High
  • Mitigation Strategies:
    • 1. Option Whitelisting: Strictly control which httpie options are allowed. Whitelist permitted options and their allowed values. Reject any unapproved options.
    • 2. Argument Validation: For allowed options, validate the user-provided arguments. For example, if --output is allowed, ensure the filename is safe and avoids path traversal (e.g., ../).
    • 3. Configuration-Driven: Define allowed httpie invocations in a configuration file, rather than dynamically constructing them from user input.
  • Description: An attacker influences the environment variables of the process running the application. They modify httpie-related environment variables (HTTPIE_CONFIG_DIR, HTTPIE_DEFAULT_OPTIONS, http_proxy, https_proxy) to alter httpie's behavior. Example: Setting HTTPIE_DEFAULT_OPTIONS to include --output /tmp/malicious.txt or changing proxy settings.
  • Impact: Depends on the manipulated variable. Can lead to file system modification, data disclosure, or bypassing security controls (like proxy settings).
  • Affected CLI Component: httpie's reliance on environment variables for configuration. Components that read these variables (config loading, proxy handling, default option handling).
  • Risk Severity: High
  • Mitigation Strategies:
    • 1. Environment Sanitization: Before invoking httpie, explicitly clear or set relevant environment variables to known-good values. Do not rely on the inherited environment.
    • 2. Restricted Environment: Run httpie in a restricted environment (e.g., a container) with minimal environment variables.
    • 3. Configuration File: Use a configuration file for httpie settings, rather than environment variables.
  • Description: The application uses httpie's session features (--session or --session-read-only). Session files (containing cookies, authentication data) are stored insecurely (e.g., world-readable directories) or with weak permissions. An attacker accesses these files.
  • Impact: Session hijacking. The attacker can read the session file and impersonate the authenticated user, gaining unauthorized access.
  • Affected CLI Component: httpie's session management (--session, --session-read-only). Components that read/write session data to files.
  • Risk Severity: High
  • Mitigation Strategies:
    • 1. Secure Storage: Store session files in secure, restricted directories with appropriate permissions (only readable/writable by the application's user).
    • 2. Dedicated Storage: Consider a secure storage mechanism (database, key-value store) instead of files.
    • 3. Ephemeral Sessions: Use ephemeral (in-memory) sessions when possible.
    • 4. Short-Lived Sessions: Configure sessions to expire quickly.
  • Description: The application intends to use a proxy, but an attacker manipulates httpie's options or environment to bypass it. This could involve injecting --no-proxy or modifying http_proxy/https_proxy environment variables.
  • Impact: Bypassing security controls. The attacker communicates directly with the target, potentially bypassing firewalls, intrusion detection, or other proxy-enforced security.
  • Affected CLI Component: httpie's proxy handling, influenced by options (--proxy, --no-proxy) and environment variables (http_proxy, https_proxy).
  • Risk Severity: High
  • Mitigation Strategies:
    • 1. Explicit Proxy Configuration: Set proxy settings explicitly in the application's code, not relying on environment variables or user input.
    • 2. Disable Proxy Options: Prevent users from controlling proxy-related options.
    • 3. Environment Sanitization: Clear or explicitly set http_proxy and https_proxy before invoking httpie.