[GH-ISSUE #5852] [Bug]: LDAP default total traffic is saved as bytes instead of GB #4063

Closed
opened 2026-10-31 20:36:53 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @rty813 on GitHub (Jul 7, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5852

Describe the bug

When LDAP sync auto-creates clients, the "Default total (GB)" setting is written directly into the client totalGB field without converting from GB to bytes.

For example, if ldapDefaultTotalGB is set to 10, the created client gets totalGB: 10, which is treated as 10 bytes, not 10 GB. The client becomes depleted almost immediately.

This looks inconsistent with the rest of the UI/API, where totalGB is stored in bytes and the frontend converts GB input to bytes before saving.

How to reproduce

  1. Enable LDAP sync.
  2. Enable auto-create clients.
  3. Set LDAP "Default total (GB)" to a non-zero value, for example 10.
  4. Let LDAP sync create a new client.
  5. Inspect the created client record or inbound settings JSON.

Actual behavior

The created client has:

"totalGB": 10

The quota is interpreted as 10 bytes.

Expected behavior

The created client should have:

"totalGB": 10737418240

for a 10 GB setting.

Code reference

In internal/web/job/ldap_sync_job.go, LDAP auto-create currently sets:

TotalGB: int64(defGB),

but defGB comes from ldapDefaultTotalGB, and the UI label says "Default total (GB)".

Other client creation paths convert GB to bytes before saving, for example gbToBytes(form.totalGB) in the client form and totalGB * 1024 * 1024 * 1024 in ResetClientTrafficLimitByEmail.

A possible fix would be to convert the LDAP default before assigning it:

TotalGB: int64(defGB) * 1024 * 1024 * 1024,

with 0 still meaning unlimited.

Originally created by @rty813 on GitHub (Jul 7, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5852 ### Describe the bug When LDAP sync auto-creates clients, the "Default total (GB)" setting is written directly into the client `totalGB` field without converting from GB to bytes. For example, if `ldapDefaultTotalGB` is set to `10`, the created client gets `totalGB: 10`, which is treated as 10 bytes, not 10 GB. The client becomes depleted almost immediately. This looks inconsistent with the rest of the UI/API, where `totalGB` is stored in bytes and the frontend converts GB input to bytes before saving. ### How to reproduce 1. Enable LDAP sync. 2. Enable auto-create clients. 3. Set LDAP "Default total (GB)" to a non-zero value, for example `10`. 4. Let LDAP sync create a new client. 5. Inspect the created client record or inbound settings JSON. ### Actual behavior The created client has: ```json "totalGB": 10 ``` The quota is interpreted as 10 bytes. ### Expected behavior The created client should have: ```json "totalGB": 10737418240 ``` for a 10 GB setting. ### Code reference In `internal/web/job/ldap_sync_job.go`, LDAP auto-create currently sets: ```go TotalGB: int64(defGB), ``` but `defGB` comes from `ldapDefaultTotalGB`, and the UI label says "Default total (GB)". Other client creation paths convert GB to bytes before saving, for example `gbToBytes(form.totalGB)` in the client form and `totalGB * 1024 * 1024 * 1024` in `ResetClientTrafficLimitByEmail`. A possible fix would be to convert the LDAP default before assigning it: ```go TotalGB: int64(defGB) * 1024 * 1024 * 1024, ``` with `0` still meaning unlimited.
bsakaguchi 2026-10-31 20:36:53 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jul 7, 2026):

Confirmed in the source. internal/web/job/ldap_sync_job.go:187-198 (buildClient) sets:

TotalGB: int64(defGB),

where defGB comes from GetLdapDefaultTotalGB() (internal/web/service/setting.go:984-986), backed by the ldapDefaultTotalGB setting labeled "Default total (GB)" (internal/web/translation/en-US.json:1397, UI input in frontend/src/pages/settings/GeneralTab.tsx:389-390). This value is entered and stored in GB, but buildClient assigns it straight into Client.TotalGB with no conversion, and Client.TotalGB is documented and used as a byte count everywhere else:

  • internal/database/model/model.go:704 — TotalGB int64 ... // Total traffic limit in GB (comment describes the unit the field is derived from, but the stored value is bytes).
  • frontend/src/pages/clients/ClientFormModal.tsx:170-173 — gbToBytes multiplies by 1024*1024*1024 before saving a client from the panel.
  • internal/web/service/client_inbound_apply.go:1298-1305 — ResetClientTrafficLimitByEmail does c["totalGB"] = totalGB * 1024 * 1024 * 1024.

So a client auto-created by LDAP sync with ldapDefaultTotalGB = 10 ends up with totalGB: 10 (10 bytes), which is effectively an immediate quota exhaustion, matching the reported behavior. Setting ldapDefaultTotalGB = 0 is unaffected since 0 means unlimited on both sides.

The fix suggested in the report is correct and consistent with the rest of the codebase: convert in buildClient (internal/web/job/ldap_sync_job.go:192), e.g. TotalGB: int64(defGB) * 1024 * 1024 * 1024, while continuing to treat 0 as unlimited.

Workaround until fixed: leave ldapDefaultTotalGB at 0 (unlimited) for LDAP auto-created clients, or manually correct the total_gb value in the database / edit the client's traffic limit from the panel after creation.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4904852166 --> @github-actions[bot] commented on GitHub (Jul 7, 2026): Confirmed in the source. `internal/web/job/ldap_sync_job.go:187-198` (`buildClient`) sets: ```go TotalGB: int64(defGB), ``` where `defGB` comes from `GetLdapDefaultTotalGB()` (`internal/web/service/setting.go:984-986`), backed by the `ldapDefaultTotalGB` setting labeled `"Default total (GB)"` (`internal/web/translation/en-US.json:1397`, UI input in `frontend/src/pages/settings/GeneralTab.tsx:389-390`). This value is entered and stored in GB, but `buildClient` assigns it straight into `Client.TotalGB` with no conversion, and `Client.TotalGB` is documented and used as a byte count everywhere else: - `internal/database/model/model.go:704` — `TotalGB int64 ... // Total traffic limit in GB` (comment describes the unit the field is *derived from*, but the stored value is bytes). - `frontend/src/pages/clients/ClientFormModal.tsx:170-173` — `gbToBytes` multiplies by `1024*1024*1024` before saving a client from the panel. - `internal/web/service/client_inbound_apply.go:1298-1305` — `ResetClientTrafficLimitByEmail` does `c["totalGB"] = totalGB * 1024 * 1024 * 1024`. So a client auto-created by LDAP sync with `ldapDefaultTotalGB = 10` ends up with `totalGB: 10` (10 bytes), which is effectively an immediate quota exhaustion, matching the reported behavior. Setting `ldapDefaultTotalGB = 0` is unaffected since `0` means unlimited on both sides. The fix suggested in the report is correct and consistent with the rest of the codebase: convert in `buildClient` (`internal/web/job/ldap_sync_job.go:192`), e.g. `TotalGB: int64(defGB) * 1024 * 1024 * 1024,` while continuing to treat `0` as unlimited. Workaround until fixed: leave `ldapDefaultTotalGB` at `0` (unlimited) for LDAP auto-created clients, or manually correct the `total_gb` value in the database / edit the client's traffic limit from the panel after creation. *This reply was generated automatically; a maintainer may follow up.*
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#4063
No description provided.