From 70208ecf1b6da294c2fa68b90d3cc40889317a8e Mon Sep 17 00:00:00 2001 From: Oleksandra Matviienko Date: Wed, 14 Oct 2026 10:15:55 +0200 Subject: [PATCH] Fixed attributes read without scope hanging for sysadmin The sys-tenant audit bypass added for tenant profile actions applied to every action type, so ATTRIBUTES_READ reached constructActionData for SYS_ADMIN with the null scope that the no-scope attributes endpoint passes, and scope.name() threw an NPE inside the Guava callback. The DeferredResult was never completed and the request hung until the async timeout. Limit the bypass to write actions and tolerate a null scope in the ATTRIBUTES_READ/ATTRIBUTES_DELETED action data, which also covers the same NPE for any user when the audit mask is set to RW. --- .../controller/TelemetryControllerTest.java | 16 +++++++++++++++- .../server/dao/audit/AuditLogServiceImpl.java | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/application/src/test/java/org/thingsboard/server/controller/TelemetryControllerTest.java b/application/src/test/java/org/thingsboard/server/controller/TelemetryControllerTest.java index 3ae44db1b0..6d4a582abf 100644 --- a/application/src/test/java/org/thingsboard/server/controller/TelemetryControllerTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/TelemetryControllerTest.java @@ -31,7 +31,8 @@ import static org.thingsboard.server.common.data.query.EntityKeyType.TIME_SERIES @DaoSqlTest @TestPropertySource(properties = { "sql.attributes.value_no_xss_validation=true", - "sql.ts.value_no_xss_validation=true" + "sql.ts.value_no_xss_validation=true", + "audit-log.logging-level.mask.device=RW" }) public class TelemetryControllerTest extends AbstractControllerTest { @@ -291,6 +292,19 @@ public class TelemetryControllerTest extends AbstractControllerTest { Assert.assertTrue(tsDataAfterDeletion.get("key3").get(0).get("value").isNull()); } + @Test + public void testGetAttributesWithoutScopeBySysAdmin() throws Exception { + loginSysAdmin(); + doGetAsync("/api/plugins/telemetry/TENANT/" + tenantId + "/values/attributes").andExpect(status().isOk()); + } + + @Test + public void testGetAttributesWithoutScopeWhenReadAuditEnabled() throws Exception { + loginTenantAdmin(); + Device device = createDevice(); + doGetAsync("/api/plugins/telemetry/DEVICE/" + device.getId() + "/values/attributes").andExpect(status().isOk()); + } + private Device createDevice() throws Exception { String testToken = "TEST_TOKEN"; diff --git a/dao/src/main/java/org/thingsboard/server/dao/audit/AuditLogServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/audit/AuditLogServiceImpl.java index b6824cb21b..5e2b3d72c2 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/audit/AuditLogServiceImpl.java +++ b/dao/src/main/java/org/thingsboard/server/dao/audit/AuditLogServiceImpl.java @@ -107,7 +107,7 @@ public class AuditLogServiceImpl implements AuditLogService { public ListenableFuture logEntityAction(TenantId tenantId, CustomerId customerId, UserId userId, String userName, @NotNull I entityId, E entity, ActionType actionType, Exception e, Object... additionalInfo) { - if (canLog(entityId.getEntityType(), actionType) || (tenantId != null && tenantId.isSysTenantId())) { + if (canLog(entityId.getEntityType(), actionType) || (tenantId != null && tenantId.isSysTenantId() && !actionType.isRead())) { JsonNode actionData = constructActionData(entityId, entity, actionType, additionalInfo); ActionStatus actionStatus = ActionStatus.SUCCESS; String failureDetails = ""; @@ -223,7 +223,7 @@ public class AuditLogServiceImpl implements AuditLogService { case ATTRIBUTES_READ: actionData.put("entityId", entityId.toString()); scope = extractParameter(AttributeScope.class, 0, additionalInfo); - actionData.put("scope", scope.name()); + actionData.put("scope", scope != null ? scope.name() : null); @SuppressWarnings("unchecked") List keys = extractParameter(List.class, 1, additionalInfo); ArrayNode attrsArrayNode = actionData.putArray("attributes");