Fix Shadow API Exposure in Yii
Shadow APIs in Yii frameworks are often the result of lazy ActiveController implementations or 'magical' routing. When you extend ActiveController, Yii automatically exposes a full CRUD suite (index, view, create, update, delete, options). If these aren't explicitly disabled or protected by RBAC, you're running undocumented endpoints that attackers will discover via fuzzing. This is a massive leak of internal state and data.
The Vulnerable Pattern
namespace app\controllers;
use yii\rest\ActiveController;
/**
- VULNERABLE: Exposes all CRUD operations by default.
Attackers can guess /users/delete/1 even if the UI doesn’t use it. */ class UserController extends ActiveController { public $modelClass = ‘app\models\User’; }
The Secure Implementation
To eliminate Shadow API exposure in Yii: 1. Override the 'actions()' method and 'unset' any default REST actions that are not strictly necessary. 2. Configure 'enableStrictParsing => true' in your 'urlManager' component; this forces Yii to only recognize routes explicitly defined in your ruleset, preventing the framework from auto-generating routes for every controller. 3. Layer 'AccessControl' and 'VerbFilter' behaviors to ensure that even if a route exists, it is gated by identity and restricted to the correct HTTP method (e.g., preventing a GET request from hitting a state-changing endpoint).
namespace app\controllers;use yii\rest\ActiveController; use yii\filters\auth\HttpBearerAuth; use yii\filters\AccessControl; use yii\filters\VerbFilter;
class UserController extends ActiveController { public $modelClass = ‘app\models\User’;
public function actions() { $actions = parent::actions(); // Explicitly disable shadow endpoints not required by the business logic unset($actions['delete'], $actions['create'], $actions['update']); return $actions; } public function behaviors() { $behaviors = parent::behaviors(); // Enforce Authentication $behaviors['authenticator'] = [ 'class' => HttpBearerAuth::class, ]; // Enforce RBAC/Access Control $behaviors['access'] = [ 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, 'actions' => ['index', 'view'], 'roles' => ['@'], // Only authenticated users ], ], ]; // Hard-restrict HTTP Verbs $behaviors['verbs'] = [ 'class' => VerbFilter::class, 'actions' => [ 'index' => ['GET'], 'view' => ['GET'], ], ]; return $behaviors; }
}
Your Yii API
might be exposed to Shadow API Exposure
74% of Yii apps fail this check. Hackers use automated scanners to find this specific flaw. Check your codebase before they do.
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.