ActiveRecord-JDBC-Adapter, SQL Injection, CVE-2023-22796 (Critical)

Listen to this Post

The vulnerability exists within the `quote_string` method in lib/arjdbc/jdbc/adapter.rb. This method is responsible for escaping single quotes in user input before it is used in SQL queries to prevent injection. The flawed implementation uses `sql.gsub(“‘”, “””)` to escape quotes. However, this simple string replacement is insufficient when dealing with multibyte character encodings like GBK or BIG5. In these encodings, certain multibyte characters include the single quote byte (0x27) as their trailing byte. An attacker can craft input where a multibyte sequence ends with 0x27, which the `gsub` incorrectly splits and escapes. This corrupts the byte sequence, causing the database to interpret the following attacker-controlled bytes as part of the SQL command. By strategically placing these sequences, an attacker can “smuggle” unescaped single quotes or other SQL meta-characters into the final query, breaking out of the string context and executing arbitrary SQL commands on the database server.
Platform: ActiveRecord-JDBC-Adapter
Version: < 50.7
Vulnerability: SQL Injection
Severity: Critical
Date: 2023-01-18

Prediction: 2023-02-15

What Undercode Say:

Analytics:

grep -r "gsub.'.''" lib/arjdbc/jdbc/adapter.rb
find . -name ".rb" -type f -exec grep -l "quote_string" {} \;
bundle show activerecord-jdbc-adapter

How Exploit:

Crafted payload exploiting multibyte encoding
Example for GBK-like encoding: 0xbf27 becomes ' in the query.
payload = "\xbf\x27 OR 1=1--"
User.where("name = '{payload}'").to_sql
Resulting corrupt query may bypass quoting.

Protection from this CVE:

Update gem immediately.

Use parameterized queries.

Validate/sanitize all inputs.

Avoid dynamic SQL.

Impact:

Data Theft

Data Manipulation

Authentication Bypass

Full Compromise

🎯Let’s Practice Exploiting & Learn Patching For Free:

Sources:

Reported By: github.com
Extra Source Hub:
Undercode

🔐JOIN OUR CYBER WORLD [ CVE News • HackMonitor • UndercodeNews ]

💬 Whatsapp | 💬 Telegram

📢 Follow DailyCVE & Stay Tuned:

𝕏 formerly Twitter 🐦 | @ Threads | 🔗 Linkedin Featured Image

Scroll to Top