[GH-ISSUE #5516] [Bug]: Invalid value error for empty rewrite port field in tunnel inbound #3851

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

Originally created by @DenMaxRus on GitHub (Jun 23, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5516

Describe the bug

When typing rewritePort in tunnel inbound, then removing it, json contains "rewritePort": null and on save ui shows settings.rewritePort — Invalid input error. You need to manually remove the whole rewritePort to fix it

How to reproduce the problem

  1. Open Tunnel inbound settings, Protocol tab
  2. Change Rewrite port field to some value, e.g. 12345
  3. Clear Rewrite port field
  4. Go to Json tab
  5. Click save

Expected behavior

Json doesn't contain rewritePort OR rewritePort value is 0. https://xtls.github.io/en/config/inbounds/tunnel.html#inboundconfigurationobject

Actual behavior

Json contains "rewritePort": null and on save ui shows settings.rewritePort — Invalid input error, can't save.

Relevant logs


Screenshots

Image

3x-ui version

3.3.1,3.4.0

Xray-core version

26.6.22

How did you install 3x-ui?

Docker / Docker Compose

Operating system

Ubuntu 24.04

Which parts of the panel are affected?

Frontend (UI / panel pages), Xray config generation

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

Yes — Nginx

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @DenMaxRus on GitHub (Jun 23, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5516 ### Describe the bug When typing `rewritePort` in tunnel inbound, then removing it, json contains `"rewritePort": null` and on save ui shows `settings.rewritePort — Invalid input` error. You need to manually remove the whole `rewritePort` to fix it ### How to reproduce the problem 1. Open Tunnel inbound settings, Protocol tab 2. Change `Rewrite port` field to some value, e.g. `12345` 3. Clear `Rewrite port` field 4. Go to Json tab 5. Click save ### Expected behavior Json doesn't contain `rewritePort` OR `rewritePort` value is 0. https://xtls.github.io/en/config/inbounds/tunnel.html#inboundconfigurationobject ### Actual behavior Json contains `"rewritePort": null` and on save ui shows `settings.rewritePort — Invalid input` error, can't save. ### Relevant logs ```shell ``` ### Screenshots <img width="661" height="504" alt="Image" src="https://github.com/user-attachments/assets/05c23d06-1c5a-4200-93ba-abf0b7fdd31e" /> ### 3x-ui version 3.3.1,3.4.0 ### Xray-core version 26.6.22 ### How did you install 3x-ui? Docker / Docker Compose ### Operating system Ubuntu 24.04 ### Which parts of the panel are affected? Frontend (UI / panel pages), Xray config generation ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? Yes — Nginx ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:35:24 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jun 23, 2026):

This is a confirmed bug in the frontend schema. The root cause is a type mismatch between what Ant Design's InputNumber emits when cleared and what the Zod schema accepts.

What happens step by step

  1. When the user clears the Rewrite port field, Ant Design's InputNumber writes null into the form store — that is its standard behavior for an empty numeric field.
  2. The advanced JSON editor reflects the raw form store, so the JSON tab shows "rewritePort": null.
  3. On save, InboundFormModal.tsx (line 464) runs InboundFormSchema.safeParse(values).
  4. The tunnel settings branch in frontend/src/schemas/protocols/inbound/tunnel.ts declares:
    rewritePort: PortSchema.optional()
    
    where PortSchema (in frontend/src/schemas/primitives/port.ts) is:
    z.number().int().min(1).max(65535)
    
  5. Zod's .optional() permits undefined but not null. The form store value is null, so Zod rejects it with "Invalid input" at path settings.rewritePort.
  6. formatInboundValidation in frontend/src/pages/inbounds/form/formatValidationError.ts formats this as the settings.rewritePort — Invalid input toast the reporter sees.

Why the workaround works

Manually deleting the rewritePort key from the JSON editor sets the form store value to undefined, which .optional() does accept.

Correct fix (for contributors)

In frontend/src/schemas/protocols/inbound/tunnel.ts, change the rewritePort field to accept and normalize null:

rewritePort: PortSchema.nullish().transform(v => v ?? undefined),

nullish() is equivalent to .nullable().optional() — it accepts both null and undefined. The .transform() collapses null to undefined so the field is omitted from the serialized payload (matching the expected behavior described in the issue) rather than sent as null.

A secondary inconsistency: PortSchema enforces min(1), but the InputNumber in frontend/src/pages/inbounds/form/protocols/tunnel.tsx renders with min={0}. Xray's tunnel docs state that rewritePort: 0 means "do not rewrite", so PortSchema.nullish() should arguably use z.number().int().min(0).max(65535) — but that is separate from the crash reported here.

Affected versions: confirmed present in v3.3.1 and v3.4.0 (current release).


This reply was generated automatically by the issue-triage assistant; a maintainer may follow up.

<!-- gh-comment-id:4783109091 --> @github-actions[bot] commented on GitHub (Jun 23, 2026): This is a confirmed bug in the frontend schema. The root cause is a type mismatch between what Ant Design's `InputNumber` emits when cleared and what the Zod schema accepts. **What happens step by step** 1. When the user clears the `Rewrite port` field, Ant Design's `InputNumber` writes `null` into the form store — that is its standard behavior for an empty numeric field. 2. The advanced JSON editor reflects the raw form store, so the JSON tab shows `"rewritePort": null`. 3. On save, `InboundFormModal.tsx` (line 464) runs `InboundFormSchema.safeParse(values)`. 4. The tunnel settings branch in `frontend/src/schemas/protocols/inbound/tunnel.ts` declares: ```ts rewritePort: PortSchema.optional() ``` where `PortSchema` (in `frontend/src/schemas/primitives/port.ts`) is: ```ts z.number().int().min(1).max(65535) ``` 5. Zod's `.optional()` permits `undefined` but **not** `null`. The form store value is `null`, so Zod rejects it with "Invalid input" at path `settings.rewritePort`. 6. `formatInboundValidation` in `frontend/src/pages/inbounds/form/formatValidationError.ts` formats this as the `settings.rewritePort — Invalid input` toast the reporter sees. **Why the workaround works** Manually deleting the `rewritePort` key from the JSON editor sets the form store value to `undefined`, which `.optional()` does accept. **Correct fix (for contributors)** In `frontend/src/schemas/protocols/inbound/tunnel.ts`, change the `rewritePort` field to accept and normalize `null`: ```ts rewritePort: PortSchema.nullish().transform(v => v ?? undefined), ``` `nullish()` is equivalent to `.nullable().optional()` — it accepts both `null` and `undefined`. The `.transform()` collapses `null` to `undefined` so the field is omitted from the serialized payload (matching the expected behavior described in the issue) rather than sent as `null`. A secondary inconsistency: `PortSchema` enforces `min(1)`, but the `InputNumber` in `frontend/src/pages/inbounds/form/protocols/tunnel.tsx` renders with `min={0}`. Xray's tunnel docs state that `rewritePort: 0` means "do not rewrite", so `PortSchema.nullish()` should arguably use `z.number().int().min(0).max(65535)` — but that is separate from the crash reported here. **Affected versions:** confirmed present in v3.3.1 and v3.4.0 (current release). --- *This reply was generated automatically by the issue-triage assistant; 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#3851
No description provided.