zigbee2mqtt icon indicating copy to clipboard operation
zigbee2mqtt copied to clipboard

FE crash on malformed percent-encoded request path (res.status is not a function)

Open yo3gnd opened this issue 6 months ago • 0 comments

What happened?

Z2M crashed when its frontend received a malformed percent-encoded HTTP path. The stack ends up in express-static-gzip, which tries to do res.status(400).send(...) after decodeURIComponent(req.path) throws. In Zigbee2MQTT, res at that point is a plain Node ServerResponse, not an Express response, so the process falls over with:

TypeError: res.status is not a function
    at expressStaticGzip (.../express-static-gzip/index.js:37:11)
    at Server.onRequest (/app/lib/extension/frontend.ts:109:21)

The practical result is that one bad request to the frontend can take the whole z2m process down. A silly little HTTP path should not be allowed to pull the plug on the bridge.

What did you expect to happen?

I expected z2m to return 400 Bad Request for the malformed path and carry on with its life.

How to reproduce it (minimal and precise)

  1. Start Zigbee2MQTT with the frontend enabled.
  2. Send a request with an invalid percent-encoded path, for example:
GET /%E0%A4%A HTTP/1.1
Host: <zigbee2mqtt-host>:8080

Zigbee2MQTT version

2.10.0

Adapter firmware version

EZSP v8 6.7.9.0 build 405

Adapter

ezsp (Sonoff ZBBridge + Tasmota, exposed over TCP serial, with serial.adapter: ezsp)

Setup

Plain Zigbee2MQTT in a docker stack with x86 Home Assistant host and some custom containers on that network. Frontend exposed directly on 0.0.0.0:8080. Coordinator is remote over tcp://...:8888.

Device database.db entry

No response

Debug log

No response

Notes

The hardware and ezsp context turned out to be a red herring here. That was merely how I stumbled into it. The actual fault is frontend-side and looks adapter-agnostic: Zigbee2MQTT hands raw Node HTTP objects to express-static-gzip, and the middleware's bad-request path assumes an Express response object.

The trigger in my case was an unrelated local service hitting the frontend port in a shared homelab setup, but the underlying bug is generic: malformed request paths should be handled defensively.

I have a small fix for this which validates request.path before calling the middleware and returns a plain Node 400 response instead of crashing the process.

Possibly related:

  • #29305
  • #25000

yo3gnd avatar May 06 '26 16:05 yo3gnd