/** * DelegationScopeGuard (L33) * * Limits what permissions a child agent can inherit from its parent. * Like OAuth token downscoping — a child can only receive a strict subset * of the parent's scopes, and scopes further decay with each delegation hop. * * Threat Model: * - ASI07: Insecure Inter-Agent Communication * - Privilege amplification via delegation (child claims more than parent has) * - Lateral movement through scope inheritance * - Scope laundering (accumulating permissions across hops) * * Protection Capabilities: * - Strict subset enforcement (child ⊆ parent) * - Per-hop scope decay * - Blocked scope list (never inheritable regardless of parent) * - Maximum allowed scope set * - Full delegation audit trail */ export interface DelegationScopeGuardConfig { /** * Maximum fraction of parent scopes a child may inherit per hop (0–1). * 1.0 = child may inherit all parent scopes; 0.5 = at most half; 0 = no inheritance. * Default: 1.0 (no automatic decay — rely on explicit scope lists instead) */ maxScopeInheritance?: number; /** Scopes that can never be delegated to any child, regardless of parent. */ blockedScopes?: string[]; /** * Fraction by which the effective scope set shrinks per delegation hop (0–1). * 0 = no decay; 0.25 = 25% fewer scopes each hop. * Default: 0 (disabled) */ scopeDecayPerHop?: number; /** If set, only these scopes can ever appear in any delegation. */ allowedScopes?: string[]; } export interface DelegationRequest { /** ID of the delegating parent agent */ parentAgentId: string; /** Scopes the parent currently holds */ parentScopes: string[]; /** ID of the child agent receiving delegation */ childAgentId: string; /** Scopes the child is requesting */ requestedScopes: string[]; /** Delegation hop depth (0 = root → first child) */ hopDepth: number; /** Optional justification */ reason?: string; } export interface DelegationScopeResult { allowed: boolean; reason: string; violations: string[]; request_id: string; scope_analysis: { parent_scopes: string[]; requested_scopes: string[]; granted_scopes: string[]; blocked_scopes_found: string[]; out_of_parent_scopes: string[]; exceeds_inheritance_limit: boolean; decay_applied: boolean; effective_max_scopes: number; }; } export declare class DelegationScopeGuard { readonly guardName = "DelegationScopeGuard"; readonly guardLayer = "L33"; private readonly config; /** Audit trail: delegationId → result */ private readonly auditLog; constructor(config?: DelegationScopeGuardConfig); /** * Validate a delegation request and return the actually-grantable scopes. * * @param request - The delegation being attempted * @param requestId - Optional trace ID */ validateDelegation(request: DelegationRequest, requestId?: string): DelegationScopeResult; /** Return the audit trail for a delegation request. */ getAuditLog(requestId: string): DelegationScopeResult | undefined; /** Clear the audit log. */ clearAuditLog(): void; }