Mitigation Strategy: Secure Module Loading (laminas-mvc)
Mitigation Strategy: Restrict dynamic module loading within the laminas-mvc
ModuleManager
.
-
Description:
- Whitelist (Dynamic Loading): If your application dynamically loads modules (which is a feature of
laminas-mvc
'sModuleManager
), strictly limit which modules can be loaded. Create a whitelist of allowed module names within your application code. Never load a module directly from user input without checking it against this whitelist. This is crucial becauselaminas-mvc
handles module loading.- Example (Conceptual, within a controller or a custom
ModuleManager
listener):$allowedModules = ['MyModule', 'AnotherModule', 'SafeModule']; $moduleToLoad = $request->getPost('module_name'); // Get module name from request (VERY DANGEROUS without validation) if (in_array($moduleToLoad, $allowedModules)) { // Load the module using the laminas-mvc ModuleManager $moduleManager = $this->getServiceLocator()->get('ModuleManager'); // Get ModuleManager from ServiceManager $moduleManager->loadModule($moduleToLoad); } else { // Handle the error (e.g., log, display an error message, throw an exception) }
- Example (Conceptual, within a controller or a custom
- Disable Unused Modules: Remove or disable any modules that are not actively used. This directly impacts
laminas-mvc
because it manages the module lifecycle. Editconfig/modules.config.php
(which is read bylaminas-mvc
) to remove unused modules from the list. This reduces the attack surface managed bylaminas-mvc
. - Regular Audits: Periodically review the list of enabled modules in
config/modules.config.php
and the logic that handles module loading (if dynamic loading is used).
- Whitelist (Dynamic Loading): If your application dynamically loads modules (which is a feature of
-
Threats Mitigated:
- Code Injection (High Severity): Prevents attackers from injecting malicious code by loading compromised or malicious modules through the
laminas-mvc
ModuleManager
. - Privilege Escalation (High Severity): A malicious module loaded via
laminas-mvc
could gain access to the application's resources and potentially escalate privileges. - Denial of Service (Medium Severity): A malicious module loaded through
laminas-mvc
could consume excessive resources.
- Code Injection (High Severity): Prevents attackers from injecting malicious code by loading compromised or malicious modules through the
-
Impact:
- Code Injection: Risk significantly reduced (especially with whitelisting).
- Privilege Escalation: Risk significantly reduced.
- Denial of Service: Risk reduced.
-
Currently Implemented:
- Describe how modules are loaded. Example: "Dynamic module loading is not used; modules are loaded statically from
config/modules.config.php
." or "A whitelist is implemented inApplication\Controller\PluginManagerController
to control dynamic module loading."
- Describe how modules are loaded. Example: "Dynamic module loading is not used; modules are loaded statically from
-
Missing Implementation:
- Example: "No whitelist is implemented for dynamic module loading, and module names are taken directly from user input." or "Unused modules are still listed in
config/modules.config.php
."
- Example: "No whitelist is implemented for dynamic module loading, and module names are taken directly from user input." or "Unused modules are still listed in
Mitigation Strategy: Strict Route Definitions and Controller Access Control (laminas-mvc)
Mitigation Strategy: Define precise routes within laminas-mvc
's routing system and enforce controller/action-level access control within controllers managed by laminas-mvc
.
-
Description:
- Specific Routes (laminas-mvc Routing): Avoid overly broad routes in your
module.config.php
files (which configurelaminas-mvc
's routing). Use specific route types (literal, segment, hostname, etc.) and constraints within thelaminas-mvc
routing configuration.- Literal Routes: Prefer literal routes (e.g.,
/users/profile
). - Segment Routes: Use constraints to restrict parameter values within the route definition. Example (in
module.config.php
):'my-route' => [ 'type' => Laminas\Router\Http\Segment::class, // Using laminas-mvc's Segment route 'options' => [ 'route' => '/users/:id', 'constraints' => [ 'id' => '[0-9]+', // Only allow numeric IDs - enforced by laminas-mvc ], 'defaults' => [ 'controller' => Controller\UserController::class, 'action' => 'view', ], ], ],
- Hostname Routes: Use hostname routes to restrict routes to specific domains.
- Regular Expressions: Use regular expressions in constraints for strict parameter patterns.
- Literal Routes: Prefer literal routes (e.g.,
- Controller/Action Access Control (laminas-mvc Controllers): Implement authorization checks within your controller actions, which are managed by
laminas-mvc
. This is in addition to route-level security.laminas-mvc
Controller Logic: Place authorization checks inside the action methods of your controllers (which extendLaminas\Mvc\Controller\AbstractActionController
).- Example (Conceptual - within a
laminas-mvc
controller):namespace MyModule\Controller; use Laminas\Mvc\Controller\AbstractActionController; use Laminas\View\Model\ViewModel; class UserController extends AbstractActionController { public function viewAction() { // Access control check *within the laminas-mvc controller* if (!$this->isAllowed('user', 'view')) { // Hypothetical authorization check return $this->redirect()->toRoute('login'); // Redirect handled by laminas-mvc } // ... (rest of the action logic) return new ViewModel(); // ViewModel is part of laminas-mvc } }
- Avoid Exposing Internal Methods: Do not map routes (in
laminas-mvc
's configuration) to controller methods that are not intended to be directly accessible. - Route Testing (laminas-test): Use
laminas-test
(which integrates withlaminas-mvc
) to thoroughly test your routing configuration. This ensures that only intended routes are accessible and that constraints are working correctly within thelaminas-mvc
context. - Regular Audits: Periodically review your routing configuration (in
module.config.php
files) and access control logic within yourlaminas-mvc
controllers.
- Specific Routes (laminas-mvc Routing): Avoid overly broad routes in your
-
Threats Mitigated:
- Route Hijacking (Medium Severity): Prevents attackers from crafting URLs that match unintended routes within
laminas-mvc
's routing system. - Unauthorized Access (High Severity): Prevents unauthorized users from accessing protected resources or actions by enforcing checks within
laminas-mvc
controllers. - Parameter Manipulation (Medium Severity): Limits the ability of attackers to manipulate route parameters as processed by
laminas-mvc
. - Information Disclosure (Medium Severity): Prevents attackers from discovering internal controller methods.
- Route Hijacking (Medium Severity): Prevents attackers from crafting URLs that match unintended routes within
-
Impact:
- Route Hijacking: Risk significantly reduced with specific route definitions within
laminas-mvc
. - Unauthorized Access: Risk significantly reduced with controller-level access control within
laminas-mvc
controllers. - Parameter Manipulation: Risk reduced with route constraints enforced by
laminas-mvc
. - Information Disclosure: Risk reduced.
- Route Hijacking: Risk significantly reduced with specific route definitions within
-
Currently Implemented:
- Describe how routes are defined and how access control is implemented within your
laminas-mvc
controllers. Example: "Routes are defined using segment routes with regular expression constraints inmodule.config.php
. Access control checks are performed within each controller action using a custom authorization service."
- Describe how routes are defined and how access control is implemented within your
-
Missing Implementation:
- Example: "No controller-level access control is implemented within
laminas-mvc
controllers; authorization relies solely on routing." or "Some routes use overly broad wildcard patterns inmodule.config.php
." or "Nolaminas-test
tests are in place to verify routing behavior."
- Example: "No controller-level access control is implemented within
Mitigation Strategy: Secure Event Manager Usage (laminas-mvc)
Mitigation Strategy: Validate event data and restrict listener registration within the laminas-mvc
EventManager
.
-
Description:
- Validate Event Data (laminas-mvc Events): Treat data passed through
laminas-mvc
events as untrusted. Within your event listeners that are attached to thelaminas-mvc
EventManager
, validate any data received from the event object. This is crucial becauselaminas-mvc
uses its ownEventManager
extensively.- Example (Conceptual - within a listener attached to the
laminas-mvc
EventManager
):// In a module's Module.php, attaching to the laminas-mvc EventManager: public function onBootstrap(MvcEvent $e) { $eventManager = $e->getApplication()->getEventManager(); // Get the laminas-mvc EventManager $eventManager->attach(MvcEvent::EVENT_DISPATCH, [$this, 'onDispatch'], 100); } public function onDispatch(MvcEvent $e) { $routeMatch = $e->getRouteMatch(); // Get data from the laminas-mvc MvcEvent if ($routeMatch) { $controller = $routeMatch->getParam('controller'); // ... (validate $controller - it's data from a laminas-mvc event!) } }
- Example (Conceptual - within a listener attached to the
- Restrict Listener Registration (laminas-mvc EventManager): Avoid registering listeners to the
laminas-mvc
EventManager
based on user input.- Whitelist (Dynamic Registration): If you must dynamically register listeners to the
laminas-mvc
EventManager
, maintain a whitelist of allowed listener classes or callables. - Configuration-Based Registration: Prefer registering listeners through configuration (e.g., in
module.config.php
using thelisteners
key undercontrollers
orservice_manager
) rather than dynamically. This is the standard way to interact withlaminas-mvc
's event system.
- Whitelist (Dynamic Registration): If you must dynamically register listeners to the
- Limit Event Propagation (laminas-mvc Events): Use event priorities and the
stopPropagation()
method within thelaminas-mvc
event flow to control event propagation. Prevent unintended listeners from being triggered.- Priorities: Assign priorities when attaching listeners to the
laminas-mvc
EventManager
. - stopPropagation(): Call
$e->stopPropagation()
within a listener (where$e
is anMvcEvent
) to prevent subsequent listeners from being executed within thelaminas-mvc
event cycle.
- Priorities: Assign priorities when attaching listeners to the
- Regular Audits: Periodically review event listeners attached to the
laminas-mvc
EventManager
.
- Validate Event Data (laminas-mvc Events): Treat data passed through
-
Threats Mitigated:
- Code Injection (High Severity): Prevents attackers from injecting malicious code through event listeners attached to the
laminas-mvc
EventManager
. - Data Tampering (Medium Severity): Prevents attackers from modifying data passed through
laminas-mvc
events. - Denial of Service (Medium Severity): A malicious listener attached to
laminas-mvc
's events could consume resources. - Unexpected Behavior (Low Severity): Improperly handled
laminas-mvc
events can lead to unexpected application behavior.
- Code Injection (High Severity): Prevents attackers from injecting malicious code through event listeners attached to the
-
Impact:
- Code Injection: Risk significantly reduced with restricted listener registration and data validation within the
laminas-mvc
context. - Data Tampering: Risk reduced with data validation.
- Denial of Service: Risk reduced.
- Unexpected Behavior: Risk reduced.
- Code Injection: Risk significantly reduced with restricted listener registration and data validation within the
-
Currently Implemented:
- Describe how event listeners are registered and how event data is handled specifically for
laminas-mvc
events. Example: "Listeners are registered via configuration inmodule.config.php
to thelaminas-mvc
EventManager
. Event data fromMvcEvent
is validated within listeners."
- Describe how event listeners are registered and how event data is handled specifically for
-
Missing Implementation:
- Example: "Event data from
MvcEvent
is not validated in any listeners attached to thelaminas-mvc
EventManager
." or "Dynamic listener registration to thelaminas-mvc
EventManager
is used without a whitelist."
- Example: "Event data from