Skip to content

experimental/clashapi: include user in connection metadata#4138

Open
yagjzx wants to merge 93 commits into
SagerNet:testingfrom
yagjzx:clashapi-expose-user-field
Open

experimental/clashapi: include user in connection metadata#4138
yagjzx wants to merge 93 commits into
SagerNet:testingfrom
yagjzx:clashapi-expose-user-field

Conversation

@yagjzx

@yagjzx yagjzx commented May 14, 2026

Copy link
Copy Markdown

The InboundContext.User field is populated by vless / hysteria2 / anytls inbounds with the matched users[].name, but it is not currently included in the JSON output of /connections in clashapi. Without it, downstream consumers (Clash Meta-compatible dashboards, custom traffic accounting) cannot attribute traffic to a configured user.

This adds a single field to the marshalled metadata.

Behaviour

  • For inbounds where a user has been matched, the field returns the configured users[].name (e.g. "user": "alice").
  • For inbounds where no user matching applies (mixed, socks, http, etc.), the field serializes to the empty string. This is non-breaking for any consumer that ignores unknown fields.

Verification

Built locally with the project's standard tags. Spun up a vless inbound with two named users (alice, bob); a client connecting with the alice UUID correctly produced "metadata": { ..., "user": "alice" } in the /connections response. Connections through a non-user-bearing mixed inbound on the same instance correctly produced "user": "".

Why this is useful

Per-user traffic accounting is a common need for any multi-tenant proxy deployment. Today the only way to recover user attribution from clashapi is to give every user their own inbound.tag (which works via metadata.type) — but that explodes the listening-port footprint and requires per-tenant TLS material. Exposing the existing User field is a one-line, zero-cost alternative.

@nekohasekai nekohasekai force-pushed the testing branch 8 times, most recently from 41d2e8c to 812a8fd Compare May 22, 2026 04:03
@nekohasekai nekohasekai force-pushed the testing branch 4 times, most recently from 4de2400 to ba2d6c6 Compare May 31, 2026 10:04
@nekohasekai nekohasekai force-pushed the testing branch 2 times, most recently from 83b7304 to 8a42af3 Compare June 8, 2026 00:52
@nekohasekai nekohasekai force-pushed the testing branch 12 times, most recently from 8ea55ff to a9fe3f3 Compare June 17, 2026 06:56
@nekohasekai nekohasekai force-pushed the testing branch 4 times, most recently from f7ca395 to f27d0e3 Compare June 21, 2026 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants