Skip to content

Decision cache key should include auth mode and policy-relevant inputs #33

Description

@beonde

Problem

The guard decision cache (_decision_cache in guard.py) keys entries on (badge_jws, tool_name) only. However, evaluate_tool_access() decisions also depend on:

  • params_hash
  • server_origin
  • policy_version
  • capability_class / deny_on_unknown_class
  • Auth mode (badge vs API key vs anonymous)

When badge_jws is empty (API-key or anonymous callers), all such requests share the same cache bucket, which can return incorrect decisions.

Additionally, cached results reuse evidence_id / evidence_json, skipping the per-call evidence guarantee.

Current mitigation

The 5-second TTL limits the blast radius. In practice, badge-based auth (the primary path) produces unique JWS strings per identity, so collisions are unlikely for the main use case.

Proposed fix

Either:

  1. Expand the cache key to include (badge_jws or api_key or "anon", tool_name, params_hash, server_origin) and generate fresh evidence IDs on cache hits
  2. Skip caching entirely when badge_jws is absent

Context

Identified during PR #32 code review (Copilot review comments on guard.py:360).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions