Skip to content

Duplicate Fact Sources Created on Every Operation Close #3261

@ChenFryd

Description

@ChenFryd

Describe the bug
_save_new_source() in app/objects/c_operation.py generates a new uuid.uuid4() every time an operation completes. This creates a duplicate fact source on each operation completion, even when a source with the same operation name already exists. Over time, identical fact sources accumulate in the database and clutter the Fact Sources UI page, requiring manual deletion via the API.

To Reproduce

  1. Create an adversary with any abilities
  2. Run an operation using that adversary
  3. Wait for the operation to complete
  4. Run another operation with the same name
  5. Navigate to "Fact Sources" in the Caldera UI
  6. Observe that a new fact source with the same operation name was created for each run

Expected behavior
When an operation completes, _save_new_source() should check if a fact source with the same name already exists. If it does, the existing source should be updated rather than creating a new duplicate entry.

Screenshots
N/A

Desktop (please complete the following information):

  • OS: Ubuntu 22.04
  • Browser: Firefox, Chrome
  • Version : Caldera 5.0.0 (master, commit 4ed3182)

Additional context
The root cause is in app/objects/c_operation.py, line 450:

data = dict(
    id=str(uuid.uuid4()),  # always creates a new ID
    name=self.name,
    ...
)

A fix would be to look up an existing source by name before generating a new UUID:

existing = await services.get('data_svc').locate('sources', match=dict(name=self.name))
source_id = existing[0].id if existing else str(uuid.uuid4())

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions