CVE-2022-21223

8.1 HIGH

📋 TL;DR

CVE-2022-21223 is a command injection vulnerability in cocoapods-downloader that allows attackers to execute arbitrary commands on systems using vulnerable versions. The vulnerability occurs when the download function passes user-controlled parameters to the 'hg clone' command without proper sanitization. This affects developers and systems using CocoaPods with Mercurial (hg) repositories.

💻 Affected Systems

Products:
  • cocoapods-downloader
Versions: All versions before 1.6.2
Operating Systems: All platforms where CocoaPods is used (macOS, Linux, Windows)
Default Config Vulnerable: ⚠️ Yes
Notes: Only affects systems using Mercurial (hg) repositories with CocoaPods. Systems using only Git or other SCM systems are not vulnerable.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Full system compromise allowing arbitrary command execution with the privileges of the CocoaPods process, potentially leading to data theft, ransomware deployment, or complete system takeover.

🟠

Likely Case

Arbitrary command execution in build/CI/CD environments, potentially compromising build artifacts, stealing credentials, or pivoting to other systems in the network.

🟢

If Mitigated

Limited impact if proper network segmentation, least privilege principles, and input validation are implemented, potentially containing the attack to isolated build environments.

🌐 Internet-Facing: MEDIUM - Exploitation requires the system to process malicious hg repository URLs, which could come from compromised dependencies or malicious package sources.
🏢 Internal Only: MEDIUM - Internal build systems and developer workstations using vulnerable versions are at risk, especially if processing untrusted dependencies.

🎯 Exploit Status

Public PoC: ⚠️ Yes
Weaponized: LIKELY
Unauthenticated Exploit: ⚠️ Yes
Complexity: LOW

Exploitation is straightforward by crafting malicious hg repository URLs with command injection payloads. The vulnerability is well-documented with public proof-of-concept examples.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: 1.6.2 and later

Vendor Advisory: https://github.com/CocoaPods/cocoapods-downloader/pull/127

Restart Required: No

Instructions:

1. Update cocoapods-downloader gem: 'gem update cocoapods-downloader'
2. Verify version is 1.6.2 or higher: 'gem list cocoapods-downloader'
3. Update Gemfile.lock if using Bundler: 'bundle update cocoapods-downloader'

🔧 Temporary Workarounds

Disable Mercurial support

all

Temporarily disable hg repository support in CocoaPods configuration

export COCOAPODS_DISABLE_HG=1

Use Git repositories only

all

Configure CocoaPods to use only Git repositories instead of Mercurial

Modify Podfile to use git sources only

🧯 If You Can't Patch

  • Implement strict input validation for repository URLs in CI/CD pipelines
  • Run CocoaPods in isolated containers with minimal privileges and network access

🔍 How to Verify

Check if Vulnerable:

Check cocoapods-downloader version: 'gem list cocoapods-downloader | grep cocoapods-downloader'

Check Version:

gem list cocoapods-downloader | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+'

Verify Fix Applied:

Verify version is 1.6.2 or higher: 'gem list cocoapods-downloader' should show version >= 1.6.2

📡 Detection & Monitoring

Log Indicators:

  • Unusual hg clone commands with suspicious flags
  • Process execution from CocoaPods with unexpected arguments
  • Failed hg repository downloads with unusual parameters

Network Indicators:

  • Outbound connections from build systems to unexpected destinations
  • hg protocol traffic with unusual payloads

SIEM Query:

process.name:"hg" AND cmdline:"clone" AND cmdline:("||" OR ";" OR "`" OR "$")

🔗 References

📤 Share & Export