CVE-2019-5477

9.8 CRITICAL

📋 TL;DR

CVE-2019-5477 is a command injection vulnerability in Nokogiri v1.10.3 and earlier that allows remote code execution via unsafe user input passed to the undocumented `Nokogiri::CSS::Tokenizer#load_file` method. This affects Ruby applications using vulnerable Nokogiri versions to parse CSS with untrusted input. The vulnerability originates from Rexical gem v1.0.6 and earlier, which Nokogiri uses for CSS parsing.

💻 Affected Systems

Products:
  • Nokogiri
  • Rexical
Versions: Nokogiri <= v1.10.3, Rexical <= v1.0.6
Operating Systems: All operating systems running Ruby
Default Config Vulnerable: ✅ No
Notes: Only vulnerable when using the undocumented `Nokogiri::CSS::Tokenizer#load_file` method with untrusted user input as filename parameter.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Full system compromise with attacker gaining shell access and executing arbitrary commands as the application user.

🟠

Likely Case

Remote code execution leading to data theft, privilege escalation, or lateral movement within the environment.

🟢

If Mitigated

Limited impact if proper input validation and sandboxing prevent command injection attempts.

🌐 Internet-Facing: HIGH
🏢 Internal Only: MEDIUM

🎯 Exploit Status

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

Exploitation requires specific application code patterns but is straightforward once those conditions are met.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: Nokogiri v1.10.4+, Rexical v1.0.7+

Vendor Advisory: https://github.com/sparklemotion/nokogiri/issues/1915

Restart Required: Yes

Instructions:

1. Update Nokogiri gem: `gem update nokogiri` 2. Verify version: `gem list nokogiri` shows v1.10.4 or higher 3. Restart application services

🔧 Temporary Workarounds

Input Validation

all

Validate and sanitize all user input before passing to Nokogiri CSS parsing functions

Avoid load_file Method

all

Do not use the undocumented Nokogiri::CSS::Tokenizer#load_file method with user-controlled input

🧯 If You Can't Patch

  • Implement strict input validation and sanitization for all CSS parsing inputs
  • Run application with minimal privileges and in isolated containers to limit impact

🔍 How to Verify

Check if Vulnerable:

Check Nokogiri version: `gem list | grep nokogiri` - versions <=1.10.3 are vulnerable

Check Version:

gem list | grep nokogiri

Verify Fix Applied:

Confirm Nokogiri version >=1.10.4: `gem list | grep nokogiri`

📡 Detection & Monitoring

Log Indicators:

  • Unusual subprocess executions from Ruby application
  • Failed command injection attempts in application logs

Network Indicators:

  • Outbound connections from application to unexpected destinations

SIEM Query:

process.name:ruby AND cmdline:*load_file* AND cmdline:*|* OR cmdline:*;* OR cmdline:*`*

🔗 References

📤 Share & Export