{"record":{"id":"698620dd171fb85b","repo":"nats-io/nats-server","slug":"qos-v-is-invalid-in-mqtt","errorCode":null,"errorMessage":"QoS=%v is invalid in MQTT","messagePattern":"QoS=(.+?) is invalid in MQTT","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mqtt.go","lineNumber":4248,"sourceCode":"\t}\n\tif will.retain {\n\t\tpp.flags |= mqttPubFlagRetain\n\t}\n\tc.mu.Unlock()\n\ts.mqttInitiateMsgDelivery(c, pp)\n\tc.flushClients(0)\n}\n\n//////////////////////////////////////////////////////////////////////////////\n//\n// PUBLISH protocol related functions\n//\n//////////////////////////////////////////////////////////////////////////////\n\nfunc (c *client) mqttParsePub(r *mqttReader, pl int, pp *mqttPublish, hasMappings bool) error {\n\tqos := mqttGetQoS(pp.flags)\n\tif qos > 2 {\n\t\treturn fmt.Errorf(\"QoS=%v is invalid in MQTT\", qos)\n\t}\n\n\tif c.mqtt.rejectQoS2Pub && qos == 2 {\n\t\treturn fmt.Errorf(\"QoS=2 is disabled for PUBLISH messages\")\n\t}\n\n\t// Keep track of where we are when starting to read the variable header\n\tstart := r.pos\n\n\tvar err error\n\tpp.topic, err = r.readBytes(\"topic\", false)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif len(pp.topic) == 0 {\n\t\treturn errMQTTTopicIsEmpty\n\t}\n\tif err := mqttValidateTopic(pp.topic, \"topic\"); err != nil {","sourceCodeStart":4230,"sourceCodeEnd":4266,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/mqtt.go#L4230-L4266","documentation":"MQTT PUBLISH parser guard: the QoS bits extracted from the fixed-header flags evaluate to 3, which is a reserved/invalid value in MQTT (only 0, 1, 2 exist). The packet is malformed and the connection is failed.","triggerScenarios":"Thrown at server/mqtt.go:4248 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the publisher's fixed-header flags encoding","Use a spec-compliant MQTT client library"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}