DC-033: fix getLocalVersion __dirname resolution
CI / Test & Lint (push) Has been cancelled
CI / Security audit (push) Has been cancelled

The SelfUpdater's getLocalVersion() used __dirname to find package.json
and VERSION, but server.js loads the module via './src/docker/self-updater'
so __dirname resolves to /app/src/docker inside the container — which
has no package.json. Result: /api/v1/system/version silently returned
{version: '0.0.0', commit: null} and checkForUpdate() always thought we
were outdated.

Walk a candidate list of paths (api root first, __dirname second) so the
function works regardless of where the module is required from. Log to
stderr on total failure instead of swallowing silently.

Verified on DNS2: /api/v1/system/version now returns
{"name":"DashCaddy","version":"1.14.8","commit":"fef7e07"}
(v1.14.8 with the security fixes DC-020..032).
This commit is contained in:
Krystie
2026-07-05 21:49:39 -07:00
parent ba23cdff02
commit 20d280f1dd
+19 -8
View File
@@ -105,16 +105,27 @@ class SelfUpdater extends EventEmitter {
// ── Version / Identity Info ── // ── Version / Identity Info ──
getLocalVersion() { getLocalVersion() {
try { // Resolve package.json/VERSION relative to the api root, not __dirname.
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8')); // This module is loaded via `./src/docker/self-updater` so __dirname is
let commit = null; // `/app/src/docker` inside the container, which has no package.json.
// Fall back to __dirname (matches the legacy root-copy contract) so
// existing callers and future restructurings keep working.
const candidates = [
path.join(__dirname, '..', '..', 'package.json'),
path.join(__dirname, 'package.json'),
];
for (const pkgPath of candidates) {
try { try {
commit = fs.readFileSync(path.join(__dirname, 'VERSION'), 'utf8').trim(); const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
} catch { /* ignore */ } let commit = null;
return { version: pkg.version, commit }; try {
} catch (e) { commit = fs.readFileSync(pkgPath.replace(/package\.json$/, 'VERSION'), 'utf8').trim();
return { version: '0.0.0', commit: null }; } catch { /* ignore */ }
return { version: pkg.version, commit };
} catch { /* try next candidate */ }
} }
console.error('[SelfUpdater] getLocalVersion failed: no candidate package.json found');
return { version: '0.0.0', commit: null };
} }
getInstanceInfo() { getInstanceInfo() {