File tree 2 files changed +20
-0
lines changed
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -176,6 +176,12 @@ export default class MQTT {
176
176
skipLog = false ,
177
177
skipReceive = true ,
178
178
) : Promise < void > {
179
+ if ( topic . includes ( '+' ) || topic . includes ( '#' ) ) {
180
+ // https://github.com/Koenkk/zigbee2mqtt/issues/26939#issuecomment-2772309646
181
+ logger . error ( `Topic '${ topic } ' includes wildcard characters, skipping publish.` ) ;
182
+ return ;
183
+ }
184
+
179
185
const defaultOptions = { qos : 0 as const , retain : false } ;
180
186
topic = `${ base } /${ topic } ` ;
181
187
Original file line number Diff line number Diff line change @@ -283,6 +283,20 @@ describe('Controller', () => {
283
283
controller . mqtt . client . reconnecting = false ;
284
284
} ) ;
285
285
286
+ it ( 'Should not allow publishing wildcard characters in topic' , async ( ) => {
287
+ await controller . start ( ) ;
288
+ await flushPromises ( ) ;
289
+ mockMQTTPublishAsync . mockClear ( ) ;
290
+ // @ts -expect-error private
291
+ await controller . mqtt . publish ( 'z2m/#/status' , 'empty' ) ;
292
+ expect ( mockMQTTPublishAsync ) . toHaveBeenCalledTimes ( 0 ) ;
293
+ expect ( mockLogger . error ) . toHaveBeenCalledWith ( `Topic 'z2m/#/status' includes wildcard characters, skipping publish.` ) ;
294
+ // @ts -expect-error private
295
+ await controller . mqtt . publish ( 'z2m/+/status' , 'empty' ) ;
296
+ expect ( mockMQTTPublishAsync ) . toHaveBeenCalledTimes ( 0 ) ;
297
+ expect ( mockLogger . error ) . toHaveBeenCalledWith ( `Topic 'z2m/+/status' includes wildcard characters, skipping publish.` ) ;
298
+ } ) ;
299
+
286
300
it ( 'Load empty state when state file does not exist' , async ( ) => {
287
301
data . removeState ( ) ;
288
302
await controller . start ( ) ;
You can’t perform that action at this time.
0 commit comments