@@ -40,6 +40,13 @@ function isSocketWriteAuthorized(socket) {
4040 return ! ! ( socket && socket . isAuthenticated ) ;
4141}
4242
43+ function isSocketAdminAuthorized ( socket ) {
44+ if ( ! settings || ! settings . secureEnabled ) {
45+ return true ;
46+ }
47+ return ! ! ( socket && socket . isAuthenticated && api ?. authJwt ?. haveAdminPermission ( socket . userGroups ) ) ;
48+ }
49+
4350function init ( _io , _api , _settings , _log , eventsMain ) {
4451 io = _io ;
4552 settings = _settings ;
@@ -197,6 +204,10 @@ function init(_io, _api, _settings, _log, eventsMain) {
197204 // client ask device browse
198205 socket . on ( Events . IoEventTypes . DEVICE_BROWSE , ( message ) => {
199206 try {
207+ if ( ! isSocketAdminAuthorized ( socket ) ) {
208+ logger . warn ( `${ Events . IoEventTypes . DEVICE_BROWSE } : unauthorized request from ${ socket . userId || 'guest' } ` ) ;
209+ return ;
210+ }
200211 if ( message ) {
201212 if ( message . device ) {
202213 devices . browseDevice ( message . device , message . node , function ( nodes ) {
@@ -218,6 +229,10 @@ function init(_io, _api, _settings, _log, eventsMain) {
218229 // client ask device node attribute
219230 socket . on ( Events . IoEventTypes . DEVICE_NODE_ATTRIBUTE , ( message ) => {
220231 try {
232+ if ( ! isSocketAdminAuthorized ( socket ) ) {
233+ logger . warn ( `${ Events . IoEventTypes . DEVICE_NODE_ATTRIBUTE } : unauthorized request from ${ socket . userId || 'guest' } ` ) ;
234+ return ;
235+ }
221236 if ( message ) {
222237 if ( message . device ) {
223238 devices . readNodeAttribute ( message . device , message . node ) . then ( result => {
@@ -278,6 +293,10 @@ function init(_io, _api, _settings, _log, eventsMain) {
278293 // client ask host interfaces
279294 socket . on ( Events . IoEventTypes . HOST_INTERFACES , ( message ) => {
280295 try {
296+ if ( ! isSocketAdminAuthorized ( socket ) ) {
297+ logger . warn ( `${ Events . IoEventTypes . HOST_INTERFACES } : unauthorized request from ${ socket . userId || 'guest' } ` ) ;
298+ return ;
299+ }
281300 if ( message === 'get' ) {
282301 message = { } ;
283302 utils . getHostInterfaces ( ) . then ( result => {
@@ -300,7 +319,7 @@ function init(_io, _api, _settings, _log, eventsMain) {
300319 // client ask device webapi request and return result
301320 socket . on ( Events . IoEventTypes . DEVICE_WEBAPI_REQUEST , ( message ) => {
302321 try {
303- if ( ! isSocketWriteAuthorized ( socket ) ) {
322+ if ( ! isSocketAdminAuthorized ( socket ) ) {
304323 logger . warn ( `${ Events . IoEventTypes . DEVICE_WEBAPI_REQUEST } : unauthorized request from ${ socket . userId || 'guest' } ` ) ;
305324 return ;
306325 }
@@ -326,6 +345,10 @@ function init(_io, _api, _settings, _log, eventsMain) {
326345 // client ask device tags configurtions, used for connections that load tags dinamically (webapi)
327346 socket . on ( Events . IoEventTypes . DEVICE_TAGS_REQUEST , ( message ) => {
328347 try {
348+ if ( ! isSocketAdminAuthorized ( socket ) ) {
349+ logger . warn ( `${ Events . IoEventTypes . DEVICE_TAGS_REQUEST } : unauthorized request from ${ socket . userId || 'guest' } ` ) ;
350+ return ;
351+ }
329352 if ( message && message . deviceId ) {
330353 devices . getDeviceTagsResult ( message . deviceId ) . then ( result => {
331354 message . result = result ;
0 commit comments