3x-ui/internal/web/service
Grigoriy d7698ec7aa
feat(xray): browse geosite/geoip categories from routing rules (#6165)
* feat(xray): browse geosite/geoip categories from routing rules

Routing rules made you type category names from memory: nothing showed which
categories a database actually contains, what is inside one, or whether a
name resolves at all — a typo only surfaced when Xray refused the config.

The panel now reads Xray's .dat databases itself and exposes them over four
endpoints: databases in the asset folder, a database's categories, one page
of a category's rules, and validation of the tokens already in a rule. The
reader walks the protobuf wire format directly rather than decoding into Go
structs, because a 10 MB geosite.dat holds well over a million domains and
materialising them costs ~284 MB where streaming costs ~19 MB. Only the
category index is cached, entry pages are scanned on demand, and scans are
serialised, so twenty concurrent requests peak at 87 MB instead of 1 GB.
A database's type is decided by its contents, not its file name, since
custom .dat files are named freely.

In the rule form, the source-IP, IP and domain fields gain a database button
opening the browser: search over categories, a preview of what a category
holds, and a multi-select that merges into the field. Plain domains, CIDRs
and categories the panel does not know are left untouched; categories already
present come back ticked, and unticking one removes it from the rule.

* fix(xray): read geo databases through os.Root and match codes verbatim

CodeQL flagged the database read as a path built from a user-supplied value,
and it was right about the shape of it. The file name arrives in a request;
resolve() rejects traversal and stats the file through an os.Root, but the
read itself went through a joined path with os.ReadFile. That left the
symlink defence incomplete: the stat could pass while the read followed a
link planted — or swapped in — afterwards.

Reads now go through the same root, so a request-supplied name never becomes
a path this code resolves on its own, and the size limit is applied to the
opened file rather than to a separate stat of it.

Lookup no longer trims the category code either. It backs the routing-token
validator, and the core matches codes verbatim: "geosite: cn" will not start
Xray, so repairing that space here hid exactly the typo the validator exists
to report.

* fix(xray): address review findings on the geo category browser

Asset folder. The browser read config.GetBinFolderPath() unconditionally,
but the core honours a preset XRAY_LOCATION_ASSET and only falls back to the
bin folder (ensureXrayAssetLocation). On an install pointing at a shared
asset directory the panel listed an empty folder and reported perfectly
valid geosite:/geoip: tokens as missing — the validator warning about a
correct config. The directory is now resolved with the core's precedence.

Paging. Serving one page read and rescanned the whole database, so walking
category-ads-all re-read it per page. The index now records each category's
byte range and a page reads only that record through the os.Root handle,
with the current category's records held for the duration of a paging
session. Profiling that also showed the real cost was not the read but the
slice of payload pointers built per call — a category holds a hundred
thousand of them — so records are now walked with a callback instead.
Ten pages over category-ads-all: 239 MB allocated, now 4.3 MB.

Cached failures. Any error from reading a file was latched under the file's
size+mtime, so a transient ENOMEM or EMFILE marked a healthy database as
damaged until it changed on disk. Only deterministic failures are cached.

Wrong kind. A geoip: token typed into a domain field parsed as a plain
domain and was waved through, though the core cannot resolve it as one. It
is now reported, with its own reason and wording.

Frontend. The category filter fed the query key on every keystroke, so each
character triggered a request that re-scanned the database; it is debounced
now. GeoTokenInput accepts and forwards a ref, so React Hook Form can focus
these three fields on a validation error again. A failed validation shows
that it failed instead of rendering the same empty state as "no issues".

Also drops an unreachable branch in the token-count guard and corrects the
categories endpoint docs, where limit is unbounded by default.

---------

Co-authored-by: STRENCH0 <17428017+STRENCH0@users.noreply.github.com>
2026-08-15 17:12:59 +02:00
..
email
integration
outbound fix(migration): stop a half-applied startup migration from committing silently (#6182) 2026-08-14 20:10:39 +02:00
panel feat(api): scoped, optionally expiring API tokens (#6201) 2026-08-15 15:31:49 +02:00
tgbot test(tgbot): detect open-coded keypad transitions (#6214) 2026-08-15 15:27:02 +02:00
access_log_parse_test.go
api_scale_postgres_test.go feat(sub): add per-client subscription HWID limits (#5802) 2026-08-15 16:50:20 +02:00
backup_filename_test.go
bulk_clients_test.go
bulk_traffic_test.go
client.go feat(sub): add per-client subscription HWID limits (#5802) 2026-08-15 16:50:20 +02:00
client_add_dedupe_test.go
client_apply_field_test.go
client_bulk.go feat(sub): add per-client subscription HWID limits (#5802) 2026-08-15 16:50:20 +02:00
client_bulk_flow_test.go
client_bulk_reenable_test.go
client_bulk_reset_reenable_test.go
client_create_fanout_test.go
client_create_reuse_test.go
client_crud.go feat(sub): add per-client subscription HWID limits (#5802) 2026-08-15 16:50:20 +02:00
client_delete_continue_test.go
client_delete_node_baseline_test.go
client_delete_node_full_test.go
client_delete_tombstone_test.go fix(node): stop the node sync from deleting clients it never meant to 2026-08-01 15:19:08 +02:00
client_effective_flow_test.go
client_email_validation_test.go
client_external_link.go
client_flow_isolation_test.go
client_group_bulk_test.go fix(groups): report changed bulk moves without restarting xray (#6199) 2026-08-14 19:50:06 +02:00
client_group_node_sync_test.go feat(sub): add per-client subscription HWID limits (#5802) 2026-08-15 16:50:20 +02:00
client_group_reset_test.go
client_groups.go fix(groups): report changed bulk moves without restarting xray (#6199) 2026-08-14 19:50:06 +02:00
client_hwid.go feat(sub): add per-client subscription HWID limits (#5802) 2026-08-15 16:50:20 +02:00
client_hwid_test.go feat(sub): add per-client subscription HWID limits (#5802) 2026-08-15 16:50:20 +02:00
client_inbound_apply.go fix(xray): stop the runtime user API from crashing xray-core 2026-07-28 13:52:10 +02:00
client_link.go fix(node): stop the node sync from deleting clients it never meant to 2026-08-01 15:19:08 +02:00
client_locks.go fix(node): stop the node sync from deleting clients it never meant to 2026-08-01 15:19:08 +02:00
client_locks_test.go
client_lookup.go feat(api): add GET endpoint to look up clients by Telegram ID (#5945) 2026-07-28 22:38:44 +02:00
client_lookup_test.go feat(api): add GET endpoint to look up clients by Telegram ID (#5945) 2026-07-28 22:38:44 +02:00
client_paging.go feat(sub): add per-client subscription HWID limits (#5802) 2026-08-15 16:50:20 +02:00
client_paging_test.go perf(clients): make the clients page scale to large panels 2026-07-30 02:49:32 +02:00
client_portable.go feat(sub): add per-client subscription HWID limits (#5802) 2026-08-15 16:50:20 +02:00
client_stat_reuse_test.go feat(sub): add per-client subscription HWID limits (#5802) 2026-08-15 16:50:20 +02:00
client_sync_mtproto_test.go
client_sync_multiprotocol_test.go
client_sync_orphan.go fix(node): stop the node sync from deleting clients it never meant to 2026-08-01 15:19:08 +02:00
client_sync_orphan_test.go fix(node): stop the node sync from deleting clients it never meant to 2026-08-01 15:19:08 +02:00
client_test.go
client_traffic.go feat(sub): add per-client subscription HWID limits (#5802) 2026-08-15 16:50:20 +02:00
client_update_enable_test.go feat(sub): add per-client subscription HWID limits (#5802) 2026-08-15 16:50:20 +02:00
client_update_no_inbound_test.go feat(sub): add per-client subscription HWID limits (#5802) 2026-08-15 16:50:20 +02:00
client_update_rename_test.go feat(sub): add per-client subscription HWID limits (#5802) 2026-08-15 16:50:20 +02:00
client_wireguard.go
client_wireguard_crud_test.go
client_wireguard_test.go
config.json
del_shared_email_runtime_test.go
fallback.go
finalmask_rand_packet_test.go fix(xray): reject configs xray-core refuses, and check the fixtures against it 2026-07-28 14:43:55 +02:00
geodata.go feat(xray): browse geosite/geoip categories from routing rules (#6165) 2026-08-15 17:12:59 +02:00
global_traffic_test.go fix(traffic): apply maintenance side effects only after the commit lands (#6200) 2026-08-14 19:42:09 +02:00
golden_fixtures_xray_test.go chore: refresh dependencies and modernize Go test idioms 2026-07-30 03:14:22 +02:00
host.go
host_test.go
inbound.go fix(traffic): apply maintenance side effects only after the commit lands (#6200) 2026-08-14 19:42:09 +02:00
inbound_autorenew_shadowsocks_test.go fix(traffic): apply maintenance side effects only after the commit lands (#6200) 2026-08-14 19:42:09 +02:00
inbound_autorenew_test.go fix(traffic): apply maintenance side effects only after the commit lands (#6200) 2026-08-14 19:42:09 +02:00
inbound_client_ips.go fix(clients): stop a stale IP row from blocking a client edit 2026-08-02 12:32:45 +02:00
inbound_client_ips_merge_test.go
inbound_client_move_test.go
inbound_client_traffic_test.go
inbound_clients.go
inbound_disable.go fix(traffic): apply maintenance side effects only after the commit lands (#6200) 2026-08-14 19:42:09 +02:00
inbound_durable_postgres_test.go
inbound_fallback_runtime_test.go fix(node): stop the node sync from deleting clients it never meant to 2026-08-01 15:19:08 +02:00
inbound_finalmask_reality_test.go
inbound_finalmask_xmc_test.go feat(xray): update xray-core to v26.7.28 and adapt panel 2026-07-28 13:14:06 +02:00
inbound_flow_restore.go
inbound_flow_restore_test.go
inbound_import_external_proxy_test.go
inbound_import_shared_clients_test.go
inbound_migration.go fix(migration): stop a half-applied startup migration from committing silently (#6182) 2026-08-14 20:10:39 +02:00
inbound_migration_test.go fix(migration): stop a half-applied startup migration from committing silently (#6182) 2026-08-14 20:10:39 +02:00
inbound_mtproto.go fix(node): stop the node sync from deleting clients it never meant to 2026-08-01 15:19:08 +02:00
inbound_mtproto_apply_test.go
inbound_mtproto_client_test.go
inbound_mtproto_desired_test.go fix(node): stop the node sync from deleting clients it never meant to 2026-08-01 15:19:08 +02:00
inbound_mtproto_test.go
inbound_mtproto_txfail_test.go
inbound_node.go fix(node): adopt a matching deployed inbound instead of recreating it (#6197) 2026-08-14 20:01:35 +02:00
inbound_node_ips.go
inbound_node_ips_test.go
inbound_node_reconcile_test.go fix(node): adopt a matching deployed inbound instead of recreating it (#6197) 2026-08-14 20:01:35 +02:00
inbound_options_node_address_test.go
inbound_protocol.go
inbound_protocol_test.go
inbound_settings_clients.go
inbound_settings_clients_test.go
inbound_sub_sort_test.go
inbound_sublink.go
inbound_tgbot_lookup_test.go
inbound_traffic.go fix(traffic): apply maintenance side effects only after the commit lands (#6200) 2026-08-14 19:42:09 +02:00
inbound_traffic_apply.go fix(traffic): apply maintenance side effects only after the commit lands (#6200) 2026-08-14 19:42:09 +02:00
inbound_traffic_global.go
inbound_traffic_reset_test.go inbounds: allow custom monthly traffic reset days (#6071) 2026-07-28 23:27:09 +02:00
inbound_update_tag_test.go
inbound_util.go
key_gen_parse_test.go
metric_history.go
metric_history_test.go
mtproto_fake_test.go
node.go feat(nodes): opt-in encryption at rest for the outbound node API token (#6186) 2026-08-15 16:48:50 +02:00
node_bulk_dispatch_test.go fix(clients): push bulk client changes to nodes only after the commit lands (#6181) 2026-08-14 20:11:19 +02:00
node_client_breakdown_test.go
node_client_expiry_sync_test.go
node_client_renew_sync_test.go
node_client_traffic_sum_test.go
node_contract.go
node_credentials_writeonly_test.go
node_delete_orphan_test.go
node_dirty_test.go
node_host_adopt_test.go
node_mtls.go fix(nodes): apply a rotated master mTLS certificate without restarting the panel (#6194) 2026-08-15 16:03:42 +02:00
node_mtls_test.go fix(nodes): apply a rotated master mTLS certificate without restarting the panel (#6194) 2026-08-15 16:03:42 +02:00
node_netmetrics_test.go
node_origin_guid_test.go
node_push_payload_test.go fix(node): stop the node sync from deleting clients it never meant to 2026-08-01 15:19:08 +02:00
node_shared_guid_test.go
node_sweep_guard_test.go fix(node): stop the node sync from deleting clients it never meant to 2026-08-01 15:19:08 +02:00
node_tag_sync_test.go fix(node): adopt a matching deployed inbound instead of recreating it (#6197) 2026-08-14 20:01:35 +02:00
node_test.go fix(node): adopt a matching deployed inbound instead of recreating it (#6197) 2026-08-14 20:01:35 +02:00
node_token_encryption_test.go feat(nodes): opt-in encryption at rest for the outbound node API token (#6186) 2026-08-15 16:48:50 +02:00
node_tree.go
node_tree_test.go
outbound_subscription.go fix(outbounds): propagate allocation query failures (#6208) 2026-08-14 19:41:24 +02:00
outbound_subscription_ssrf_test.go
outbound_subscription_test.go fix(outbounds): propagate allocation query failures (#6208) 2026-08-14 19:41:24 +02:00
port_conflict.go
port_conflict_test.go
reality_scan.go
reality_scan_test.go
reset_writer_test.go
scale_helpers_test.go
server.go fix(database): create SQLite backup snapshots online (#6137) 2026-07-29 21:04:55 +02:00
server_import_sniff_test.go
server_import_stage_test.go
server_pg_restore_test.go
server_vlessenc_test.go
server_xray_checksum_test.go
setting.go fix(web): fallback to default secret when database setting is empty (#6189) 2026-08-15 16:40:22 +02:00
setting_clash_test.go
setting_factory_defaults_test.go fix(nodes): persist the master mTLS credential atomically and stop silent reissue (#6195) 2026-08-14 20:03:54 +02:00
setting_mtls.go fix(nodes): apply a rotated master mTLS certificate without restarting the panel (#6194) 2026-08-15 16:03:42 +02:00
setting_mtls_test.go fix(nodes): persist the master mTLS credential atomically and stop silent reissue (#6195) 2026-08-14 20:03:54 +02:00
setting_security_test.go fix(web): fallback to default secret when database setting is empty (#6189) 2026-08-15 16:40:22 +02:00
setting_sub_identity_test.go feat(sub): allow identity tokens on every subscription link (#5935) 2026-07-28 22:12:52 +02:00
shadowsocks_client_key_test.go
stream_network_alias_test.go
sub_uri_base_test.go
sync_scale_postgres_test.go
traffic_commit_test.go
traffic_poll_scale_test.go
traffic_runtime_apply_test.go fix(traffic): apply maintenance side effects only after the commit lands (#6200) 2026-08-14 19:42:09 +02:00
traffic_writer.go
traffic_writer_test.go
url_safety.go
ws_payload_scale_test.go
xray.go fix(xray): synchronize lifecycle state (#6138) 2026-07-29 21:00:29 +02:00
xray_config_clients_test.go style: drop the line comments added with the triage fixes 2026-07-27 14:37:57 +02:00
xray_config_inject_test.go
xray_config_scale_test.go
xray_lifecycle_test.go fix(xray): synchronize lifecycle state (#6138) 2026-07-29 21:00:29 +02:00
xray_metrics.go
xray_metrics_test.go
xray_restart_test.go
xray_setting.go fix(xray): synchronize lifecycle state (#6138) 2026-07-29 21:00:29 +02:00
xray_setting_dns_routing.go
xray_setting_dns_routing_test.go
xray_setting_routing_sync.go
xray_setting_routing_sync_test.go
xray_setting_test.go
xray_strip_rules_test.go
xray_wireguard_config_test.go
xray_xhttp_session_test.go