Skip to content

Commit 369ffa0

Browse files
wpfleger96HaytDuncan
authored
feat(relay): verify NIP-FI agent tokens and admit agents through owners (#8401)
The relay side of NIP-FI agent tokens. An agent token has its own type, `nip-fi-agent+jwt`, and carries its human owner's pubkey in `nostr_owner_pubkey`. This PR verifies that claim, makes denying or disconnecting the owner cut off every agent that owner authorized, and makes the verified owner decide community admission. A relay without agent support refuses the unknown type, so nothing needs to advertise or configure agent support. The `NIP-FI.md` text for the agent type is included. Builds on #8372 and #8377 (both merged). ### Owner claim and owner deny - **Token type binds the owner claim (`buzz-auth`).** A `DedicatedNipFi` issuer policy accepts `nip-fi+jwt` (human) and `nip-fi-agent+jwt` (agent); `AccessTokenAtJwt` policies stay `at+jwt`-only with their `client_id` and subject rules unchanged, and unknown types are refused. An agent token must carry a lowercase-hex `nostr_owner_pubkey` distinct from its `nostr_pubkey`; a human or `at+jwt` token carrying the claim with any value, including null, is `evidence_rejected`. The verified owner is exposed as `VerifiedAssertion::owner()`. - **No agent switch.** There is no relay setting, NIP-11 field or operator binding field for agent support. - **Session owner.** Each connection records its NIP-FI issuer and the agent's owner (`NipFiSession`) on the root WebSocket manager and the audio registry. `disconnect_nip_fi(iss, target)` closes a connection when either its own key or its recorded owner equals the target. - **Owner deny check.** `nip_fi_core::assertion_denied` checks the deny set for both `(iss, k)` and `(iss, owner)`, and every existing deny check uses it: WebSocket before upgrade and after registration, HTTP, audio, and the shadow observer, so shadow and enforce make the same decisions. The shadow disconnect observer matches a session's key or owner under its issuer with the same rule, so an owner's disconnect records a would-close for its agents. ### Shadow owner check In shadow mode, WebSocket AUTH, audio join and HTTP admission record a `Stage::Owner` verdict when an admitted agent token's owner is banned (`owner/denied`), conflicts with the agent's stored owner (`owner/denied`), or cannot be checked because a read failed (`owner/unavailable`). These are reads only; shadow admission is unchanged. Shadow applies the same stored-owner rule as enforce but never writes the link, so it can't predict a later owner-link write failure, or which of two racing first links wins. ### Admission through the verified owner - **Owner bans, unconditionally.** `community_ban_outcome` takes the token owner and checks its ban in place of a NIP-OA owner. That applies whether the agent is a member itself, the relay is open, or the agent is admitted through its owner. - **Owner-derived membership.** In `api::relay_members::check_membership`, an agent that is a member itself is still admitted first. Otherwise, when a verified assertion names an owner, the owner's membership decides (`MembershipDecision::ViaOwner`), and no NIP-OA is needed on the connection. The issuer has already passed this community's NIP-FI binding check at that point. When a token owner is present it is the only owner considered. - **Stored-owner consistency.** `link_agent_owner` replaces the boolean `materialize_nip_oa_owner` result with `OwnerLink::{Linked, Conflict, Unavailable}`. An unset stored owner is recorded, so relay bans and roster removal of the owner reach the agent through `revoke_live_access`. Shadow and enforce judge the stored owner through one read, `stored_owner_link`, and `link_agent_owner` writes (atomically, first write wins) only when that read finds no owner; a failed read fails closed. If the stored owner differs from the token owner, the request is refused with `authorization denied` on HTTP, WS and audio. A NIP-OA owner conflict keeps its existing link-error refusal. - **One decision on every surface.** Root WS AUTH, audio registration and every NIP-98 HTTP route (bridge, `buzz/v1`, git transport and settings, invites, media, workflows, moderation reads) pass `NipFiAdmission::token_owner()` / `VerifiedAssertion::owner()` into the same ban, membership and owner-link steps. The final socket check rereads bans and writer-side membership; it doesn't reread the owner link, which is written once from NULL. HTTP membership still goes through the bounded replica read. With a verified agent token, every HTTP admission refusal, including the fresh ban rereads in `buzz/v1` and Git settings, is NIP-FI's fixed `authorization_denied` (or `authorization_unavailable` when a dependency fails), and audio checks bans before writing the owner link. `enforce_relay_membership` now takes the `TenantContext`, because it writes the owner link. - **Publishing.** A ban caught while publishing over `POST /events` after the shared membership check is also an admission refusal. Ingest reports it as a typed `IngestError::Ban` (banned, or ban lookup unavailable) at the write gate, the HTTP typing indicator's cached gate, and the moderation and relay-admin command rereads. `IngestError::Ban` carries the legacy error. The bridge turns it into the fixed `authorization denied` / `authorization unavailable` only when the request carries a verified agent token. WebSocket and token-less HTTP responses are byte-for-byte unchanged, and timeouts, scopes, permissions and every other ingest error keep their existing responses. ### Rollout - **Deploy the relay before kgoose.** An older relay refuses `nip-fi-agent+jwt`, so agents are locked out until both are deployed. Humans are unaffected. - **There is no agent-only switch.** Setting NIP-FI to shadow or off turns it off for humans too. - **Rollback is safe for owner links.** Stored owner links survive a rollback, and the older code still honors them. - **Shadow signals:** in `buzz_nip_fi_shadow_total`, `stage="owner"` means an owner would-deny (`owner/denied`) or an owner read that was unavailable (`owner/unavailable`), not a success. A clean agent admission shows as `stage="admit", outcome="admit"`. - **The relay checks that the owner is a member, not which issuer the owner logged in through.** In a community that trusts several issuers, any trusted issuer can name any member as owner. That matches the spec: the issuer is trusted to vouch for the owner, and kgoose requires the owner's attestation. Agent tokens are only issued to relays whose NIP-FI binding trusts the issuer, and NIP-FI itself is off unless configured. No deployed config or secrets change. --------- Signed-off-by: Will Pfleger <[email protected]> Signed-off-by: Duncan <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz> Co-authored-by: Hayt <211b96e6a2b7f45fd4047988976c7bbbeeda0c15f3ae7b32eec20834b5a55118@buzz.block.builderlab.xyz> Co-authored-by: Duncan <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>
1 parent d0dee1c commit 369ffa0

36 files changed

Lines changed: 3630 additions & 548 deletions

‎Justfile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,9 @@ test-unit:
600600
+ test(=handlers::auth::tests::fi_invalid_nip42_proof_emits_terminal_evidence_rejected)
601601
+ test(=handlers::auth::tests::handle_auth_pairing_mismatch_runs_full_root_denial_path)
602602
+ test(=handlers::auth::tests::shadow_root_auth_records_pairing_denial)
603+
+ test(=handlers::auth::tests::shadow_root_auth_records_unavailable_owner_read)
604+
+ test(=handlers::ingest::postgres_tests::relay_admin_ban_maps_to_blocked_auth_failure)
605+
+ test(=handlers::ingest::postgres_tests::relay_admin_internal_maps_to_error_not_client_fault)
603606
+ test(=handlers::auth::tests::shadow_root_invalid_nip42_retires_without_record)
604607
+ test(=handlers::auth::tests::nip42_denial_class_separates_internal_failure_from_bad_evidence)
605608
+ test(=handlers::event::tests::fanout_access::owner_only_kinds_keep_only_the_owner)
@@ -612,6 +615,7 @@ test-unit:
612615
+ test(=state::tests::conn_manager_disconnect_nip_fi_is_issuer_scoped)
613616
+ test(=state::tests::conn_manager_disconnect_nip_fi_sets_authorization_denied_reason)
614617
+ test(=state::tests::nip_fi_disconnect_audio_is_issuer_scoped)
618+
+ test(=state::tests::nip_fi_owner_disconnect_closes_owned_agent_sockets_on_root_and_audio)
615619
+ test(=state::tests::nip_fi_disconnect_closes_proven_audio_socket_and_sends_policy_close_reason)
616620
+ test(=state::tests::nip_fi_disconnect_closes_target_audio_only_and_preserves_collocated_peer)
617621
+ test(=state::tests::nip_fi_disconnect_does_not_close_different_pubkey_audio_socket)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ pub use nip_fi::{
5656
NipFiDenyMap, NipFiMode, NipFiStartupError, ProductionJwksSource, ProvisionBindingError,
5757
ProvisionBindingPolicy, RevalidationDependencies, SubjectClass, SubjectClassContract,
5858
TokenClass, TransportContractId, VerifiedAssertion, VerifierError, VerifyAssertion,
59-
CLIENT_ATTACHED_HEADER, COMMAND_JWT_TYP, MAX_COMMAND_AGE_SECONDS, NOSTR_PUBKEY_CLAIM,
60-
OAUTH_CLIENT_ID_CLAIM,
59+
CLIENT_ATTACHED_HEADER, COMMAND_JWT_TYP, MAX_COMMAND_AGE_SECONDS, NOSTR_OWNER_PUBKEY_CLAIM,
60+
NOSTR_PUBKEY_CLAIM, OAUTH_CLIENT_ID_CLAIM,
6161
};
6262

6363
#[cfg(any(test, feature = "test-utils"))]

‎crates/buzz-auth/src/nip_fi/assertion.rs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ impl fmt::Debug for RevalidationDependencies {
118118
pub struct VerifiedAssertion {
119119
identity: FederatedIdentity,
120120
asserted_key: Option<PublicKey>,
121+
owner: Option<PublicKey>,
121122
capabilities: CanonicalCapabilities,
122123
authority_deadlines: Vec<DateTime<Utc>>,
123124
assertion_policy_id: AssertionPolicyId,
@@ -133,6 +134,7 @@ impl VerifiedAssertion {
133134
issuer: String,
134135
subject: String,
135136
asserted_key: Option<PublicKey>,
137+
owner: Option<PublicKey>,
136138
capabilities: CanonicalCapabilities,
137139
authority_deadlines: Vec<DateTime<Utc>>,
138140
assertion_policy_id: AssertionPolicyId,
@@ -146,6 +148,7 @@ impl VerifiedAssertion {
146148
Self {
147149
identity: FederatedIdentity { issuer, subject },
148150
asserted_key,
151+
owner,
149152
capabilities,
150153
authority_deadlines,
151154
assertion_policy_id,
@@ -165,6 +168,12 @@ impl VerifiedAssertion {
165168
self.asserted_key
166169
}
167170

171+
/// The verified `nostr_owner_pubkey` of an agent assertion; `None` for a
172+
/// key acting for itself.
173+
pub const fn owner(&self) -> Option<PublicKey> {
174+
self.owner
175+
}
176+
168177
/// The canonical closed claims/capabilities carried by the assertion.
169178
pub const fn capabilities(&self) -> &CanonicalCapabilities {
170179
&self.capabilities
@@ -212,6 +221,7 @@ impl VerifiedAssertion {
212221
"https://test.issuer.example".to_owned(),
213222
"test-subject".to_owned(),
214223
Some(asserted_key),
224+
None,
215225
CanonicalCapabilities::from_pairs(vec![]),
216226
vec![Utc::now() + Duration::seconds(3600)],
217227
AssertionPolicyId::zero(),
@@ -258,6 +268,7 @@ impl VerifiedAssertion {
258268
subject: "test-subject".to_string(),
259269
},
260270
asserted_key,
271+
owner: None,
261272
capabilities: CanonicalCapabilities::from_pairs(vec![]),
262273
authority_deadlines,
263274
assertion_policy_id: AssertionPolicyId::zero(),
@@ -272,6 +283,13 @@ impl VerifiedAssertion {
272283
},
273284
}
274285
}
286+
287+
/// Test-only: the same assertion as an agent assertion owned by `owner`.
288+
#[must_use]
289+
pub fn with_owner_for_test(mut self, owner: PublicKey) -> Self {
290+
self.owner = Some(owner);
291+
self
292+
}
275293
}
276294

277295
impl RevalidationDependencies {

‎crates/buzz-auth/src/nip_fi/config.rs‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ pub(crate) const MAX_JTI_BYTES: usize = 512;
7979
/// v2 (PR #7221): `nostr_pubkey` absence now unconditionally rejects — the
8080
/// per-issuer `require_attested_key` knob is removed and the NIP-FI v2 spec
8181
/// requirement is always enforced.
82-
pub(crate) const VERIFIER_CONTRACT_VERSION: u32 = 2;
82+
///
83+
/// v3 (PR #8401): dedicated policies also accept the `nip-fi-agent+jwt` agent
84+
/// type, which requires a `nostr_owner_pubkey` claim (a valid lowercase key
85+
/// distinct from the asserted key); a `nip-fi+jwt` or `at+jwt` token carrying
86+
/// `nostr_owner_pubkey` with any value, `null` included, is rejected.
87+
pub(crate) const VERIFIER_CONTRACT_VERSION: u32 = 3;
8388

8489
/// The transport-contract fingerprint folded into [`TransportContractId`].
8590
/// **Bump on any change** to the client-attached parsing, attachment,
@@ -90,6 +95,10 @@ pub(crate) const TRANSPORT_CONTRACT_VERSION: u32 = 1;
9095
/// "Assertion validation"). Not configurable: other encodings and aliases deny.
9196
pub const NOSTR_PUBKEY_CLAIM: &str = "nostr_pubkey";
9297

98+
/// The fixed name of the owner-key claim on an agent assertion (NIP-FI.md,
99+
/// "Agent keys"). Same encoding as [`NOSTR_PUBKEY_CLAIM`].
100+
pub const NOSTR_OWNER_PUBKEY_CLAIM: &str = "nostr_owner_pubkey";
101+
93102
/// The fixed identity-subject claim. Identity is the exact tuple `(iss, sub)`
94103
/// (NIP-FI.md:35-41), so the subject coordinate is always the JWT `sub` claim
95104
/// and is never deployment-configurable: an operator cannot seal a mutable
@@ -326,7 +335,9 @@ pub enum TokenClass {
326335
/// The mutually exclusive resource-owner/client-subject contract.
327336
subject_class: SubjectClassContract,
328337
},
329-
/// A dedicated Buzz assertion: protected `typ` is exactly `nip-fi+jwt`.
338+
/// A dedicated Buzz assertion: protected `typ` is exactly `nip-fi+jwt`
339+
/// (human; `nostr_owner_pubkey` forbidden) or `nip-fi-agent+jwt` (agent;
340+
/// `nostr_owner_pubkey` required).
330341
DedicatedNipFi,
331342
}
332343

@@ -792,7 +803,7 @@ mod jwks_transport_identity_tests {
792803

793804
assert_eq!(
794805
hex::encode(policy(contract).id().as_bytes()),
795-
"fae0dd479d79306c5eef135594f678a5cdf3a2ee45770e20a7e83395fc76857f",
806+
"29ecb98c34dc7574616d72caf1565cda35585a15f682f0d30f6c011342a555d8",
796807
"public_https mode omits the mesh transport tag"
797808
);
798809
}
@@ -808,7 +819,7 @@ mod jwks_transport_identity_tests {
808819

809820
assert_eq!(
810821
hex::encode(policy(contract).id().as_bytes()),
811-
"dca3e998388ae75bdea6bb2070c8f28b8d389a8b874de96e7852dd1f71b14bcd",
822+
"da846eec66b2e084ac3557d8e5c2a3a2faf12946e965c82d2ef46f91b6fa014e",
812823
"mesh transport is part of policy identity"
813824
);
814825
}

‎crates/buzz-auth/src/nip_fi/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub use community::{CommunityBinding, CommunityBindingError};
3939
pub use config::{
4040
AssertionPolicyId, ClientSubjectPosture, FreshnessClass, IssuerPolicy, IssuerPolicyError,
4141
IssuerRegistry, SubjectClass, SubjectClassContract, TokenClass, TransportContractId,
42-
NOSTR_PUBKEY_CLAIM, OAUTH_CLIENT_ID_CLAIM,
42+
NOSTR_OWNER_PUBKEY_CLAIM, NOSTR_PUBKEY_CLAIM, OAUTH_CLIENT_ID_CLAIM,
4343
};
4444
pub use denial::DenialClass;
4545
pub use deny_map::{CrossPodMergeResult, DenySetFull, IssuerCapacity, NipFiDenyMap};

‎crates/buzz-auth/src/nip_fi/verifier.rs‎

Lines changed: 65 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
//! Corrections applied to the mined #1476 verifier, per the settled spec:
1616
//!
1717
//! - **Token class + `typ` enforcement**: a policy selects exactly one class
18-
//! before parsing claims; `at+jwt` and `nip-fi+jwt` `typ` values are enforced
19-
//! exactly, and the long-form `application/at+jwt` is rejected.
18+
//! before parsing claims; `at+jwt`, `nip-fi+jwt` and `nip-fi-agent+jwt`
19+
//! `typ` values are enforced exactly, and the long-form `application/at+jwt` is rejected.
2020
//! - **ID-token denial**: OIDC ID tokens deny even when `iss`, `aud`, `sub`
2121
//! match, via exact `typ` mismatch against every accepted class.
2222
//! - **Fixed `nostr_pubkey`**: accepted only as lowercase hex of exactly one
@@ -30,8 +30,8 @@ use super::community::CommunityBinding;
3030
use super::config::{
3131
is_asymmetric_algorithm, ClientSubjectPosture, FreshnessClass, IssuerPolicy, IssuerRegistry,
3232
SubjectClass, TokenClass, TransportContractId, MAX_CLIENT_ID_BYTES, MAX_JWKS_KEYS,
33-
MAX_KID_BYTES, MAX_SUBJECT_BYTES, MAX_TOKEN_BYTES, NOSTR_PUBKEY_CLAIM, OAUTH_CLIENT_ID_CLAIM,
34-
SUBJECT_CLAIM,
33+
MAX_KID_BYTES, MAX_SUBJECT_BYTES, MAX_TOKEN_BYTES, NOSTR_OWNER_PUBKEY_CLAIM,
34+
NOSTR_PUBKEY_CLAIM, OAUTH_CLIENT_ID_CLAIM, SUBJECT_CLAIM,
3535
};
3636
use super::denial::DenialClass;
3737
use chrono::{DateTime, TimeZone, Utc};
@@ -392,7 +392,7 @@ impl<S: IssuerKeySource> FederatedAssertionVerifier<S> {
392392
if !policy.algorithms().contains(&header.algorithm) {
393393
return Err(VerifierError::UnsupportedAlgorithm);
394394
}
395-
enforce_token_type(policy.token_class(), header.typ.as_deref())?;
395+
let owner_rule = enforce_token_type(policy.token_class(), header.typ.as_deref())?;
396396

397397
// Resolve the key snapshot internally from the trusted source, keyed by
398398
// the policy's exact `iss`. The snapshot is never a caller argument, so
@@ -440,6 +440,7 @@ impl<S: IssuerKeySource> FederatedAssertionVerifier<S> {
440440

441441
let subject = claim_string(&claims, SUBJECT_CLAIM, MAX_SUBJECT_BYTES)?;
442442
let asserted_key = parse_nostr_pubkey_claim(&claims)?;
443+
let owner = parse_owner_claim(owner_rule, &claims, asserted_key)?;
443444

444445
let now = Utc::now();
445446
let deadlines = self.check_time_and_deadlines(policy, &key_set, &claims, now)?;
@@ -461,6 +462,7 @@ impl<S: IssuerKeySource> FederatedAssertionVerifier<S> {
461462
policy.issuer().to_owned(),
462463
subject,
463464
asserted_key,
465+
owner,
464466
capabilities,
465467
deadlines,
466468
policy.id_for_community(community.expected_aud()),
@@ -746,17 +748,48 @@ fn parse_algorithm(alg: &str) -> Result<Algorithm, VerifierError> {
746748
}
747749
}
748750

749-
/// Enforce the policy's single token class against the header `typ`.
750-
fn enforce_token_type(class: &TokenClass, typ: Option<&str>) -> Result<(), VerifierError> {
751-
match class {
752-
TokenClass::AccessTokenAtJwt { .. } => match typ {
753-
Some("at+jwt") => Ok(()),
754-
_ => Err(VerifierError::TokenTypeRejected),
755-
},
756-
TokenClass::DedicatedNipFi => match typ {
757-
Some("nip-fi+jwt") => Ok(()),
758-
_ => Err(VerifierError::TokenTypeRejected),
759-
},
751+
/// Whether an accepted token type must carry `nostr_owner_pubkey`.
752+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
753+
enum OwnerRule {
754+
/// `nip-fi-agent+jwt`: the owner claim is mandatory.
755+
Required,
756+
/// Every other accepted type: the owner claim must be absent.
757+
Forbidden,
758+
}
759+
760+
/// Enforce the policy's single token class against the header `typ`. The
761+
/// dedicated class has a human (`nip-fi+jwt`) and an agent
762+
/// (`nip-fi-agent+jwt`) type; `at+jwt` policies accept only `at+jwt`.
763+
fn enforce_token_type(class: &TokenClass, typ: Option<&str>) -> Result<OwnerRule, VerifierError> {
764+
match (class, typ) {
765+
(TokenClass::AccessTokenAtJwt { .. }, Some("at+jwt"))
766+
| (TokenClass::DedicatedNipFi, Some("nip-fi+jwt")) => Ok(OwnerRule::Forbidden),
767+
(TokenClass::DedicatedNipFi, Some("nip-fi-agent+jwt")) => Ok(OwnerRule::Required),
768+
_ => Err(VerifierError::TokenTypeRejected),
769+
}
770+
}
771+
772+
/// The `nostr_owner_pubkey` claim, bound to the token type (NIP-FI.md, "Agent
773+
/// keys"): an agent token must carry a canonical owner key distinct from the
774+
/// asserted key; any other type carrying the claim, with any value, denies.
775+
fn parse_owner_claim(
776+
rule: OwnerRule,
777+
claims: &Map<String, Value>,
778+
asserted_key: Option<PublicKey>,
779+
) -> Result<Option<PublicKey>, VerifierError> {
780+
let value = claims.get(NOSTR_OWNER_PUBKEY_CLAIM);
781+
match (rule, value) {
782+
(OwnerRule::Forbidden, None) => Ok(None),
783+
(OwnerRule::Required, None) | (OwnerRule::Forbidden, Some(_)) => {
784+
Err(VerifierError::ClaimRejected)
785+
}
786+
(OwnerRule::Required, Some(value)) => {
787+
let owner = parse_lowercase_hex_key(value)?;
788+
if Some(owner) == asserted_key {
789+
return Err(VerifierError::ClaimRejected);
790+
}
791+
Ok(Some(owner))
792+
}
760793
}
761794
}
762795

@@ -802,21 +835,23 @@ fn enforce_claim_semantics(
802835
fn parse_nostr_pubkey_claim(
803836
claims: &Map<String, Value>,
804837
) -> Result<Option<PublicKey>, VerifierError> {
805-
match claims.get(NOSTR_PUBKEY_CLAIM) {
806-
None => Err(VerifierError::ClaimRejected),
807-
Some(value) => {
808-
let raw = value.as_str().ok_or(VerifierError::ClaimRejected)?;
809-
if raw.len() != 64
810-
|| !raw
811-
.bytes()
812-
.all(|b| b.is_ascii_hexdigit() && !b.is_ascii_uppercase())
813-
{
814-
return Err(VerifierError::ClaimRejected);
815-
}
816-
let key = PublicKey::from_hex(raw).map_err(|_| VerifierError::ClaimRejected)?;
817-
Ok(Some(key))
818-
}
838+
let value = claims
839+
.get(NOSTR_PUBKEY_CLAIM)
840+
.ok_or(VerifierError::ClaimRejected)?;
841+
parse_lowercase_hex_key(value).map(Some)
842+
}
843+
844+
/// Lowercase hex of exactly one 32-byte key; any other encoding denies.
845+
fn parse_lowercase_hex_key(value: &Value) -> Result<PublicKey, VerifierError> {
846+
let raw = value.as_str().ok_or(VerifierError::ClaimRejected)?;
847+
if raw.len() != 64
848+
|| !raw
849+
.bytes()
850+
.all(|b| b.is_ascii_hexdigit() && !b.is_ascii_uppercase())
851+
{
852+
return Err(VerifierError::ClaimRejected);
819853
}
854+
PublicKey::from_hex(raw).map_err(|_| VerifierError::ClaimRejected)
820855
}
821856

822857
/// Capture only the claim names the policy reads into a canonical set. The

0 commit comments

Comments
 (0)