Scan, Extract & Call
Stop typing numbers manually. Point your camera at business cards, docs, or screens to extract and dial numbers instantly.
Get Scan2Call 📱As search habits shift from classic index-based search engines to Generative Engine Optimization (GEO) and Answer Engine Optimization (AEO), online merchants must optimize their platforms to be easily read by large language model (LLM) agents. This transition is highly visible in headless commerce, where platforms like Mage-OS—the modern, lightweight, highly compatible alternative to Magento 2—expose GraphQL and REST endpoints directly to the open web. High-performance, crawlable product catalogs are vital for systems like those detailed in Architecting Autonomous AI Shopping Agents: Shopify & Edge AI. However, this open posture creates a significant security risk: User-Agent spoofing.
Malicious actors, competitors, and aggressive scrapers continuously execute distributed denial-of-service (DDoS) campaigns, run vulnerability scanners, and harvest price indexes by copying legitimate user-agents such as ClaudeBot, GPTBot, and Google-Extended. Because legacy security configurations often whitelist these user-agents to preserve SEO and AEO discoverability, spoofed crawlers bypass standard Web Application Firewall (WAF) rules entirely. This allows them to execute highly complex, nested GraphQL queries directly against the application server.
In headless architecture, the target of these attacks is rarely the presentation layer (e.g., Next.js, Nuxt, or Hydrogen). Instead, the target is the headless Mage-OS GraphQL endpoints (/graphql) or REST endpoints (/rest/V1/*). The compute budget required to process a single nested GraphQL query (calculating stock levels, pricing matrices, and catalog rules) can be thousands of times higher than rendering a static HTML page. Flat-blocking all AI bots prevents search optimization, but letting spoofed bots through exposes your architecture to scraping, inventory locking, and performance degradation. Defending this boundary requires a robust headless mage-os security strategy that verifies identity before requests ever hit your servers.
Implementing reverse-DNS (rDNS) checks directly on the origin backend (e.g., inside an Express/NestJS gateway or within the Mage-OS PHP kernel) is highly inefficient. DNS resolution relies on network I/O, which blocks thread execution and consumes socket connections. During a distributed scraping run, executing synchronous getnameinfo or getaddrinfo calls inside your application tier quickly causes resource exhaustion, turning a verification mechanism into a self-inflicted denial-of-service vector.
To eliminate this overhead, security logic must be decoupled from the origin and moved to the edge. Cloudflare Workers serve as a zero-latency gatekeeper. Running on V8 isolates across Cloudflare's global edge network, Workers execute in sub-millisecond start times, capturing incoming API requests before they reach the origin gateway.
An effective edge verification architecture uses a dynamic, asynchronous validation workflow to confirm that the requester is a legitimate bot:
Traffic Ingress: An incoming request targets /graphql with a User-Agent claiming to be ClaudeBot.
Cache Check: The Worker queries Cloudflare Key-Value (KV) storage using the client's IP address as the key. If a validated entry exists, the request is instantly allowed or rejected.
Dynamic Edge Verification: If the IP is unverified, the Worker executes an asynchronous, double-lookup DNS check (rDNS and forward IP lookup) via a secure DNS-over-HTTPS (DoH) API.
Downstream Signing: Upon verification, the Worker generates an HMAC-SHA256 signature using a shared secret. It appends this signature as a custom header to the request before forwarding it to the backend. This allows downstream services to easily confirm the edge-verification status without running redundant checks.
Edge Verification Pipeline:
Client Request → Cloudflare Edge Worker → Cache / DoH Verification → Downstream Origin Gateway (Nginx/Mage-OS)
Using this edge architecture, your origin servers only process validated, cryptographically signed requests. If you are scaling multi-tenant applications or handling high-throughput read paths, routing validated bot traffic to dedicated, lower-priority replicas can help balance load, a design pattern similar to the one discussed in High-Availability Read-Replica Routing in TypeScript with MySQL on GCP.
To implement this edge layer, we write a production-ready Cloudflare Worker in TypeScript using modern ES modules. The worker validates the incoming IP using Cloudflare's DNS-over-HTTPS capabilities and signs the verified payloads.
First, configure the project's local dependency manifest. Ensure you have the Cloudflare Wrangler CLI installed to manage deployments.
{
"name": "edge-bot-validator",
"version": "1.0.0",
"devDependencies": {
"@cloudflare/workers-types": "^4.20240314.0",
"typescript": "^5.4.2",
"wrangler": "^3.35.0"
}
}To safely run DNS lookups within Cloudflare's serverless environment, we query Cloudflare's DNS-over-HTTPS service (cloudflare-dns.com) using JSON payloads. This bypasses the limitations of standard edge environments that lack native Node.js dns module access.
Create a helper module dns.ts to handle the reverse and forward lookups:
// dns.ts
export async function verifyBotDns(ip: string, botDomainSuffix: string): Promise<boolean> {
try {
// 1. Reverse Lookup: Convert IP to pointer record (PTR)
const reverseIp = ip.split('.').reverse().join('.') + '.in-addr.arpa';
const rDnsUrl = `https://cloudflare-dns.com/dns-query?name=${reverseIp}&type=PTR`;
const rDnsResponse = await fetch(rDnsUrl, {
headers: { 'Accept': 'application/dns-json' }
});
const rDnsData: any = await rDnsResponse.json();
if (!rDnsData.Answer || rDnsData.Answer.length === 0) {
return false;
}
const ptrRecord = rDnsData.Answer[0].data;
// Validate that the returned PTR domain ends with the legitimate suffix
if (!ptrRecord.endsWith(botDomainSuffix) && !ptrRecord.endsWith(botDomainSuffix + '.')) {
return false;
}
// 2. Forward Lookup: Ensure the PTR domain points back to the client IP
const fDnsUrl = `https://cloudflare-dns.com/dns-query?name=${ptrRecord}&type=A`;
const fDnsResponse = await fetch(fDnsUrl, {
headers: { 'Accept': 'application/dns-json' }
});
const fDnsData: any = await fDnsResponse.json();
if (!fDnsData.Answer || fDnsData.Answer.length === 0) {
return false;
}
const resolvedIp = fDnsData.Answer[0].data;
return resolvedIp === ip;
} catch (error) {
console.error('DNS Verification Error:', error);
return false;
}
}Next, implement custom request-signing using the WebCrypto API inside crypto.ts to prevent upstream header forgery:
// crypto.ts
export async function signVerificationHeader(
ip: string,
status: string,
timestamp: string,
secret: string
): Promise<string> {
const encoder = new TextEncoder();
const keyData = encoder.encode(secret);
const message = encoder.encode(`${ip}:${status}:${timestamp}`);
const cryptoKey = await crypto.subtle.importKey(
'raw',
keyData,
{ name: 'HMAC', hash: 'SHA-256' },
false,
['sign']
);
const signatureBuffer = await crypto.subtle.sign('HMAC', cryptoKey, message);
// Convert ArrayBuffer to Hex String
return Array.from(new Uint8Array(signatureBuffer))
.map(b => b.toString(16).padStart(2, '0'))
.join('');
}This edge logic is highly effective at filtering out illegitimate traffic. If you lack the in-house resources to design, implement, and maintain advanced serverless pipelines, you can hire TypeScript developer talent or partner with specialized architecture teams to integrate these systems into your deployment workflow.
Once the Cloudflare Worker verifies the bot's identity, the downstream architecture (including your API gateway, proxy layer, and headless Mage-OS application server) must trust and enforce the edge-verification status.
By default, HTTP headers are easily manipulated. We secure our custom status headers by requiring the downstream origin server to validate the HMAC-SHA256 signature generated by the edge worker. This ensures that no client can bypass edge filters by sending pre-crafted X-Bot-Verification-Status headers directly to the backend.
Nginx Reverse Proxy Gatekeeper Configuration
# /etc/nginx/conf.d/mage_os_gatekeeper.conf
server {
listen 80;
server_name api.yourstore.com;
location /graphql {
# Ensure internal services only accept verified headers
set $required_header $http_x_bot_verification_status;
set $expected_sig $http_x_bot_verification_signature;
# Block direct requests claiming to be verified bots that bypass Cloudflare
if ($http_user_agent ~* "(ClaudeBot|GPTBot)") {
set $test_bot "A";
}
if ($http_x_bot_verification_status != "VERIFIED") {
set $test_bot "${test_bot}B";
}
if ($test_bot = "AB") {
return 403 "{\"errors\": [{\"message\": \"Access Denied: Unverified Crawler\"}]}";
}
proxy_pass http://upstream_mage_os;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}For requests that claim to be search crawlers but fail verification, we apply aggressive rate limiting or issue a challenge page (e.g., Cloudflare Turnstile) rather than offering a flat 403 block. This protects the storefront from false positives, such as legitimate, unmapped IP ranges owned by newly launched search partners.
To enforce rate limits directly on unverified bots, configure cloudflare workers rate limiting inside your wrangler.toml profile:
# wrangler.toml rate limiting configuration example
[[unsafe.bindings]]
name = "RATE_LIMITER"
type = "ratelimit"
namespace_id = "1001"
simple = [
{ limit = 10, period = 60 }
]This allows your Edge Worker to throttle unverified requests locally, shielding your API layer from high-volume automated traffic.
Introducing a middleware layer to your network path requires careful performance optimization, especially for a high-traffic headless Mage-OS store where API speed directly impacts conversion rates. Our edge verification model is designed to minimize latency overhead.
By integrating Cloudflare KV caching, we avoid running dynamic DNS-over-HTTPS lookups on every request. Verified IPs are stored directly at the edge, resulting in near-zero latency impact:
Execution Pipeline Stage | Latency Overhead (ms) | Database Load (Origin) |
|---|---|---|
Direct Unverified Request to Origin | 0 ms | 100% (High risk of resource starvation) |
Worker Execution (Cache Hit - Cloudflare KV) | 1.2 - 2.8 ms | 0% (Shielded at the Edge) |
Worker Execution (Cache Miss - Dynamic DNS Resolving) | 45 - 85 ms (First Request Only) | 0% (Shielded at the Edge) |
A cache hit on a pre-validated IP adds less than 3 milliseconds of processing overhead to the request pipeline. Meanwhile, because unverified or spoofed bots are blocked at the edge, the origin application server is shielded from unwanted traffic.
Real-world telemetry shows that on high-traffic storefronts, up to 73% of incoming requests targeting catalog APIs that use crawler user-agents are spoofed. This confirms that implementing validation at the network edge is essential for protecting backend resources.
To safely run edge validation on production commerce APIs, ensure your infrastructure adheres to these technical best practices:
Implement Cryptographic Secret Rotation: Store your shared HMAC signature secret securely within Cloudflare Secrets. Use Wrangler's secret manager to rotate the secret every 90 days: wrangler secret put HMAC_SECRET. Ensure your origin gateways are updated simultaneously to prevent valid traffic from being dropped during rollover.
Design Fail-Safe Fallbacks: If the DNS-over-HTTPS API times out or becomes unreachable, design the worker to fail-open with an active rate-limiter, rather than flat-blocking all traffic. This preserves search indexing availability during global network incidents.
Isolate Sensitive Backend Logic: For multi-tenant or multi-catalog environments, ensure that validated crawler requests are limited to read-only API actions. Never expose write operations, cart checkouts, or user registration to crawlers. This security design principle is similar to the multi-tenant isolation techniques discussed in Row-Level Tenant Isolation in MySQL & TypeScript.
Generate PDF Storefront Indexes: Reduce the resource footprint of search crawlers by pre-generating static documents (such as catalog summaries or data sheets) and caching them at the edge. Utilizing tools like PDFaiGen helps you generate fast, offline-ready documentation that search agents can scan without repeatedly hitting your core database.
To verify claudebot dns manually, perform a reverse DNS lookup on the connecting IP to confirm it resolves to a domain ending in *.crawl.anthropic.com. Then, perform a forward lookup on that domain name to verify it resolves back to the original connecting IP. This prevents IP spoofing.
No. Standard Google crawlers use distinct IP blocks that can be validated using the same double-lookup rDNS methods. By filtering out unverified and spoofed scrapers, you free up server resources, which improves your API response times—a positive factor for SEO rankings.
Yes. Storing verified crawler IPs in Cloudflare KV allows you to cache verification results globally for up to 24 hours. Subsequent requests from those IPs skip dynamic DNS lookup, keeping edge validation overhead under 3 milliseconds.
Securing headless commerce platforms against sophisticated automation requires moving security verification to the network edge. By using Cloudflare Workers, TypeScript, and DNS-over-HTTPS validation, you can filter out spoofed search crawlers before they reach your backend APIs. This architecture protects your database resources, reduces hosting costs, and ensures your legitimate AEO and SEO traffic continues to process without interruption.
import { verifyBotDns } from './dns';
import { signVerificationHeader } from './crypto';
interface Env {
HMAC_SECRET: string;
BOT_CACHE_KV: KVNamespace;
}
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise {
const url = new URL(request.url);
// Only target API endpoints vulnerable to scanning
if (!url.pathname.startsWith('/graphql') && !url.pathname.startsWith('/rest/')) {
return fetch(request);
}
const userAgent = request.headers.get('user-agent') || '';
const clientIp = request.headers.get('cf-connecting-ip') || '';
// Identify if the client claims to be an authorized crawler
const isClaudeBot = userAgent.includes('ClaudeBot');
const isGptBot = userAgent.includes('GPTBot');
if ((isClaudeBot || isGptBot) && clientIp) {
const cacheKey = `bot_status:${clientIp}`;
let verificationStatus = await env.BOT_CACHE_KV.get(cacheKey);
if (!verificationStatus) {
const botDomain = isClaudeBot ? 'crawl.anthropic.com' : 'openai.com';
const isValid = await verifyBotDns(clientIp, botDomain);
verificationStatus = isValid ? 'VERIFIED' : 'SPOOFED';
// Cache result for 24 hours to minimize DNS lookup latency
ctx.waitUntil(env.BOT_CACHE_KV.put(cacheKey, verificationStatus, { expirationTtl: 86400 }));
}
if (verificationStatus === 'SPOOFED') {
return new Response(JSON.stringify({ errors: [{ message: 'Access Denied: Spoofed Crawler Detected' }] }), {
status: 403,
headers: { 'Content-Type': 'application/json' }
});
}
// Inject signed verification headers for the downstream Mage-OS origin
const modifiedHeaders = new Headers(request.headers);
const timestamp = Date.now().toString();
const signature = await signVerificationHeader(clientIp, verificationStatus, timestamp, env.HMAC_SECRET);
modifiedHeaders.set('X-Bot-Verification-Status', verificationStatus);
modifiedHeaders.set('X-Bot-Verification-Timestamp', timestamp);
modifiedHeaders.set('X-Bot-Verification-Signature', signature);
return fetch(new Request(request, { headers: modifiedHeaders }));
}
return fetch(request);
}
};Architecting Autonomous AI Shopping Agents: Shopify & Edge AI: Understand the broader context of how autonomous AI agents interface with headless commerce storefronts and the network architectures designed to support them.
High-Availability Read-Replica Routing in TypeScript with MySQL on GCP: When legitimate crawlers verify successfully, routing their read-heavy catalog requests to secondary database replicas protects your checkout database nodes from exhaustion.
Row-Level Tenant Isolation in MySQL & TypeScript: For multi-tenant headless architectures, securing down-level access models ensures that parsed API payloads never cross tenant boundaries.
Our engineers build threat detection, secure coding, and application security into your stack.