Skip to content

Commit 885bed3

Browse files
authored
fix(workflow): bind trigger author to the signed event (#4607)
This change derives `trigger_author` exclusively from the signed event pubkey. Actor tags remain available as event data but cannot override the identity used by author-sensitive workflow conditions. This removes the impersonation path without changing workflow definitions or requiring stored-data migration. ## Testing - `bin/cargo test -p buzz-workflow` at `78819df`: 154 passed, 2 Postgres-dependent tests ignored - `git diff --check origin/main...codex/security-workflow-trigger-author` Originating Buzz thread: `buzz://message?channel=3928fe05-df61-4b5d-b9c7-d623b9b10ea1&id=3c6c02312f763fbe0d2bfc33a6c1a362f91d0354f3d18b039cf7a0558c1439d1` Signed-off-by: Jordan Mecom <[email protected]>
1 parent 997b8ca commit 885bed3

1 file changed

Lines changed: 22 additions & 12 deletions

File tree

  • crates/buzz-workflow/src

‎crates/buzz-workflow/src/lib.rs‎

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -956,18 +956,10 @@ pub fn build_trigger_context(event: &buzz_core::StoredEvent) -> executor::Trigge
956956
let kind_u32 = event_kind_u32(&event.event);
957957
let content = event.event.content.clone();
958958

959-
let author = event
960-
.event
961-
.tags
962-
.iter()
963-
.find_map(|tag| {
964-
if tag.kind().to_string() == "actor" {
965-
tag.content().map(|value| value.to_string())
966-
} else {
967-
None
968-
}
969-
})
970-
.unwrap_or_else(|| event.event.pubkey.to_hex());
959+
// Workflow conditions make authorization decisions from `trigger_author`,
960+
// so it must come from the event signature. An `actor` tag is ordinary
961+
// signer-controlled metadata and cannot speak for another pubkey.
962+
let author = event.event.pubkey.to_hex();
971963

972964
// For reaction events (NIP-25), the content field holds the emoji character
973965
// or shortcode (e.g. "👍", "+", "-"). Expose it as `emoji`.
@@ -1608,6 +1600,24 @@ steps:
16081600
assert!(ctx.author.chars().all(|c| c.is_ascii_hexdigit()));
16091601
}
16101602

1603+
#[test]
1604+
fn build_trigger_context_ignores_actor_tag() {
1605+
use nostr::{EventBuilder, Keys, Kind, Tag};
1606+
1607+
let signer = Keys::generate();
1608+
let impersonated = Keys::generate();
1609+
let event = EventBuilder::new(Kind::Custom(9), "forged actor")
1610+
.tags([Tag::parse(["actor", &impersonated.public_key().to_hex()]).expect("actor tag")])
1611+
.sign_with_keys(&signer)
1612+
.expect("sign");
1613+
let stored = buzz_core::StoredEvent::new(event, Some(uuid::Uuid::new_v4()));
1614+
1615+
let ctx = build_trigger_context(&stored);
1616+
1617+
assert_eq!(ctx.author, signer.public_key().to_hex());
1618+
assert_ne!(ctx.author, impersonated.public_key().to_hex());
1619+
}
1620+
16111621
#[test]
16121622
fn build_trigger_context_message_id_is_hex() {
16131623
let stored = make_message_event();

0 commit comments

Comments
 (0)