[glm-grade=B] fix: dead dashboard WS, corrupted error.log, auth-polling storm, re-auth freeze + CVE bumps
CI / Test & Lint (push) Canceled after 0s
CI / Security audit (push) Canceled after 0s

Adversarial audit 2026-08-16 (GLM-5.3 delegate, 2 rounds, 141 tool calls):

P0-1: Dashboard WebSocket (/api/v1/ws) dead on EVERY boot since DC-076.
server.js passed module exports (DependencyManager class, {AutoRestartManager}
namespace, SSLMonitor class) instead of createApp()'s live instances — first
.on() threw ERR_INVALID_ARG_TYPE, catch swallowed it. Fix: app.locals.ctx
exposed in src/app.js; server.js passes all 8 real EventEmitter instances.

P0-2: error.log corrupted since 2026-07-14. errorMiddleware called
logError(FILE, SIZE, path, err, meta) — 5 args into a 3-arg wrapper —
logging 'Error: 5242880' garbage every ~60s and DISCARDING the real error
object. Fix: correct 3-arg call + legacy-shape guard in logErrorWrapper +
~74 log.error sites swept to pass real error objects (AST-verified scope-
safe 71/71, 29/29 modules load clean).

P0-3: auth-polling storm (stranded grade=B commit never landed in prod):
401/403 behind TOTP gate hammered /api/v1/services/status + SSE reconnect
every 2-8s, with misleading direct-probe fallback marking services 'up'.
Fix landed + B-round MEDIUM follow-up: TOTP re-auth success now clears
_dcAuthLost, resumes SSE (new _sseResume clears the latch), and refreshes.

Also: eslintignore static-sites/ (33→0 errors); nodemailer 8→9.0.5 and
sharp 0.33→0.35.3 (3 high CVEs killed; jest green on new majors);
dockerode@5/uuid deferred (semver-major, Docker API surface).

Verification: 80/80 suites, 1837/1837 tests; ESLint 0 errors/743 warnings;
node --check all changed files; bundles rebuilt + SW cache bumped.

Judges: Codex quota-dead until Aug 19 (verified live) — GLM adversarial
delegate per operator directive 2026-08-07. Round 1: 98-call mechanical
verification (timed out pre-verdict). Round 2 (this grade): B, one MEDIUM
(re-auth freeze) — fixed in this commit as prescribed.
This commit is contained in:
Krystie
2026-08-16 04:18:07 -07:00
parent 295c63ce94
commit e99413150e
39 changed files with 533 additions and 355 deletions
+10 -6
View File
@@ -318,7 +318,7 @@ async function createApp() {
const { writeJsonFile } = require('./utilities/fs-helpers');
await writeJsonFile(config.TOTP_CONFIG_FILE, totpConfig);
} catch (e) {
log.error('config', 'Could not save TOTP config', { error: e.message });
log.error('config', e, null, { note: 'Could not save TOTP config' });
}
}
@@ -437,7 +437,7 @@ async function createApp() {
ctx.workflowEngine = workflowEngine;
log.info('app', 'Workflow engine initialized');
} catch (err) {
log.error('app', 'Failed to initialize workflow engine', { error: err.message });
log.error('app', err, null, { note: 'Failed to initialize workflow engine' });
}
}
@@ -501,12 +501,12 @@ async function createApp() {
if (ctx.notification && ctx.resourceMonitor) {
ctx.resourceMonitor.on('alert', (alertData) => {
ctx.notification.sendAlert(alertData).catch(err => {
log.error('notification', 'Failed to send alert', { error: err.message });
log.error('notification', err, null, { note: 'Failed to send alert' });
});
});
ctx.resourceMonitor.on('auto-restart', (data) => {
ctx.notification.sendServiceEvent('auto-restart', data).catch(err => {
log.error('notification', 'Failed to send auto-restart notification', { error: err.message });
log.error('notification', err, null, { note: 'Failed to send auto-restart notification' });
});
});
}
@@ -514,12 +514,12 @@ async function createApp() {
if (ctx.notification && ctx.backupManager) {
ctx.backupManager.on('backup-complete', (data) => {
ctx.notification.send('backup-complete', data).catch(err => {
log.error('notification', 'Failed to send backup-complete', { error: err.message });
log.error('notification', err, null, { note: 'Failed to send backup-complete' });
});
});
ctx.backupManager.on('backup-failed', (data) => {
ctx.notification.send('backup-failed', data).catch(err => {
log.error('notification', 'Failed to send backup-failed', { error: err.message });
log.error('notification', err, null, { note: 'Failed to send backup-failed' });
});
});
}
@@ -1097,6 +1097,10 @@ async function createApp() {
app.use('/api', notFoundHandler);
app.use(errorMiddleware);
// Expose ctx on the app for entry points (server.js dashboard-WS wiring)
// without changing the returned shape for existing callers/tests.
app.locals.ctx = ctx;
return { app, log, config: config.siteConfig, licenseManager };
}
+1 -1
View File
@@ -97,7 +97,7 @@ function loadAndMigrate(configFile, log) {
raw = JSON.parse(fs.readFileSync(configFile, 'utf8'));
} catch (e) {
if (log && log.error) {
log.error('config-migration', 'Failed to parse config.json, using defaults', { error: e.message });
log.error('config-migration', e, null, { note: 'Failed to parse config.json, using defaults' });
}
raw = null;
}
+1 -1
View File
@@ -62,7 +62,7 @@ function loadSiteConfig(CONFIG_FILE, log) {
}
} catch (e) {
if (log && log.error) {
log.error('config', 'Failed to load site config', { error: e.message });
log.error('config', e, null, { note: 'Failed to load site config' });
}
}
}
+3 -3
View File
@@ -74,7 +74,7 @@ async function refreshDnsToken(username, password, server, fetchT, log) {
return { success: false, error: result.errorMessage || 'Login failed' };
} catch (error) {
log.error('dns', 'DNS token refresh error', { error: error.message });
log.error('dns', error, null, { note: 'DNS token refresh error' });
return { success: false, error: error.message };
}
}
@@ -141,7 +141,7 @@ async function ensureValidDnsToken(siteConfig, credentialManager, fetchT, log) {
return await refreshDnsToken(username, password, server || primaryIp, fetchT, log);
}
} catch (err) {
log.error('dns', 'Credential manager error', { error: err.message });
log.error('dns', err, null, { note: 'Credential manager error' });
}
return {
@@ -237,7 +237,7 @@ async function getTokenForServer(targetServer, siteConfig, credentialManager, fe
return await authenticateToServer(username, password);
}
} catch (err) {
log.error('dns', 'Credential manager error', { server: targetServer, error: err.message });
log.error('dns', err, null, { note: 'Credential manager error', server: targetServer });
}
return { success: false, error: 'No DNS credentials configured' };
+1 -1
View File
@@ -121,7 +121,7 @@ function assembleContext({
try {
fs.writeFileSync(TAILSCALE_CONFIG_FILE, JSON.stringify(meta, null, 2), 'utf8');
} catch (e) {
log.error('tailscale-coord', 'Failed to write tailscale-config.json', { error: e.message });
log.error('tailscale-coord', e, null, { note: 'Failed to write tailscale-config.json' });
}
}
async function getCoordClient() {
+1 -1
View File
@@ -103,7 +103,7 @@ function createProviderDnsContext(siteConfig, buildDomain, credentialManager, fe
}
return { success: false, error: result.errorMessage || 'Login failed' };
} catch (error) {
log.error('dns', 'DNS token refresh error', { error: error.message });
log.error('dns', error, null, { note: 'DNS token refresh error' });
return { success: false, error: error.message };
}
}
+2 -6
View File
@@ -172,9 +172,7 @@ class DNSPropagationChecker extends EventEmitter {
expectedIp,
totalTime: result.totalTime
}, 'success').catch(err => {
this.log.error('dns-propagation', 'Failed to send propagation notification', {
error: err.message
});
this.log.error('dns-propagation', err, null, { note: 'Failed to send propagation notification' });
});
}
} else {
@@ -187,9 +185,7 @@ class DNSPropagationChecker extends EventEmitter {
expectedIp,
totalTime: result.totalTime
}, 'warning').catch(err => {
this.log.error('dns-propagation', 'Failed to send timeout notification', {
error: err.message
});
this.log.error('dns-propagation', err, null, { note: 'Failed to send timeout notification' });
});
}
}
@@ -118,7 +118,7 @@ class TechnitiumDNSProvider extends BaseDNSProvider {
return await this._doLogin(username, password);
}
} catch (err) {
log.error('technitium', 'Global credential error', { error: err.message });
log.error('technitium', err, null, { note: 'Global credential error' });
}
return {
@@ -164,7 +164,7 @@ class TechnitiumDNSProvider extends BaseDNSProvider {
return { success: false, error: result.errorMessage || 'Login failed' };
} catch (error) {
log.error('technitium', 'Login error', { error: error.message });
log.error('technitium', error, null, { note: 'Login error' });
return { success: false, error: error.message };
}
}
@@ -363,7 +363,7 @@ class TechnitiumDNSProvider extends BaseDNSProvider {
const parsed = this._parseLogText(logText, limit);
return { success: true, logs: parsed };
} catch (error) {
log.error('technitium', 'Failed to fetch DNS logs', { error: error.message });
log.error('technitium', error, null, { note: 'Failed to fetch DNS logs' });
throw new Error(`Failed to get DNS logs: ${error.message}`);
}
}
@@ -449,7 +449,7 @@ class TechnitiumDNSProvider extends BaseDNSProvider {
throw new Error(result.errorMessage || 'Restart failed');
} catch (error) {
log.error('technitium', 'DNS restart error', { error: error.message });
log.error('technitium', error, null, { note: 'DNS restart error' });
throw new Error(`Failed to restart DNS server: ${error.message}`);
}
}
@@ -483,7 +483,7 @@ class TechnitiumDNSProvider extends BaseDNSProvider {
throw new Error(result.errorMessage || 'Update check failed');
} catch (error) {
log.error('technitium', 'Update check error', { error: error.message });
log.error('technitium', error, null, { note: 'Update check error' });
throw new Error(`Failed to check for updates: ${error.message}`);
}
}
@@ -86,7 +86,7 @@ class AutoRestartManager extends EventEmitter {
}
this.log.info('auto-restart', 'Policies loaded', { count: this.policies.size });
} catch (err) {
this.log.error('auto-restart', 'Failed to load policies', { error: err.message });
this.log.error('auto-restart', err, null, { note: 'Failed to load policies' });
}
// Listen to health checker status transitions
@@ -246,7 +246,7 @@ class AutoRestartManager extends EventEmitter {
...eventData,
});
} catch (notifErr) {
this.log.error('auto-restart', 'Notification failed', { error: notifErr.message });
this.log.error('auto-restart', notifErr, null, { note: 'Notification failed' });
}
return { action: 'max-reached', ...eventData };
@@ -312,7 +312,7 @@ class AutoRestartManager extends EventEmitter {
...successData,
});
} catch (notifErr) {
this.log.error('auto-restart', 'Notification failed', { error: notifErr.message });
this.log.error('auto-restart', notifErr, null, { note: 'Notification failed' });
}
this.log.info('auto-restart', 'Container restarted', {
@@ -349,7 +349,7 @@ class AutoRestartManager extends EventEmitter {
...failData,
});
} catch (notifErr) {
this.log.error('auto-restart', 'Notification failed', { error: notifErr.message });
this.log.error('auto-restart', notifErr, null, { note: 'Notification failed' });
}
this.log.error('auto-restart', 'Restart failed', {
@@ -478,7 +478,7 @@ class AutoRestartManager extends EventEmitter {
}
await writeJsonFile(this.policiesFile, obj);
} catch (err) {
this.log.error('auto-restart', 'Failed to save policies', { error: err.message });
this.log.error('auto-restart', err, null, { note: 'Failed to save policies' });
}
}
@@ -75,7 +75,7 @@ class ConfigDriftDetector extends EventEmitter {
const data = await this.servicesStateManager.read();
services = Array.isArray(data) ? data : (data.services || []);
} catch (err) {
this.log.error('drift', 'Failed to read services', { error: err.message });
this.log.error('drift', err, null, { note: 'Failed to read services' });
}
// Gather live Docker containers
@@ -83,7 +83,7 @@ class ConfigDriftDetector extends EventEmitter {
try {
containers = await this.docker.client.listContainers({ all: true });
} catch (err) {
this.log.error('drift', 'Failed to list containers', { error: err.message });
this.log.error('drift', err, null, { note: 'Failed to list containers' });
}
// Build lookup maps
@@ -51,7 +51,7 @@ class NotificationManager extends EventEmitter {
this.config = this._mergeConfig(DEFAULT_CONFIG, data);
}
} catch (error) {
this.log.error('notification', 'Failed to load config', { error: error.message });
this.log.error('notification', error, null, { note: 'Failed to load config' });
}
}
@@ -89,7 +89,7 @@ class NotificationManager extends EventEmitter {
fs.writeFileSync(this.NOTIFICATIONS_FILE, JSON.stringify(this.config, null, 2));
return true;
} catch (error) {
this.log.error('notification', 'Failed to save config', { error: error.message });
this.log.error('notification', error, null, { note: 'Failed to save config' });
throw error;
}
}
@@ -429,7 +429,7 @@ class NotificationManager extends EventEmitter {
const interval = (this.config.healthCheck?.intervalMinutes || 5) * 60 * 1000;
this.healthDaemonInterval = setInterval(() => {
this.checkHealth().catch(err => {
this.log.error('notification', 'Health check failed', { error: err.message });
this.log.error('notification', err, null, { note: 'Health check failed' });
});
}, interval);
@@ -488,7 +488,7 @@ class NotificationManager extends EventEmitter {
lastCheck: this.config.healthCheck.lastCheck
};
} catch (error) {
this.log.error('notification', 'Health check error', { error: error.message });
this.log.error('notification', error, null, { note: 'Health check error' });
throw error;
}
}
@@ -331,7 +331,7 @@ class DiskSpaceMonitor extends EventEmitter {
result.error = err.message;
result.completedAt = new Date().toISOString();
if (this.log) {
this.log.error('disk', 'Disk cleanup failed', { error: err.message, level });
this.log.error('disk', err, null, { note: 'Disk cleanup failed', level });
}
return result;
}
+5 -5
View File
@@ -143,7 +143,7 @@ class SSLMonitor extends EventEmitter {
try {
servicesData = await this.ctx.servicesStateManager.read();
} catch (err) {
this.log.error('ssl-monitor', 'Failed to read services', { error: err.message });
this.log.error('ssl-monitor', err, null, { note: 'Failed to read services' });
return this.getStatus();
}
@@ -212,13 +212,13 @@ class SSLMonitor extends EventEmitter {
// Initial check (non-blocking)
this.checkAll().catch(err => {
this.log.error('ssl-monitor', 'Initial SSL check failed', { error: err.message });
this.log.error('ssl-monitor', err, null, { note: 'Initial SSL check failed' });
});
// Schedule periodic checks
this.intervalHandle = setInterval(() => {
this.checkAll().catch(err => {
this.log.error('ssl-monitor', 'Periodic SSL check failed', { error: err.message });
this.log.error('ssl-monitor', err, null, { note: 'Periodic SSL check failed' });
});
}, this.config.intervalMs);
@@ -299,7 +299,7 @@ class SSLMonitor extends EventEmitter {
clearInterval(this.intervalHandle);
this.intervalHandle = setInterval(() => {
this.checkAll().catch(err => {
this.log.error('ssl-monitor', 'Periodic SSL check failed', { error: err.message });
this.log.error('ssl-monitor', err, null, { note: 'Periodic SSL check failed' });
});
}, this.config.intervalMs);
}
@@ -355,7 +355,7 @@ class SSLMonitor extends EventEmitter {
validTo: certResult.validTo
}, level <= THRESHOLDS.CRITICAL ? 'error' : 'warning');
} catch (err) {
this.log.error('ssl-monitor', 'Failed to send SSL notification', { error: err.message });
this.log.error('ssl-monitor', err, null, { note: 'Failed to send SSL notification' });
}
}
} else if (level === null) {
+1 -1
View File
@@ -81,7 +81,7 @@ class PluginManager extends EventEmitter {
workflowActions: [...this.workflowActions.keys()],
});
} catch (err) {
this.log.error('plugins', 'Failed to scan plugin directory', { error: err.message });
this.log.error('plugins', err, null, { note: 'Failed to scan plugin directory' });
this.loaded = true; // Don't crash — just run without plugins
}
}
+1 -8
View File
@@ -7,15 +7,9 @@
* ./error-logger.js and its ./error.log file have been retired.
*/
const path = require('path');
const { AppError } = require('./errors');
const { LIMITS } = require('./constants');
const { logError: unifiedLogError, safeErrorMessage } = require('../utils/logging');
const { errorResponse } = require('../utils/responses');
const platformPaths = require('../../platform-paths');
const ERROR_LOG_FILE = process.env.ERROR_LOG_FILE || path.join(platformPaths.dataDir, 'error.log');
const MAX_ERROR_LOG_SIZE = LIMITS.ERROR_LOG_SIZE;
/**
* Global error handling middleware
@@ -24,11 +18,10 @@ const MAX_ERROR_LOG_SIZE = LIMITS.ERROR_LOG_SIZE;
function errorMiddleware(err, req, res, next) {
// Log all errors with request context (unified, same file the rest of the app uses)
unifiedLogError(
ERROR_LOG_FILE,
MAX_ERROR_LOG_SIZE,
req.path,
err,
{
req,
method: req.method,
ip: req.ip,
userId: req.user?.id,
@@ -228,7 +228,7 @@ async function syncHealthCheckerServices({ log, SERVICES_FILE, servicesStateMana
log.info('health', 'Health checker synced', { added, updated, removed });
}
} catch (error) {
log.error('health', 'Error syncing health checker', { error: error.message });
log.error('health', error, null, { note: 'Error syncing health checker' });
}
}
+8
View File
@@ -417,6 +417,14 @@ function safeErrorMessage(error) {
// Supports: logError(context, error, extra) → existing route call pattern
async function logErrorWrapper(ctx, err, extra) {
// Guard against legacy call shapes that used to corrupt error.log:
// the old 5-arg form logError(file, maxSize, path, err, meta) made ctx
// a file path and turned maxSize (a number) into the "error". Detect and
// normalize so the real error always reaches error.log.
if (typeof ctx === 'string' && /^\/.*\.(log|json)$/.test(ctx) && typeof err === 'number') {
// Legacy shape: (file, size, reqPath, error, meta) → shift args.
[ctx, err, extra] = [arguments[2], arguments[3], { ...arguments[4], req: undefined }];
}
const req = extra?.req;
const payload = extra ? { ...extra } : {};
if (payload.req) delete payload.req;