apache / apache/shenyu

[BUG] MqttContext.isValid NPE when client omits password (anonymous/username-only CONNECT)

Open
#6,847 2 comments 0 reactions 1 assignee Claimed by @wy471x View on GitHub
plugin: mqtt priority: high type: bug
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

## Description
`msg.payload().passwordInBytes()` returns null for any CONNECT whose connect-flags password bit is 0 (valid MQTT client — anonymous or username-only). It is passed into `MqttContext.isValid`, which calls `new String((byte[]) null)` → NPE.

## Location
- `shenyu-protocol/shenyu-protocol-mqtt/src/main/java/org/apache/shenyu/protocol/mqtt/Connect.java:60-62`
- `shenyu-protocol/shenyu-protocol-mqtt/src/main/java/org/apache/shenyu/protocol/mqtt/MqttContext.java:48`

## Impact
Handler thread throws; client never receives a CONNACK and the connection hangs.

## Suggested fix
Null-check `passwordInBytes` in `MqttContext.isValid` (treat null as empty).

## Related existing
Distinct from MQTT-09 (#6748, charset decoding of a non-null password) — this is a null-deref on a missing password.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.