GuardAPI Logo
GuardAPI

Fix NoSQL Injection in FuelPHP

NoSQL injection in FuelPHP typically manifests when using the Mongo_Db package. Attackers exploit PHP's associative array handling to inject MongoDB operators like $ne (not equal) or $gt (greater than) into query filters. If your application accepts raw arrays from Input::post() or Input::get() and passes them directly to the database driver, an attacker can bypass authentication or dump the entire collection.

The Vulnerable Pattern

$username = Input::post('username');
$password = Input::post('password');

// VULNERABLE: Passing raw input directly into a filter array. // Attacker sends: password[$ne]=1 $user = Mongo_Db::instance()->where(array( ‘user’ => $username, ‘pass’ => $password ))->get(‘users’);

The Secure Implementation

The exploit occurs because PHP translates 'password[$ne]=1' into an associative array ['password' => ['$ne' => '1']]. When the Mongo_Db driver receives this, it executes a 'not equal' query instead of a literal string match. To remediate, you must strictly cast inputs to strings and avoid passing user-controlled associative arrays to query builders. Using the fluent interface (where('key', 'value')) ensures the value is treated as a literal rather than a query structure.

$username = (string) Input::post('username');
$password = (string) Input::post('password');

// SECURE: Explicit type casting and using key-value pairs in the where method. // This prevents the driver from interpreting input as a nested operator array. $user = Mongo_Db::instance() ->where(‘user’, $username) ->where(‘pass’, $password) ->get(‘users’);

System Alert • ID: 5193
Target: FuelPHP API
Potential Vulnerability

Your FuelPHP API might be exposed to NoSQL Injection

74% of FuelPHP apps fail this check. Hackers use automated scanners to find this specific flaw. Check your codebase before they do.

RUN FREE SECURITY DIAGNOSTIC
GuardLabs Engine: ONLINE

Free Tier • No Credit Card • Instant Report

Verified by Ghost Labs Security Team

This content is continuously validated by our automated security engine and reviewed by our research team. Ghost Labs analyzes over 500+ vulnerability patterns across 40+ frameworks to provide up-to-date remediation strategies.