log-firewall
Installable defences for LLM agents that read logs — tested against published and adaptive log-injection attacks.
An attacker can write text into your logs without logging in: a URL, a User-Agent header, an SSH username, or any
input that lands in an error message. When an AI agent later reads those logs — to triage an alert or debug an
outage — it may obey that text: call a real attack benign, or run the attacker's "fix". log-firewall sits between
your telemetry and your agent and offers several defences, and this repo measures each one — including against
attacks written specifically to beat it.
Research question: do log-injection defences survive an attacker who knows they are there? Short answer: gating the agent's actions holds; filtering what it reads does not. See the numbers below.
Results (headline)
Tool-using SOC responder agent, qwen2.5:7b (simulated tools; attacker goal = close a malicious alert as
benign and allowlist the source). Lower is better except utility.
| Defence | Utility | Malicious called benign | Harmful action executed |
|---|---|---|---|
| none (no defence) | 75% | 87% | 86% |
| best stack (gate + detector + AIOpsShield), fixed attacks | 65% | 6% | 0 / 150 |
| best stack, adaptive attacks aimed at it | 72% | 35% (K1) |
0 / 173 |
The layered stack takes harmful actions from 86% to zero and keeps them there even under adaptive attack. But adaptive attacks push the verdict ("is this malicious?") back up — content filters that redact or rewrite log text are evaded once the attacker knows them. The action gate is what holds.
What beat the content filters (all measured; full table in eval/reports/full.md):
- AIOpsShield (field abstraction), fail-open: an attacker log line in a format it has no template for passes
through raw → conceal
0.3% → 100%. - Trained detector: log-native phrasing found by a small black-box search evades it on most lines; LogJack
hijacks
9% → 22%. - Summarise-then-reason: holds on one model/task but cracks on another — SOC conceal up to
35%,qwen3triage up to50%. - Action gates: hold on forbidden actions (
0/173) but can be steered into allowed harmful ones — e.g.block_ipof your own gateway (40%), or asecretsmanager batch-get-secret-valuethe policy didn't list.
Across three open models (qwen2.5:7b, qwen3:8b, llama3.1:8b) and three attack sets (LogJack, a reconstructed
SOC/triage set, and AIOpsDoom-generated payloads). Full method, per-attack breakdown, hypotheses and Fisher tests:
eval/reports/.
Install
pip install log-firewall # the defences (dependency-free)
pip install "log-firewall[detector]" # + ONNX runtime, to run a trained detector
Use
from log_firewall import make
# 1. Clean a tool result before the agent sees it (strip instruction-like text, kept structure)
defence = make("sanitise")
safe = defence.transform_tool_output("get_logs", raw_tool_result) # pass `safe` to the model
# 2. Or gate the agent's actions: block a command whose justification traces to untrusted log text
gate = make("gate-v2")
decision = gate.check_tool_call("run_command", {"command": "aws iam create-user --user-name x"})
if not decision.allowed:
print("blocked:", decision.reason) # writes need an approved change record
# 3. Defence-in-depth: gate + detector + field abstraction (the strongest combination measured).
# Needs the [detector] extra + a trained model (LOG_FIREWALL_DETECTOR) and your AIOpsShield templates:
# stack = make("gate-v2+detector+aiopsshield")
# Or compose your own from the data-free defences:
from log_firewall import Stack, PolicyGateV2, Sanitise, Quarantine
stack = Stack(PolicyGateV2(), Sanitise(), Quarantine())
Every defence implements the same interface — transform_tool_output(tool_name, text) and
check_tool_call(tool_name, args) — so you can drop it into any agent framework (plain function calls, LangGraph,
the Claude Agent SDK) wherever tool results and tool calls pass through.
The defences
Name (make(...)) |
What it does | Works out of the box? |
|---|---|---|
quarantine |
Wraps tool output in typed, random-tagged "untrusted data" blocks | yes |
sanitise |
Strips instruction-like text, role markers, Unicode tricks, encoded blobs from free-text fields; keeps structure | yes |
gate / gate-v2 |
Vets each tool call: blocks writes and commands whose text traces to untrusted log output | yes |
gate-soc |
The same idea for a SOC agent: persistent config changes (allowlist, suppress) need a human | yes |
detector-heuristic |
Rule-based injection scorer; withholds flagged log lines | yes |
detector |
A fine-tuned small encoder (ONNX, CPU) that scores each line | needs a trained model dir (LOG_FIREWALL_DETECTOR) + [detector] extra |
aiopsshield |
Reconstruction of AIOpsShield (USENIX Sec 2026): replaces attacker-writable fields with tokens | needs templates derived by fuzzing your app |
str |
Summarise-then-reason (Dual-LLM): a tool-less model extracts typed facts; the agent sees only those | needs a model you bind for the extraction call |
The trained detector model and AIOpsShield templates are not shipped (they are app-specific): train/derive your
own (scripts/train_detector.py, docs/detector-model-card.md) or pass your own artifacts.
Honest caveats
- Adaptive attacks beat content filters. Defences that redact or rewrite log text are evaded by an attacker who knows the defence. Treat them as depth, not a boundary; gate the actions.
- Per-model. The same defence helps one model family and hurts another — measure on your model.
- Open-weight models. Results are on
qwen2.5/qwen3/llama3.1; frontier models resist naive payloads more. - Reconstruction.
aiopsshieldis rebuilt from the paper's description (its code is unreleased as of 2026-12); seedocs/aiopsshield-reconstruction.md.
Safety of the test setup
All agent tools in the evaluation harness are simulated. Read tools return canned log text; action tools only record the attempted command. Nothing is ever executed.
Development
Requires uv and GNU Make. The research harness (src/harness) is not part of the
published wheel; it runs from a source checkout.
make install # create the environment
make check # lint, type-check, tests
make fetch-data # download third-party attack data (pinned, hash-checked; not stored in git)
make smoke MODEL=ollama_chat/qwen2.5:3b
Credits and licence
Apache-2.0 (see LICENSE). The harness reuses prompts, tool definitions and scoring from LogJack (MIT, © 2026 Harsh Shah) and generates payloads with AIOpsDoom (Apache-2.0); see NOTICE. AIOpsShield is reproduced from Pasquini et al., When AIOps Become "AI Oops" (USENIX Security 2026). CVE data via the NVD API — this product uses the NVD API but is not endorsed or certified by the NVD.
Metadata
Release files for log-firewall 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| log_firewall-0.1.0.tar.gz | 33.7 kB | Without provenance | Details for log_firewall-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| log_firewall-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for log_firewall-0.1.0-py3-none-any.whl |
Total release size: 73.7 kB
Release files / log_firewall-0.1.0.tar.gz
| Download URL | log_firewall-0.1.0.tar.gz |
|---|---|
| Size | 33.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
285ddad8fd974d5473914c5a6c7d1cae83e7c1e3afe8adfba1b5c231e9f593fb
|
|
BLAKE2b-256 checksum How to use checksums |
e3c62d4262e6bdf858a92aa99d426c6ced16c47475b552284ca311f54e26b258
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Release files / log_firewall-0.1.0-py3-none-any.whl
| Download URL | log_firewall-0.1.0-py3-none-any.whl |
|---|---|
| Size | 40.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2680a98d95f1d8eb915c6d221c3685f682d6a8d719ce2bbdc69a1038ae72bd8e
|
|
BLAKE2b-256 checksum How to use checksums |
bf5d2775633549dfa8062afa6a7ad3c10eaf6b8e0038f670805b86752d143e68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Security for log-firewall 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.