§ 06 · LDAP / ACTIVE DIRECTORY · INTERNALS
How sign-in works
Two binds, one search, and a handful of rules that stop the wrong person from getting the right account.
This page follows one sign-in by EXAMPLE\jane.smith from the moment she clicks Sign in. The code lives in apps/web/modules/auth/ldap/lib/: authorize.ts (the entry point), client.ts (talking to the directory), provision.ts (the HiveCFM user) and errors.ts (codes and messages).
A bind is LDAP’s word for “sign in to the directory”. HiveCFM binds twice per login: first as the service account (to search), then as the person (to check her password).
The whole login on one diagram
Step by step
1 · Rate limits and input checks
Before anything touches the directory:
- Per IP: the normal login limit, 10 attempts per 15 minutes.
- Per username: 5 LDAP attempts per 15 minutes for the same username (case-insensitive). This is set below typical AD lockout thresholds, so HiveCFM slows an attacker down before AD locks the real person out.
- The username must be 1–256 characters and the password 1–128 characters. An empty password is refused outright: to a directory, an empty password is an anonymous bind, which many servers report as “success”.
- If
LDAP_AUTH_DISABLED=1is set, or LDAP is switched off in the settings, the login is refused with “Directory sign-in is not enabled.”
2 · The username is cleaned
Anything up to and including the last backslash is removed, and spaces at the ends are trimmed.
| Typed | Searched for |
|---|---|
jane.smith | jane.smith |
EXAMPLE\jane.smith | jane.smith |
jane.smith@bank.example | jane.smith@bank.example (matches userPrincipalName) |
3 · The server is found
- Direct mode, or Standard mode with a server override: the typed host and port. Port defaults to 636 for LDAPS, 389 otherwise.
- Standard mode: a DNS SRV lookup for
_ldap._tcp.<domain>. HiveCFM keeps only answers inside the configured domain (a defence against a spoofed DNS answer pointing at an attacker’s server), sorts them by priority and weight, and keeps the first 3.
4 · Connect and TLS
HiveCFM opens the connection with a 5-second connect timeout and a 10-second limit per operation.
- With LDAPS, TLS starts immediately. With StartTLS, HiveCFM connects in plain text on 389 and upgrades to TLS before sending any password.
- The DC’s certificate must chain to a trusted CA: the CA pasted in the settings, or a public CA.
- The certificate must match the host name you connect to (when you connect by name). Connecting by IP still checks the certificate chain, but a certificate without that IP in it fails the name check.
- Verify server certificate off skips both checks. Encryption stays, but the proof of identity is gone.
5 · Service-account bind
HiveCFM binds as the bind user (e.g. svc-hivecfm@bank.example) with the stored, decrypted bind password. If this fails, the error is always LDAP_BIND_SERVICE_INVALID: the person’s password has not been sent anywhere yet.
6 · Search for exactly one person
HiveCFM searches the Base DN and everything under it with the user filter. {username} in the filter is replaced by the cleaned username, escaped according to RFC 4515: \, *, (, ) and the NUL character are turned into harmless codes. A username like *)(objectClass=* therefore cannot widen the search.
The search asks for at most 2 results:
| Results | Outcome |
|---|---|
| 0 | LDAP_USER_NOT_FOUND |
| 1 | Continue |
| 2 or more | LDAP_USER_MULTIPLE — the filter is too loose. HiveCFM never guesses which one is meant. |
It reads only these attributes: the email and name attributes from the settings, userPrincipalName, sAMAccountName, givenName, sn, objectGUID and entryUUID.
7 · Bind as the person
HiveCFM binds as the DN it just found, with the password she typed. This is the real password check, done by the directory itself.
If AD refuses, its error text contains a sub-code (for example data 52e). HiveCFM turns it into a specific code: wrong password, disabled, locked, expired, must change password, or not allowed at this time or from this workstation. The full table is in Troubleshooting.
No retry on another DC once the password was sent. In Standard mode HiveCFM may try the next DC when one cannot be reached (DNS not found, connection refused, timeout). But once the person’s password has gone to a DC, any failure stops the login. A network error at that point is ambiguous: the DC may already have counted a failed attempt, and trying the same password on the next DC would push the person towards an AD lockout.
8 · Read email, name and id
| What | Where it comes from | Rule |
|---|---|---|
the Email attribute (mail), else userPrincipalName | Lowercased. Must be a valid email address. If neither works: LDAP_NO_EMAIL_ATTRIBUTE. | |
| Name | the Name attribute (displayName), else givenName + sn, else sAMAccountName | Cleaned to letters, digits, spaces, ' and - (any language; Arabic names are kept). Smith, Jane (IT) becomes Smith Jane IT. If nothing usable is left: LDAP User. |
| Unique id | objectGUID (AD), else entryUUID (OpenLDAP and others) | objectGUID is stored in the .NET text format, the same as the old HiveCFM’s CFMUser.Guid. If the directory gives neither, the login is refused (LDAP_UNKNOWN). The DN is never used as an id: DNs are reused when an account is deleted and re-created or renamed, so a different person could inherit the account. |
9 · Find or create the HiveCFM user
The rules in plain words:
- Match by objectGUID first. It never changes for an AD account, even when the person is renamed or their email changes.
- Never take over a non-LDAP account. If a local or SSO account already uses that email, the sign-in is refused with
LDAP_EMAIL_CONFLICT. Auto-linking would let anyone who can set a directorymailvalue take over that HiveCFM account. - Never re-link to a different directory person. An LDAP user already bound to another objectGUID is not handed over just because the emails match.
- People added in advance already exist. If an owner used Add from directory, the LDAP user row (with that objectGUID, no password) and its membership are already there. The first sign-in takes the “yes” branch: it stores the password hash, sets the last sign-in time, and the person lands straight in their workspace.
- New users get no membership. They land on “No workspace found — Please contact your administrator to get access to a workspace.” until an admin adds them (Giving users access). LDAP users also cannot create their own organization.
- The email is marked verified, because the directory is the source of truth. That is why people must not be able to edit their own
mailin the directory. - Email changes are visible. When a person’s directory email changes, HiveCFM updates it, writes a warning log line and an audit entry (“updated”, field email).
- Two first logins at the same moment (two tabs) are handled: the second request finds the row the first one created and continues with it.
10 · About the stored password hash
HiveCFM stores a bcrypt hash of the directory password on the user row, and refreshes it when the password changes. This was requested for the feature, but the hash is never accepted for login:
- The normal email + password sign-in refuses any user whose
identityProviderisldap, even with the right password. (Tested: posting a directory user’s correct password to the email login returns 401.) - There is no “directory is down, use the stored hash” fallback.
So a person disabled or re-passworded in AD is affected at their very nextNext.jsReact framework used by HiveCFM Core. Handles routing, server rendering, and API routes in one bundle. sign-in.
11 · The session
Once the user is found or created, HiveCFM records the last login time and starts a normal HiveCFM session. Two-factor authentication (TOTP) does not apply to directory users; HiveCFM’s 2FA is only for local email accounts.
Every login is checked live
There is no cache of “this person is fine”. Each sign-in goes to the directory again, so:
| Change in AD | Effect in HiveCFM |
|---|---|
| Password changed | The new password works at once. The old one is refused (subject to the directory’s own rules). |
| Account disabled | Next sign-in shows “Your directory account can’t sign in (disabled, locked or expired). Contact your IT administrator.” |
| Account locked | Next sign-in shows “Invalid username or password.” (see below). |
| Display name or email changed | Updated in HiveCFM at the nextNext.jsReact framework used by HiveCFM Core. Handles routing, server rendering, and API routes in one bundle. sign-in. |
| Account deleted | Cannot sign in. The HiveCFM user row stays (HiveCFM has no directory sync). |
A session that is already open is not ended by a change in AD. The change applies at the next sign-in. To force everyone out at once, toggle LDAP (see Security and sessions), or deactivate the person in HiveCFM.
What the person sees
The login page deliberately says less than the admin test does. An attacker must not be able to learn which usernames exist.
| Situation | Message on the login page |
|---|---|
| Unknown user, several matches, wrong password, empty password, locked account | Invalid username or password. |
| Disabled, expired, or logon not allowed at this time or from this workstation | Your directory account can’t sign in (disabled, locked or expired). Contact your IT administrator. |
| Password expired or must be changed | Your password has expired or must be changed. Change it in Windows, then sign in again. |
| Email belongs to a non-LDAP account | An account with this email already exists. Contact your administrator. |
| No usable email in the directory | Your directory account has no email address. Contact your IT administrator. |
| HiveCFM user deactivated | Your account is currently inactive. Please contact the organization admin. |
| LDAP off or kill switch set | Directory sign-in is not enabled. |
| Anything else: DC unreachable, TLS problem, service account rejected, settings cannot be decrypted | Directory sign-in is temporarily unavailable. Please try again later or contact your administrator. |
Why is “locked” shown as “invalid”? AD answers “locked” (data 775) even when the typed password is wrong. If the login page said “locked”, anyone could confirm that a username exists just by guessing badly a few times. The admin’s Test user credential shows the real code, LDAP_ACCOUNT_LOCKED.
Why is “not found” as slow as “wrong password”? When no user is found, HiveCFM still does the same amount of password-hashing work, so the response time does not reveal whether the username exists.
What is logged, and what never is
| Logged | Never logged |
|---|---|
ldap: sign-in failed with the error code, DC host and port, and the list of steps (name, ok/failed, duration) | The person’s password or the bind password |
| A hashed identifier for the username, not the username itself | The search filter (it contains the typed username) or the person’s DN |
| Auth audit entries: attempt failed with the code, user created, email changed, authentication succeeded | Step detail text from the directory |
ldap: provisioning refused with LDAP_EMAIL_CONFLICT or LDAP_USER_INACTIVE | The test password used on the settings page |
The settings page’s own audit entries (action “updated”, target ldapConfiguration) record the old and new configuration with the CA certificate reduced to a yes/no flag and no bind password at all.
What HiveCFM never does with the password
- It never sends the directory password to other HiveCFM services (Superset, n8n, Novu). Directory users are deliberately not provisioned into them on sign-in.
- It never writes it in plain text anywhere. The only copy kept is the bcrypt hash described above.