How to override a middleware

Is that possible to override a middleware? I’m trying to implement a plugin for permission control on tasks inside a big project and I need to control task edit or other pages.

It seems in Kanboard design there’s not possible to add or override a Middleware without touching the app folder of source code.
However I’ve implement a dirty work around which I hope we can avoid in near feature by adding Middleware registration feature in core Kanboard code.
My work around is to write a class with exact same name and namespace of selected middleware and modifing methods that we need after that including the PHP file in Plugin.php manually.

Any comment on this work around or suggesting a better way?

Give me an example, of the file you are overriding.


namespace Kanboard\Middleware;

use Kanboard\Core\Controller\AccessForbiddenException;
use Kanboard\Core\Controller\BaseMiddleware;

 * Class ProjectAuthorizationMiddleware
 * @package Kanboard\Middleware
 * @author  Frederic Guillot
class ProjectAuthorizationMiddleware extends BaseMiddleware
     * Execute middleware
    public function execute()
        $project_id = $this->request->getIntegerParam('project_id');
        $task_id = $this->request->getIntegerParam('task_id');

	if($task_id > 0 && !$this->helper->user->hasTaskAccess($task_id)){
	    throw new AccessForbiddenException();

        if ($task_id > 0 && $project_id === 0) {
            $project_id = $this->taskFinderModel->getProjectId($task_id);

        if ($project_id > 0 && ! $this->helper->user->hasProjectAccess($this->router->getController(), $this->router->getAction(), $project_id)) {
            throw new AccessForbiddenException();


Sorry, not what I meant. I meant how did you try to override it?

Did you try

            $this->container['ProjectAuthorizationMiddleware'] = $this->container->factory(function ($c) {
                return new YourNewProjectAuthorizationMiddlewareClass($c);

in your Plugin.php

It might not actually work, but worth a try.

No, Your code didn’t work. while the manual include worked for me.