Principle:AISecurityLab Hackagent Attack Dependency Injection
| 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
- Implementation:AISecurityLab_Hackagent_AttackParams
- Implementation:AISecurityLab_Hackagent_resolve_campaign
- Implementation:AISecurityLab_Hackagent_StaticAttack
- Implementation:AISecurityLab_Hackagent_IterativeAttack
- Implementation:AISecurityLab_Hackagent_AutoDANTurboParams
- Implementation:AISecurityLab_Hackagent_BoNParams
- Implementation:AISecurityLab_Hackagent_PAPParams
- Implementation:AISecurityLab_Hackagent_TapParams
- Implementation:AISecurityLab_Hackagent_CrescendoParams
- Implementation:AISecurityLab_Hackagent_Attack_Registry
- Implementation:AISecurityLab_Hackagent_ModelFactory