Skip to content

[Improvement] Privilege array length mismatch in POConverters.fromSecurableObjectPO #10277

@justinmclean

Description

@justinmclean

What would you like to be improved?

POConverters.fromSecurableObjectPO iterates by privilegeNames.size() but indexes privilegeConditions at the same index without validating equal lengths. If persisted JSON arrays are mismatched, runtime deserialization throws IndexOutOfBoundsException, breaking role read paths (for example role fetch/list flows that deserialize securable objects).

How should we improve?

Possibel solution si to validate deserialized inputs before iterating:

  • ensure both lists are non-null,
  • ensure privilegeNames.size() == privilegeConditions.size(),
  • fail fast with a clear exception

Here a test showing the issue:

  @Test
  public void testFromSecurableObjectPOWithMismatchedPrivileges() {
    SecurableObjectPO securableObjectPO =
        SecurableObjectPO.builder()
            .withRoleId(1L)
            .withMetadataObjectId(1L)
            .withType(MetadataObject.Type.CATALOG.name())
            .withPrivilegeNames("[\"USE_CATALOG\", \"CREATE_SCHEMA\"]")
            .withPrivilegeConditions("[\"ALLOW\"]")
            .withCurrentVersion(1L)
            .withLastVersion(1L)
            .withDeletedAt(0L)
            .build();

    Assertions.assertThrows(
        IndexOutOfBoundsException.class,
        () ->
            POConverters.fromSecurableObjectPO(
                "test_catalog", securableObjectPO, MetadataObject.Type.CATALOG));
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions