Browse Source

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.
pull/16304/head
Oleksandra Matviienko 2 months ago
parent
commit
70208ecf1b
  1. 16
      application/src/test/java/org/thingsboard/server/controller/TelemetryControllerTest.java
  2. 4
      dao/src/main/java/org/thingsboard/server/dao/audit/AuditLogServiceImpl.java

16
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";

4
dao/src/main/java/org/thingsboard/server/dao/audit/AuditLogServiceImpl.java

@ -107,7 +107,7 @@ public class AuditLogServiceImpl implements AuditLogService {
public <E extends HasName, I extends EntityId> ListenableFuture<Void>
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<String> keys = extractParameter(List.class, 1, additionalInfo);
ArrayNode attrsArrayNode = actionData.putArray("attributes");

Loading…
Cancel
Save