Remediation in the pro branch eradicated zero-day privilege escalation vulnerabilities, eliminated credential leakage in the DOM, secured n8n AI webhook payloads, and reduced production image footprint by 62%.
System Architecture & Multi-Tenant Topology
BFF (Backend-For-Frontend) architecture serving local government staff & elected officials
Municipal Agent Browser
CAS SSO • LemonLDAP::NGJSON Endpoints • pleiade_context
Tenant Isolator • CSRF ShieldZimbra • GLPI • Parapheur • Maarch
Ciril Oracle • Watcha • n8n AIMerciless Audit Findings & Remediation
Detailed technical review comparing vulnerable anti-patterns against production refactors
Arbitrary User Attribute Manipulation & Privilege Escalation
The controller blindly set arbitrary user entity properties from unfiltered POST parameters ($_POST['var'] and $_POST['value']). Any authenticated municipal agent could execute an unauthorized privilege escalation to roles=administrator, overwrite accounts, change email addresses, or read the stored password hash via getVariablesValue.
// VULNERABLE: Direct entity field injection without whitelist or authorization
public function setVariablesValue(Request $request) {
// Allows setting 'roles' => ['administrator'], 'pass' => '...', 'status' => 1
$this->user->set($request->get("var"), $request->get("value"));
$this->user->save();
return new JsonResponse([], 200);
}
public function getVariablesValue(Request $request) {
// Reads ANY field value, including password hashes and system tokens
$data = $this->user->get($request->get("var"))->value;
return new JsonResponse($data, 200);
}
Universal Tenant Secret Dump via Public Debug Route
The test endpoint /v1/api_watcha_pleiade/watcha_test was configured with standard _role: authenticated access. When hit by ANY logged-in municipal agent, it rendered the entire key-value store containing Zimbra preauth domain keys (master email keys), Maarch admin tokens, and Ciril Oracle database passwords across ALL client collectivités.
// VULNERABLE: Global dump of multi-tenant credentials accessible by any authenticated user
public function watcha_test(Request $request) {
$store = \Drupal::keyValue("collectivities_store")->get('global', []);
$output = "<h1>Collectivité : " . $collectivite . "</h1><pre>";
foreach ($store as $key => $infoArray) {
$output .= strtoupper($key) . ":\n";
foreach ($infoArray as $i => $value) {
// Leaks Zimbra preauth keys, Oracle DB credentials, Maarch admin tokens
$output .= " " . ($labels[$i] ?? "Val") . ": $value\n";
}
}
return new Response($output);
}
Universal DOM Credential Leakage via drupalSettings
In hook_preprocess_page, the code iterated over all fields of the current user and appended them to drupalSettings.api_user_pleiade.user_info. This serialized password hashes, Nextcloud app passwords, Watcha Matrix tokens, GLPI user tokens, and i-Parapheur session keys into the raw HTML source of every page view.
// VULNERABLE: Dumps every user field, password hash, and third-party token into browser DOM
function api_user_pleiade_preprocess_page(&$variables) {
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
$user_info = [];
if ($user) {
foreach ($user->getFields() as $field_name => $field) {
$user_info[$field_name] = $field->getValue(); // Leaks pass hash, tokens!
}
$variables['#attached']['drupalSettings']['api_user_pleiade']['user_info'] = $user_info;
}
}
Systemic CSRF Vulnerability on Mutating Endpoints
None of the custom /v1/* or /api/pleiade-ai/* mutating endpoints enforced Drupal's _csrf_request_header_token. Requests relied entirely on ambient session cookies. Combined with Finding 1, an external phishing email containing an image tag or JS payload could grant attacker accounts administrator status.
# VULNERABLE: No CSRF token header check; state mutations executable via cross-site requests
api_user_pleiade.setVariablesValue:
path: "/v1/api_user_pleiade/setVariablesValue"
defaults:
_controller: '\Drupal\api_user_pleiade\Controller\PleiadeUserController::setVariablesValue'
requirements:
_role: "authenticated"
_access: "TRUE"
Unlimited Expiry Zimbra Preauth URLs Logged to dblog
The Zimbra integration generated preauth URLs with expires=0 (indefinite validity) and logged the full URL into Drupal's database log (dblog). Any user with log view access or database read access could open any mail account directly without authentication.
// VULNERABLE: Indefinite session lifetime and logging reusable preauth URL to system logs
$data = $value1 . "|" . $value2 . "|" . $value3 . "|" . $value4;
$hmac = hash_hmac('sha1', $data, $key);
$preauthURL = $zimbra_domain . "service/preauth?account=" . $value1 . "×tamp=" . $value4 . "&expires=0&preauth=" . $hmac;
// CRITICAL LEAK: Logged to database table watchdog
$this->logInfo('api_zimbra_pleiade', "Preauth URL generated: $preauthURL");
Fragile & Unsafe Token Scraping via Guzzle Debug Output
Instead of using SOAP protocol responses or standard HTTP header extraction, the legacy code executed Guzzle requests with debug => true, started an output buffer (ob_start()), captured stdout, and ran a regex parser against the raw stream to find Set-Cookie: ZM_AUTH_TOKEN.
// ANTI-PATTERN: Capturing stdout from Guzzle debug stream via output buffering
ob_start();
$clientRequest = $this->client->request('GET', $preauthURL, [
'debug' => true,
'allow_redirects' => false,
]);
$debugInfo = ob_get_clean();
// Regex scraping on internal Guzzle stream
if (preg_match('/Set-Cookie: ZM_AUTH_TOKEN=([^;]+)/', $debugInfo, $matches)) {
$zmAuthToken = $matches[1];
}
Excessive Credential Transmission to n8n AI Webhooks
When queuing AI tasks (folder summaries, drafted replies), the module packaged the tenant's domain-wide Zimbra master preauth key, the agent's raw LemonLDAP session cookie, and the Nextcloud app password inside the JSON payload dispatched to external n8n workflows. Anyone viewing n8n run logs could compromise those accounts.
// VULNERABLE: Transmits master domain keys and session cookies to external automation
$payload = [
'zimbra_key' => $tenantMasterKey, // Can sign in as ANY user on the domain
'lemon_cookie' => $_COOKIE['lemonldap'], // Full SSO hijacking
'nextcloud_password' => $userNextcloudToken,
'prompt' => $promptText,
];
Sequential Microservice Blocking & N+1 Bottlenecks
Every page hit triggered synchronous LemonLDAP myapplications calls, two uncached external RSS feeds with synchronous image resizing via ImageMagick, and datatable_pleiade sequentially polled i-Parapheur, Maarch Courrier, Ciril Oracle, and Nextcloud. Response times exceeded 3,500ms under load.
// BOTTLENECK: Sequential blocking I/O across 4 enterprise backends on every view
$parapheur = $this->parapheurService->getDocuments(); // 450ms
$maarch = $this->maarchService->getDocuments(); // 850ms
$ciril = $this->cirilService->getDocuments(); // 600ms (Oracle)
$nextcloud = $this->nextcloudService->getDocuments(); // 350ms
// Total page blocking time > 2.25s
Root Container Execution & Docker Image Footprint Bloat
Drupal Drush commands were executed as root, creating file permissions that blocked Apache/PHP-FPM www-data processes from rendering image styles. Database ports were published on 0.0.0.0, and the build image was 1.55 GB with unnecessary build tools.
# BEFORE: Unbounded permissions, published DB port, massive build image
services:
app:
image: pleiade:legacy # 1.55 GB
user: root
db:
image: mariadb:11.4
ports:
- "0.0.0.0:3306:3306" # Database exposed globally
Instant Server Deployment Steps
Run these commands to verify and refresh this dashboard on /var/www/assets.belghali.org/