Files
wekan/server/main.js
T
Lauri Ojansivu 8ab7d46714 Trust the operating system's certificate authorities for TLS.
Since v12.15 the LDAP server's certificate is verified by default, and
Node.js verified it only against the Mozilla list it is built with. A
company root CA installed on the server with update-ca-certificates was
unknown to WeKan, so after upgrading from v12.14 the snap refused LDAPS
logins with UNABLE_TO_VERIFY_LEAF_SIGNATURE.

server/main.js now adds the operating system's CAs to Node's own before any
application code runs: tls.getCACertificates('system'), and the distribution
CA bundle files Go's crypto/x509 reads. The bundle file matters in the snap:
on Debian and Ubuntu snapd keeps the host's /etc/ssl, but the per-CA links
update-ca-certificates makes point into /usr/local/share/ca-certificates,
which the snap sees from its base. Verification is not relaxed - a CA the
system does not have is still refused - and --use-bundled-ca keeps Node's
list only. It covers LDAPS, mail, webhooks and OAuth2 in every launcher.

A refused LDAP certificate now says what to do, in the log and in Admin
Panel's Test connection: install the CA on the server, or set LDAP_CA_CERT.
No hint suggests turning verification off.

tests/systemCaCertificates6762.test.cjs runs a TLS server with a certificate
from a test private CA (its key is not kept) and checks the reported error
without the CA, verification with it in the system bundle, refusal without
it, --use-bundled-ca, and the hints. Two LDAP guards follow the extended
error handling; prune-unreachable-npm.mjs leaves the regex guard's reviewed
list, as it no longer builds a RegExp.

Thanks to fvb-sb and xet7 !

Fixes #6762.
2026-10-12 11:14:34 +03:00

46 lines
2.0 KiB
JavaScript

// ============================================================================
// WeKan Server Entry Point
//
// Uses require() to guarantee bootstrap runs before any model code.
// ============================================================================
// 0. Secrets from files (#5724): MAIL_URL_FILE and S3_SECRET_KEY_FILE fill
// MAIL_URL and S3_SECRET_KEY before any code reads them. Never the values
// in the log - only where each came from.
{
const { applySecretFiles, retiredSecretFiles } = require('/models/lib/envSecretFiles');
const report = applySecretFiles(process.env);
for (const [name, source] of Object.entries(report)) {
if (source === 'file') console.log(`[secrets] ${name} read from ${name}_FILE`);
else if (source.startsWith('file-error:')) console.error(`[secrets] ${name}_FILE cannot be used (${source.slice(11)}); ${name} is unset`);
}
for (const { name, replacement } of retiredSecretFiles(process.env)) {
console.warn(`[secrets] ${name} is not read by WeKan; use ${replacement} instead`);
}
}
// 0b. #6762: TLS trusts the operating system's certificate authorities as well
// as Node.js's own, so a company root CA installed on the server verifies
// LDAPS, mail, webhooks and OAuth2 the way it does for every other program.
// Before anything opens a connection.
{
const { trustSystemCaCertificates } = require('/server/lib/systemCaCertificates');
try {
const result = trustSystemCaCertificates();
if (result.applied) {
console.log(`[tls] trusting ${result.added} certificate authorities of the operating system as well as Node.js's own`);
}
} catch (e) {
console.warn(`[tls] the operating system's certificate authorities could not be read (${e.message}); only Node.js's own are trusted`);
}
}
// 1. Helpers polyfill (server no-op for .helpers())
require('/imports/collectionHelpers');
// 2. Collection2 (server-only)
require('meteor/aldeed:collection2');
// 3. Load all application code
require('/server/imports');