Skip to main content

The security layer your agent needs — x402 payment middleware

Project description

DoorNo.402

PyPI npm License: MIT

DoorNo.402 is security middleware for x402 payment requests. It intercepts every 402 response before your agent pays, validates it against known attack patterns, and blocks anything suspicious before a single transaction is signed.

The problem

x402 lets servers charge AI agents for resources over HTTP. The spec has no trust model. Any server can lie about the price, inject instructions into the description field to hijack the agent's LLM, redirect payment to an unknown wallet, or drain the wallet through rapid micro-payments. Without a security layer, your agent pays whatever it is told.

Install

pip install doorno402
npm install doorno402

Quickstart — Python

from doorno402 import protect, PaymentBlockedError
from x402.clients.httpx import x402HttpxClient
from eth_account import Account

account = Account.from_key(private_key)
client = protect(x402HttpxClient(account=account))

resp = await client.get("https://api.example.com/data")
# raises PaymentBlockedError if the 402 payload is malicious

Quickstart — TypeScript

import { protect, PaymentBlockedError } from "doorno402";

const safeFetch = protect(fetch);

const resp = await safeFetch("https://api.example.com/data");
// throws PaymentBlockedError if the 402 payload is malicious

What it catches

# Vulnerability Attack Status
01 Price Inflation Server claims $0.01, charges $5 Covered
02 Unknown Recipient No ENS, zero trust score Covered
03 Redirect Hijack Payment redirected to attacker Covered
04 Prompt Injection LLM override in description Covered
05 Budget Drain Rapid micro-payments Covered
06 TLS Downgrade Payment over HTTP Covered
07 Fake Delivery Empty response after payment Covered

Configuration

protect() accepts three optional parameters:

  • daily_budget (float) — max USD per day, blocks when exceeded
  • mainnet_rpc_url (str) — Ethereum RPC for ENS trust lookups
  • raise_on_block (bool) — raise PaymentBlockedError vs return 403

How it works

DoorNo.402 registers an event hook on your HTTP client. When a server returns a 402 Payment Required response, the hook fires before the payment SDK processes it. The intercepted payload is run through a 7-stage validation pipeline: price inflation check, ENS trust scoring, redirect detection, prompt injection scan, budget enforcement, TLS verification, and delivery validation. If all stages pass, the response is forwarded to the payment SDK for execution. If any stage fails, the response status is mutated to 403 Forbidden and the payment is never signed. When raise_on_block is enabled, a PaymentBlockedError is raised instead.

KeeperHub integration

DoorNo.402 validates. KeeperHub executes. Together they form a complete secure payment pipeline for autonomous agents.

import { interceptAndForward } from "doorno402/mcp";

const safeClient = interceptAndForward(keeperHubClient, {
  dailyBudget: 5.0,
});
await agent.run(safeClient);

When DoorNo.402 approves a payment, forward the validated details to KeeperHub's Direct Execution API for guaranteed on-chain execution with retry logic and audit trail.

Live demo

The repository includes 7 deployed Vercel servers — 6 malicious, 1 honest. Each server targets a different vulnerability from the table above. The CLI runs an autonomous research agent across all 7 servers and produces a results table showing what was blocked and how much was saved.

Site Vulnerability URL
CryptoInsider Price Inflation cryptoinsider-nine.vercel.app
ChainPulse Prompt Injection chainpulse-chi.vercel.app
BlockBrief Budget Drain blockbrief-rho.vercel.app
NodeTimes Unknown Recipient nodetimes.vercel.app
Web3Daily TLS Downgrade web3daily-alpha.vercel.app
ComboAttack All vulnerabilities combo-dusky.vercel.app
ChainWatch Honest server chainwatch-tan.vercel.app

Run the CLI:

cd demo/cli
pip install -r requirements.txt
python run.py

The CLI prompts for a research topic and runs the agent autonomously across all 7 servers.

Project structure

sdk/python/       Python SDK
sdk/ts/           TypeScript SDK
demo/cli/         Interactive CLI with research agent
demo/servers/     6 malicious + 1 honest Express servers
demo/agent/       Standalone agent scripts
demo/landing/     Landing page source
skills/           Agent skill prompt for doorno402

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

doorno402-0.4.0.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

doorno402-0.4.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file doorno402-0.4.0.tar.gz.

File metadata

  • Download URL: doorno402-0.4.0.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for doorno402-0.4.0.tar.gz
Algorithm Hash digest
SHA256 8cd9a0ec72db61a7cf57ebaf5de395d1112e1c9916a3b50983596508866b41f4
MD5 6de66e584267f53362e0dc4bbabd2696
BLAKE2b-256 7b18cd8abbd6f82b2049bdb4209d79611df38585d2c3028a4bddd5cd24eda002

See more details on using hashes here.

File details

Details for the file doorno402-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: doorno402-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for doorno402-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 228536005da8e2bc473ae58400c0b59273d6ce579b8aadcca91c4d68a7739cc4
MD5 cebb381f84bd04b30ea673eacd398580
BLAKE2b-256 d080788365f330cd1676f8891b025fe98914b1e9965aae37fe26501e6175566d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page