Skip to content

[Bug] Invalid final_mask_settings host row crash-loops the whole panel at startup (FinalMaskNoiseItem rejects type:'rand') #975

Open

Description

@miadabdi

Summary

A single host row with a final_mask_settings value that fails Pydantic validation causes the panel to crash-loop at startup. Because the exception is raised inside the FastAPI lifespan hook, uvicorn exits, Docker restarts the container, and the cycle repeats forever — the web UI and all subscription URLs stay down, and since the API is dead the only recovery is direct database surgery.

Environment

  • Image: pasarguard/panel:latest, app __version__ = 5.4.1
  • Deploy: docker compose (panel + timescaledb + pgbouncer), Postgres backend

What happened

Panel entered a restart loop after a host had this final_mask_settings stored:

{tcp: null, udp: [{type: noise, settings: {reset: 30-60, noise: [{type: rand, packet: 4, delay: 1, apply_to: ip, rand: 10, rand_range: 10}]}}], quic_params: null}

Startup traceback (repeats on every restart):

pydantic_core._pydantic_core.ValidationError: 1 validation error for BaseHost
final_mask_settings.udp.0.noise.0.type
  String should match pattern '^$|^(:?array|str|base64|hex)$' [type=string_pattern_mismatch, input_value='rand', input_type=str]
  File /code/app/lifecycle.py, line 47, in lifespan
  File /code/app/core/hosts.py, line 709, in initialize_hosts
  File /code/app/core/hosts.py, line 567, in setup
  File /code/app/core/hosts.py, line 617, in _add_hosts_local
      serialized_hosts = [BaseHost.model_validate(host) for host in hosts]
ERROR:    Application startup failed. Exiting.

Root cause analysis

Two separate problems:

1. Startup validates every host row and lets one bad row kill the panel

app/core/hosts.py _add_hosts_local() runs BaseHost.model_validate(host) over all hosts inside the lifespan startup path with no per-item error handling. Any schema/Pydantic drift (version upgrades, migration leftovers, externally synced rows, other clients writing configs) bricks the entire panel rather than degrading to "this one host is unavailable".

Suggested fix direction: catch ValidationError per host, log it with the host id, and skip that host so the panel (and subscriptions for other hosts) still comes up.

2. FinalMaskNoiseItem schema rejects values Xray-core accepts

app/models/host.py:

class FinalMaskNoiseItem(FinalMaskBaseModel):
    type: str | None = Field(default=None, pattern=r"^$|^(:?array|str|base64|hex)$")
    packet: str | list[int] | None = Field(default=None)
    delay: str | int | None = Field(default=None)
    rand: int | str | None = Field(default=None)
    rand_range: str | None = Field(default=None, alias="randRange", pattern=r"^\d{1,16}(-\d{1,16})?$")

The model defines rand/rand_range fields (which only make sense for a random-byte noise type) yet type: "rand" — a valid noise type in Xray-core's Freedom/FinalMask noise settings — fails the pattern. So core-valid configs are unrepresentable, and any row carrying one (written by another client / node sync / older version) crashes the panel per problem 1.

Suggested fix direction: either allow rand in the type pattern (aligning with Xray-core), or reject it at the API write boundary with a clear 422 instead of accepting it anywhere it can be stored and then failing at startup.

Workaround we used

UPDATE hosts
SET final_mask_settings = jsonb_set(final_mask_settings::jsonb, '{udp,0,settings,noise,0,type}', '"array"')::json
WHERE id = 29;

(then docker restart the panel container). Note this silently changes the noise semantics of that rule from random bytes to whatever "array" produces.

Impact

  • Availability: total panel + subscription outage from one row
  • Recoverability: API is down, so it can only be fixed via DB access
  • Likelihood: increases with any version drift or external writers of final_mask_settings

Happy to provide the full startup log or test a fix.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions