Files
wekan/server/ldapAdminSettingsBridge.js
T
Lauri Ojansivu ccb5c28b76 Fix local Meteor packages importing app-tree code, which crashed the server at boot.
The user's own ./build.sh run reproduced it directly: "Error: Cannot find
module '/models/settings'" thrown from packages/wekan-ldap/server/ldap.js
the moment the compiled server actually started (rspack's own build only
warns about this - node test suites never catch it either, since they run
these files with plain Node, outside Meteor's package linker). A local
package under packages/ is its own isolated build unit and cannot import
an app-tree module by absolute path ('/models/...', '/server/...'), static
or dynamic, import or require - that only resolves by accident, if at all.

Four packages had this shape:
- packages/wekan-ldap/server/ldap.js imported Settings and resolveConfigValue
  from /models/settings and /models/lib/configResolver directly (added by the
  recent LDAP Admin Panel override feature). configResolver's pure functions
  are now vendored into packages/wekan-ldap/server/configResolver.js; Settings
  access is injected instead, via setLdapSettingsAccessor(), wired once at
  boot by the new server/ldapAdminSettingsBridge.js (imported from
  server/imports.js).
- packages/wekan-oidc/oidc_server.js required /models/lib/oauth2ClientSecretJwt
  (pure, Node crypto/fs only) - vendored the same way, into
  packages/wekan-oidc/oauth2ClientSecretJwt.js.
- packages/wekan-accounts-saml/saml_server.js and
  packages/wekan-accounts-cas/cas_server.js each lazily required
  /server/lib/canary inside their account-conflict guard's try/catch, so it
  failed silently (caught, not crashing boot) rather than ever actually
  logging the attempt. canary.js is stateful (Meteor/Mongo-backed rate
  limiting), so it can't be vendored the same way; server/lib/canary.js now
  sets global.__wekanTripCanary once at module load (the Node process itself
  is the one thing both sides can reach without either importing the other),
  and both packages call through that instead.

Also found while wiring this up: packages/wekan-accounts-saml/saml_server.js
imports the npm package body-parser without declaring it in package.js's
Npm.depends, which crashed boot the same way once it stopped finding the
copy some unrelated app dependency happened to hoist into node_modules.
Added it to Npm.depends.

Tests: tests/packageAppImportBoundary.test.cjs sweeps every file under
packages/ for an app-tree absolute import (the negative check - nothing
under packages/ may do this, anywhere) and pins both vendored copies'
behavior against their app-tree originals so they cannot silently drift.
tests/securityAdvisories20260825.test.cjs's CAS account-conflict assertion
updated to match the new global.__wekanTripCanary bridge call.

Verified end to end: bootstrapped Meteor 3.5.2 in-sandbox and ran the real
dev server (`meteor run`) before and after - it reproduced both the
Settings/configResolver crash and, after fixing that, the body-parser
crash, exactly as reported; after this commit it compiles and starts
cleanly with neither.

Thanks to xet7 !
2026-09-10 23:34:20 +03:00

12 lines
664 B
JavaScript

// packages/wekan-ldap (a local Meteor package, its own isolated build unit)
// cannot import the app's Settings collection directly - see
// packages/wekan-ldap/server/configResolver.js's header comment for why.
// This is the app-side half of that boundary: it hands the package a getter
// for the ldap admin-override sub-document, once, at server boot, so
// LDAP.settings_get() can resolve an Admin Panel override the same way
// models/settings.js and server/models/settings.js already do.
import { setLdapSettingsAccessor } from 'meteor/wekan-ldap';
import Settings from '/models/settings';
setLdapSettingsAccessor(() => Settings.findOne({})?.ldap || {});