From ac44835f6c57d972dff8e124cf6f1ecf1892f6d1 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 29 Jun 2026 04:02:36 +0000 Subject: [PATCH 1/2] fix(audit): record API key internal id as audit actor Requests authenticated with a standard API key produced audit log entries with an empty actor id and internal id. The key role builds a synthetic user with no id, and that user was used as the audit actor, so the actor identity was lost. Enrich the audit actor for standard API keys with the key document's id and sequence so audit entries correctly attribute the acting key. --- app/controllers/shared/api.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 791ab0fe0e..d3b2af0925 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -225,6 +225,13 @@ Http::init() API_KEY_ACCOUNT => ACTOR_TYPE_KEY_ACCOUNT, default => ACTOR_TYPE_KEY_ORGANIZATION, }); + + if ($apiKey->getType() === API_KEY_STANDARD) { + $userClone + ->setAttribute('$id', $dbKey->getId()) + ->setAttribute('$sequence', $dbKey->getSequence()); + } + $auditContext->user = $userClone; } From 4fe26dc30fa9cb453ce5a64f535d8103fd8f8a89 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 29 Jun 2026 08:06:24 +0000 Subject: [PATCH 2/2] fix(audit): record organization key internal id as audit actor Organization API keys use the same key role as standard keys, so the synthetic user with no id was cloned as the audit actor, leaving an empty actor id and internal id on audit entries. Extend the audit actor enrichment to cover organization keys as well, using the already-loaded key document's id and sequence. --- app/controllers/shared/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index d3b2af0925..5ef8eb5021 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -226,7 +226,7 @@ Http::init() default => ACTOR_TYPE_KEY_ORGANIZATION, }); - if ($apiKey->getType() === API_KEY_STANDARD) { + if ($apiKey->getType() === API_KEY_STANDARD || $apiKey->getType() === API_KEY_ORGANIZATION) { $userClone ->setAttribute('$id', $dbKey->getId()) ->setAttribute('$sequence', $dbKey->getSequence());