§ 06 · LDAP / ACTIVE DIRECTORY · SECURITY
Security and sessions
The login page hides things. The server is what refuses them.
Whoever controls the LDAP settings decides where every employee’s password is sent. That single fact drives most of the rules on this page.
Any organization owner controls sign-in for the whole instance. LDAP is one instance-wide setting, and since the instance-wide owner change an owner of any organization may change it. The page warns “This setting applies to every organization on this instance” and Save asks “Save LDAP settings for all organizations?”, but on an instance with several organizations it still means one organization’s owner can point every organization’s sign-in at a different directory. This is a deliberate product decision, not an oversight. Only give the owner role to people you would trust with sign-in for the whole instance. Per-organization LDAP is a planned follow-up.
LDAP-only mode is enforced on the server
Hiding buttons on the login page is not security: anyone can send a request straight to a sign-in endpoint. So while LDAP is on, the server itself decides which kinds of sign-in are allowed (isLoginAllowedInLdapMode in lib/login-mode.ts, called from the NextAuthNextAuthThe auth library HiveCFM Core uses to handle sessions, OAuth providers, and credentials. configuration).
| Sign-in method | LDAP off | LDAP on |
|---|---|---|
LDAP (ldap provider) | Refused (“Directory sign-in is not enabled.”) | Allowed |
Email + password (credentials) | Allowed | Only for owners of an organization (any organization; break-glass). Everyone else gets “Invalid credentials”. |
Email + password for a user whose identityProvider is ldap | Refused, always | Refused, always |
| Email link / token | Allowed | Refused, before any side effect |
| SSO (Azure AD, Google, GitHub, OIDC, SAMLSAMLThe XML-based enterprise SSO protocol HiveCFM supports for customers using Okta, Azure AD, or similar IdPs.) | Allowed | Refused, without deleting or changing the user |
| Sign-up | As configured | Closed: /auth/signup shows not-found, the sign-up action is refused, and the login page shows no sign-up link |
| Create a new organization | As configured | Refused for LDAP users (they could otherwise make themselves owner of a new org) |
“LDAP on” means: the saved switch is on and the LDAP_AUTH_DISABLED=1 kill switch is not set. If the database cannot be read, the code treats LDAP as off and the normal login page appears; this prevents a database hiccup from hiding every login form.
Everyone is signed out when LDAP is switched
When a save actually changes the switch (off → on, or on → off), HiveCFM writes the current time to instance_ldap_config.sessions_revoked_at. On every request that reads the session, the server compares that time with the session’s start time:
- Session started before
sessions_revoked_at→ the session is emptied. The browser’s stale cookie is cleared and the person lands on the login page. - Sessions from before this feature existed have no start time; they are treated as older and are signed out too.
- A fresh sign-in is never affected.
- Re-saving with the switch unchanged does not set the time, so nobody is signed out.
- “Stay signed in” cannot refresh a revoked session: the check runs before the refresh.
Why sign everyone out? Turning LDAP on changes who is allowed in. A local session started before the switch would otherwise keep working, even for an account that LDAP-only mode now refuses. Turning it off changes the rules the other way.
The admin who saved is signed out too, and lands on /auth/login?ldapChanged=enabled (or =disabled) with an explanatory notice.
Break-glass: Administrator sign-in
When LDAP is on, the company-account form has a small Administrator sign-in link. It opens /auth/login?mode=local: an email + password form titled “Administrator sign-in”, with the subtitle “Use your local administrator account.” SSO buttons are not shown there.
| Fact | Detail |
|---|---|
| Who gets in | Only owners of an organization (any organization on the instance) with a local HiveCFM password. The link is visible to everyone, but the server lets nobody else through. LDAP users never get in here, even owners: their account has no usable local password. |
| Why it exists | So an admin can fix or turn off LDAP when the directory is unreachable or the settings are wrong. Turning LDAP off on the settings page needs no directory and no test. |
| What it is not | It is not a second door for staff. Other local accounts are refused with “Invalid credentials”. |
| Keep it working | Keep at least one local owner account, with a known password. Do not set EMAIL_AUTH_DISABLED=1 on an LDAP site: it removes the email form, and with it the break-glass. |
The Administrator sign-in form may still show the “forgot password” link if password reset is enabled. A reset email only helps a local account, and only organization owners can then sign in with it. Everyone else is still refused by the server.
The kill switch: LDAP_AUTH_DISABLED=1
An environment variable on the core container. When set to 1:
- The login page is the normal email login, whatever the saved switch says.
- The LDAP provider refuses every login, even a direct request.
- LDAP-only enforcement is off, so local accounts and SSO work again.
- The LDAP settings page shows a warning: “LDAP_AUTH_DISABLED=1 is set — The server forces normal email login regardless of the switch below.”
- The Directory users waiting for access card and the Add from directory button are hidden, and their server actions refuse.
- It does not change the database and does not sign anyone out. Remove the variable and restart to return to the saved state.
Use it when nobody can reach the settings page, for example if the local owner’s password is lost and the directory is down. It needs a container restart, so it is an operator’s tool, not an admin’s. See Operations.
TLS and certificate trust
| Setting | Effect |
|---|---|
| LDAPS (636) | TLS from the first byte. Recommended. |
| StartTLS (389) | Plain connection, upgraded to TLS before the service account or any password is sent. |
| None (389) | The password travels in clear text. Lab use only. DCs that require LDAP signing refuse it with LDAP_STRONGER_AUTH_REQUIRED. |
| CA certificate | The PEM(s) pasted here are the trusted roots for this connection. Without it, only public CAs are trusted, and an internal CA gives LDAP_TLS_UNTRUSTED_CERT. |
| Verify server certificate on (default) | The certificate must chain to a trusted CA and match the host name. |
| Verify server certificate off | Encryption stays, but anyone on the network path could pretend to be the DC and collect passwords. Never in production. |
In Standard mode, DNS SRV answers that point outside the configured domain are ignored. Otherwise a spoofed DNS answer could send HiveCFM to an attacker’s server that holds a perfectly valid certificate for its own name.
The bind password
| Rule | Why |
|---|---|
Stored encrypted (AES-256-GCM) with the instance ENCRYPTION_KEY, in instance_ldap_config.bind_password. | A database dump alone does not reveal it. |
| Never sent back to the browser. The page only learns “a password is stored” and shows ”•••••••• (unchanged)”. | An admin session, a screenshot or a browser extension cannot leak it. |
| Leaving the field blank keeps the stored password. | So admins can change other fields without knowing the password. |
| …but only if the server, port, mode, domain, security, bind user, CA and verify setting are unchanged. Otherwise: “Re-enter the bind password when changing the server, security or bind user.” | Without this, an admin could point the stored secret at a server they control and capture a password they were never shown. |
| An empty bind password is refused. | An empty password is an anonymous bind, which some directories report as success. |
If ENCRYPTION_KEY changes, the stored password no longer decrypts. Tests and saves say “Stored settings could not be decrypted; re-enter the bind password and save.” Logins show “temporarily unavailable”. | Re-typing the password is the recovery. Turning LDAP off still works, because it never decrypts the secret. |
| Audit entries record the configuration without the password, and with the CA reduced to “present: yes/no”. | Audit logs are read by more people than the settings page. |
Redirects after sign-in stay on the same site
After signing in, HiveCFM follows the callbackUrl only if it points to the same host: a relative path, or a full URL whose host and port match the current one (reduced to its path). Anything else (another host, javascript:, //host, /\host, control characters) falls back to /. This prevents a crafted login link from bouncing a freshly signed-in person to a phishing page.
The design rulings, in plain language
The feature went through several security reviews. These are the decisions that shaped it, from the design ledger.
| Ruling | Decision | Why it matters |
|---|---|---|
| D1 / R8 | Never link a directory login to an existing local or SSO account by email, and never re-link an LDAP account to a different objectGUID. | Whoever can set a mail value in the directory must not be able to take over a HiveCFM account. |
| D3 | LDAP is not behind a license check. | An expired license must not lock a whole company out. |
| D5 / R10a | The stored password hash is never accepted for login. | An account disabled in AD must not get in with an old hash. |
| D6 | No offline fallback when the directory is down. | ”Down” must not mean “anyone with an old password gets in”. |
| D7 | LDAP users cannot create organizations. | Otherwise any employee could become owner of a new organization on a multi-org instance. |
| R4 | A locked account is shown as “Invalid username or password.” on the login page. | AD reports “locked” even for wrong passwords, which would confirm that a username exists. |
| R6 | DNS SRV answers outside the configured domain are ignored. | A spoofed DNS answer must not redirect passwords. |
| R7 | A user is identified by objectGUID or entryUUID, never by DN. | DNs are reused after delete or rename; a different person could inherit the account. |
| R9 | The stored bind password is reused only for an unchanged target. | An admin cannot send the hidden secret to their own server. |
| R10b / R13 | The directory is trusted for email; email changes are logged and audited. Deployment rule: people must not be able to edit their own mail. | Invites match by email, so a self-edited mail could claim someone else’s invite. |
| R12 | Owner rights now carry control over where every organization’s passwords go. Per-organization LDAP is a planned follow-up. | |
| R14 | Failed sign-ins log the code, host, port and step names only. | The step details contain the typed username and the person’s DN. |
| R17 | Directory users have no HiveCFM 2FA step. | HiveCFM 2FA applies to local email accounts only. |
| R19 | — | |
| R20 | No retry on another DC after the person’s password was sent. | Replaying the password would push the person towards an AD lockout. |
| R21 / R22 | Same-host redirects only, compared by host and port. | Prevents open redirects, and still works behind a TLS proxy. |
| R23 | LDAP-only mode is enforced on the server, with break-glass for organization owners (any organization, since the instance-wide owner change). | Hidden buttons are not protection. |
| R24 | Switching LDAP revokes sessions on every request, including sessions older than the feature. | Old sessions must not survive a change of the sign-in rules. |
| R25 | Saving is guarded by the row version: settings changed by another admin after your test are not overwritten. | Prevents enabling an untested configuration. |
| R28 | Two simultaneous first logins for one person are handled. | No duplicate users, no error. |
| R30 | After enabling, the admin finds an Administrator sign-in link on the company form. | An admin must never be locked out by their own switch. |