Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:AISecurityLab Hackagent Attack Dependency Injection

From Leeroopedia
Knowledge Sources
Domains Security_Testing, Dependency_Injection, Adversarial_Attacks
Last Updated 2026-10-29 00:00 GMT

Overview

An inversion-of-control pattern where attacks never build, configure, or call models on their own — every auxiliary model is a callable supplied from outside.

Description

In HackAgent, attacks are algorithms, not orchestrators. Whatever a technique needs to run is supplied as a callable by the campaign runner:

  • A role is an auxiliary model. Most are Completion callables (chat messages in, reply text out), such as an attacker or a decorator. One, Embedder, provides vectors for retrieval attacks.
  • The target is passed to iterative attacks at run time as a Target callable.
  • The judge is passed as a Judge callable — the campaign's evaluation panel.

This solves a fundamental problem: if attacks build their own model clients, they become tightly coupled to specific providers and configurations. Testing an attack requires a live API key. Changing a model means editing attack code. By inverting control, attacks depend only on the callable interface, and the runner controls which models are used, how they are retried, and how they are traced.

The AttackParams pydantic model enforces this contract: fields annotated with Completion or Embedder are roles; the runner discovers them via introspection and supplies the callables. Required roles are declared via REQUIRED_ROLES.

Usage

Use this principle when designing an attack framework where:

  • Attacks must be testable without live models (inject mocks).
  • The same attack must run against different providers without code changes.
  • The runner must control tracing, retry, and concurrency for all model calls.

Theoretical Basis

The pattern is inversion of control — the attack declares what it needs (roles as typed fields), and the runner supplies how (concrete callables):

# Abstract algorithm (NOT real implementation)
class PairParams(AttackParams):
    attacker: Completion  # role: the runner supplies this
    max_rounds: int = 20  # plain parameter

class Pair(IterativeAttack[PairParams]):
    REQUIRED_ROLES = frozenset({"attacker"})

    async def search(self, goal, target, judge):
        # The attack never builds a model; it calls the supplied role
        prompt = await self.params.attacker([{"role": "user", "content": goal}])
        response = await target([{"role": "user", "content": prompt}])

The AttackParams introspection methods (completion_roles, embedder_roles, role_names) let the runner discover roles and validate them before the attack runs.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment