mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[GH-ISSUE #6014] [Feature]: Automatic rotation of Reality short IDs #4165
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4165
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @nickshiro on GitHub (Jul 17, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6014
Is your feature request related to a problem?
Currently, Reality
shortIdsfor VLESS inbounds must be manually regenerated and updated through the panel whenever a target domain or fingerprint gets flagged by DPI systems. In regions with active DPI (e.g.,Russia's TSPU¹), short ID lists can accumulate detectable statistical patterns over time, and manually rotating them across multiple inbounds is tedious and error-prone, especially when running several Reality inbounds simultaneously.¹ https://ooni.org/post/2024-russia-report/
Describe the solution you'd like
Add an optional auto-renew setting for
Reality shortIdsper inbound, similar to how some panels handle automatic cert renewal. For example,configurable rotation interval(e.g.,every N days) that regenerates a subset or all of the shortIds list automatically. Optional,webhookon rotation so admins running automation (e.g., Telegram bots) can react to the change.Alternatives you've considered
Concrete use case
No response
Mockups, screenshots, or examples
No response
Which parts of the panel would this affect?
backend job, inbound form, subscriptions and node sync.
Are you willing to help?
Before submitting
@github-actions[bot] commented on GitHub (Jul 17, 2026):
Automatic
shortIdsrotation is not currently supported. There is no existing backend or scheduling support to build on, confirmed in the source:shortIdsis a plainstring[]in the Reality schema (frontend/src/schemas/protocols/security/reality.ts:64), stored server-side only inside the opaqueInbound.StreamSettingsJSON column (internal/database/model/model.go:65) — there is no dedicated backend modeling for Reality fields today.shortIds(frontend/src/pages/inbounds/form/security/reality.tsx:139-149) callsrandomizeShortIds()(frontend/src/pages/inbounds/form/useSecurityActions.ts:126-131), which builds new IDs in the browser viaRandomUtil.randomShortIds()(frontend/src/utils/index.ts:174). Unlike the X25519 keypair or ML-DSA-65 seed, which have dedicated server endpoints (/panel/api/server/getNewX25519Cert,/getNewmldsa65), there is no server-side generator forshortIds.internal/web/web.go(roughly lines 313-397); none reference Reality.internal/web/service/tgbot/) and a small in-process event bus with a fixed event enum (internal/eventbus/events.go: outbound up/down, xray.crash, node up/down, cpu/memory high, login.attempt) — nothing Reality-related exists to hook into yet.The closest existing precedent for "auto-renew on an interval" is the traffic-reset feature, a reasonable shape to copy:
Inbound.TrafficReset(enumnever|hourly|daily|weekly|monthly, defaultnever) plusInbound.LastTrafficResetTimetimestamp (internal/database/model/model.go:56-57), consumed byPeriodicTrafficResetJob(internal/web/job/periodic_traffic_reset_job.go) and registered at@hourly/@daily/@weekly/@monthlyininternal/web/web.go:347-353viaInboundService.GetInboundsByTrafficReset. A rotation-interval + last-rotated field on the Reality settings, read by a new job modeled on that one, would fit the existing architecture. The webhook-on-rotation part is separate, larger scope — there is no generic webhook caller anywhere in the backend to extend, so it would mean either building one or routing through the existing tgbot/event-bus path instead.Your second listed alternative already works today:
POST /panel/api/inbounds/update/:id(internal/web/controller/inbound.go:74) accepts the full inbound, includingstreamSettings.realitySettings.shortIds, so an external cron script can PATCH it now.If you go ahead with a PR, note two of this repo's hard requirements for this kind of change: any new
Inbound/settings field needs a GORM migration ininternal/database/db.go, and any new user-facing string (e.g. for a rotation-interval setting or webhook option) needs an English i18n key added to all 13 locale files underinternal/web/translation/.Labeled as a new feature and marked PR-welcomed, matching your intent to implement it. @MHSanaei — flagging for input on scope (rotation-interval design, and whether "notify on rotation" should reuse tgbot/event-bus rather than introduce a new generic webhook subsystem) before implementation starts.
This reply was generated automatically by an AI agent; a maintainer may follow up.
@n0ctal commented on GitHub (Aug 16, 2026):
@nickshiro — you have this marked as one you want to implement, so this is not a claim on it. We run Reality inbounds under TSPU and hit one thing while automating credential rotation elsewhere in our fork that is worth having in mind before the design settles, because it is invisible until real users disconnect.
A client carries one specific
shortId, not the list. The value is baked into the share link and the imported config. So "regenerate the list on a schedule" quietly means "disconnect everyone whose id left the list" — and it surfaces as scattered complaints hours later, not as an obvious failure at rotation time.What works is treating the list as a window rather than a set to replace:
Xray accepts several
shortIdssimultaneously, so nothing breaks while both generations are live.Two smaller notes from the same experience:
Happy to test a PR against live TSPU-facing inbounds once you have one — that is the part we can offer that is hard to come by otherwise.
@nickshiro commented on GitHub (Aug 30, 2026):
@n0ctal Thank you for sharing your experience; I didn't realize this was a complaint about the implementation. You've made some important points. I've also come to the conclusion that rotation shouldn't be instantaneous but should be a replacement process -new requests get new short IDs, and old connections will eventually expire. Together, we're working toward a common goal!
@nickshiro commented on GitHub (Aug 30, 2026):
@n0ctal Regarding the testing, would it be convenient for you to contact me on Telegram?
@n0ctal commented on GitHub (Sep 1, 2026):
Glad the replacement model landed — that is the part that matters. Rotating in place breaks live sessions for no benefit, whereas handing new short IDs to new requests and letting existing connections age out costs nothing and is invisible to users.
On Telegram: I would rather keep this in the issue. Nothing is lost by it — for testing a rotation feature the thread is the better place anyway, since versions, configs and logs stay attached to the discussion instead of scattering through a chat, and anyone hitting the same problem later can read what was actually tried.
I am happy to test. What would be most useful to know before a build exists:
For context on why the interval question is not academic: under active DPI the value of rotation is entirely in not presenting a stable statistical target, so a rotation slower than the observation window buys nothing, and one faster than the subscription refresh interval simply disconnects people. The two constraints meet somewhere quite narrow, and that window is worth stating in the setting's description rather than leaving to be discovered.
@nickshiro commented on GitHub (Sep 1, 2026):
@n0ctal, thanks for your comment.
New requestswas imprecise wording on my side. It means newly generated subscription material, not new transport connections and not rotation triggered by a subscription fetch.Rotation itself is schedule-driven. When an inbound becomes due, the selected active IDs are replaced. From that point:
If several active IDs exist, a new fetch may still receive an unchanged active ID when only part of the set is rotated. The configured rotation interval controls when the active set changes - subscription traffic does not affect that schedule.
Old IDs are moved into a retiring suffix and remain accepted for the configured grace period. This covers more than already-open sessions: a client with an old configuration can also establish new connections during the overlap. After the grace deadline, the maintenance job removes the retiring suffix from the runtime. The job currently runs hourly, so effective retirement occurs between graceHours and graceHours + 1 hour. A second rotation cannot start while the previous retiring set is still present, and validation requires the grace period to be shorter than the rotation interval. Rotation is per inbound. Each enabled vless+reality inbound has its own interval, number of IDs replaced per cycle, grace period, cursor, and next rotation timestamp. The current defaults are 30 days for rotation and 24 hours for grace. You are right that the operational constraint needs to be explicit: the grace period should be longer than the maximum expected subscription refresh interval, with some margin, while the rotation interval should reflect the DPI observation window. I will clarify that in the setting descriptions before asking anyone to test a build. One limitation worth calling out is that the current UI expresses rotation in days and grace in hours. If sub-day rotation is important for the intended DPI scenario, it is better to settle that before the test build rather than hide the limitation in documentation.
I consider this model to be one of the most successful implementations.
@n0ctal commented on GitHub (Sep 1, 2026):
Thanks — that answers all three, and the model holds up. The retiring set accepting new connections during the grace window is the right call: covering only already-open sessions would have left exactly the clients who are offline at rotation time to fail later, which is the failure mode that is hardest to attribute.
On sub-day rotation: days are the right unit, and I want to correct my own framing above.
I wrote that the value of rotation lies in not presenting a stable statistical target to DPI. On reflection that is not right, and it matters here because it is what would have argued for short intervals. A passive observer cannot distinguish a
shortIdfrom random data without the server's key, so there is no stable value for it to fingerprint in the first place.What rotation actually bounds is the lifetime of a configuration that has leaked — a subscription someone obtained, or a config lifted off a device. A valid
shortIdis what lets an active prober confirm what the server really is, rather than being handed the fallback. That is a credential-hygiene problem, and credential lifetimes are measured in days to weeks. An hourly or even four-hourly rotation would buy very little against that and cost a great deal in churn and support. Days in the UI is correct; I would not hold the test build for sub-day granularity.One thing I would change in the defaults, though: a fixed 24-hour grace is a trap.
You have the constraint stated correctly — grace must exceed the maximum expected subscription refresh interval — but leaving it to the operator to satisfy is where this will bite. The panel already knows its own answer:
Profile-Update-Intervalis sent on every subscription response fromApplyCommonHeaders(internal/sub/controller.go), from the sameupdateIntervalsetting the operator configured.So rather than documenting the rule, validate it: refuse a configuration whose grace period is shorter than the panel's own update interval, with margin. An operator who sets weekly subscription updates and leaves grace at the 24-hour default will silently cut off everyone who has not refreshed, and will learn about it from scattered complaints a day later — the same delayed, hard-to-attribute failure the grace window exists to prevent. The panel is in a position to make that configuration unrepresentable, which is better than making it documented.
And one case the model cannot cover, which is worth an explicit decision rather than an omission: a client that imported a link once and never refreshes its subscription. After the grace deadline it stops working with no diagnostic on either side. Nothing in the rotation design can save that user, which is precisely why the rotation event needs to be logged with the inbound tag and a timestamp — when that support ticket arrives weeks later, the log is the only thing that turns "it just stopped" into an answer.
@nickshiro commented on GitHub (Sep 1, 2026):
@n0ctal You’re right on both points; the only question that needs to be resolved before implementation is whether rotation should indeed be prohibited when
subUpdates = 0. From the perspective of the stated safety model, the answer is yes. However, from a semantic standpoint, it’s not entirely clear exactly how the panel should prevent such a scenario. On the one hand, it shouldn’t allow rotation to be enabled ifsubUpdates = 0; on the other hand, there’s the problem that the inbound component knows nothing about the subscriptions for which the update is being configured.Plus, this scenario prevents the manual addition of a key without a subscription, because it will simply fail.
What are your thoughts on this?
@n0ctal commented on GitHub (Sep 2, 2026):
You have found the weakness in my suggestion rather than in your own design, and I would withdraw it. Validating grace against
subUpdatesis checking the wrong thing.subUpdatesis a hint the operator sends to clients, not a fact about them. A client that has been switched off for a week has not refreshed, whatever interval the panel advertises. Worse, the check is trivially satisfiable without being satisfied: an operator who wants rotation sets some non-zero value, validation passes, and nothing about the clients has changed. That is a check which buys confidence rather than safety, which is the kind worth removing.The panel already records the fact instead of the intention.
SubService.RecordSubscriptionFetch(internal/sub/service.go:282) writeslast_sub_fetchon every subscription response, per client:So retirement does not need a configured interval at all. Stamp the rotation with a timestamp, and a retiring
shortIdbecomes droppable once every client of that inbound has alast_sub_fetchnewer than it — with the grace deadline kept as an upper bound so a single abandoned client cannot pin an id forever. Which of the two wins is an operator's choice between "never cut anyone off" and "always retire on schedule", and both are defensible; the point is that the first option becomes available at all.That answers all three of your objections without adding a coupling:
subUpdates = 0stops being a question. The setting plays no part, so there is nothing to reconcile and no configuration to forbid.The layering holds.
last_sub_fetchlives onClientTraffic, and clients already belong to an inbound. The inbound side never needs to know anything about subscription settings — only about its own clients, which it can already see.Manually added keys turn from an obstacle into the answer. A client created by hand, handed a config directly and never fetching a subscription, has no
last_sub_fetchat all. That is precisely the population rotation will break, and the panel can name them: "these seven clients have never fetched; rotating this inbound will cut them off." Forbidding rotation whenever such a client exists would disable the feature on most real deployments, and it would be protecting them from a consequence the operator may well accept. Showing the list lets that be a decision instead of a surprise.It also gives the log entry I asked for earlier something worth logging: not just "rotated at T", but "rotated at T, N clients had not refreshed". When the support ticket arrives three weeks later, that line is the answer.