# AgentCommerce: Cloudflare, Firewalls and Advanced Setup

> Let the AI agent gateway through Cloudflare, firewalls and HTTP passwords, sign custom REST calls, and set up logs and your server.

---

This page is part of the [AgentCommerce guide](/docs/agentcommerce). Start there for what the extension does, installation, setup and the frequently asked questions.

## Signed REST integrations

### What it does

The REST routes under `/rest/V1/moogento/agentcommerce/` and `/rest/V1/moogento/agentcommercepro/` accept signed requests from custom integrations, using the **Signed REST request secret** shown at agent registration. A fixed Bearer key on `/mcp` authenticates read-only requests. Commerce writes require version 2 signatures, including MCP writes from custom integrations.

### Setup

Send these headers:

```text
X-AgentCommerce-Agent-Id: your-agent-id
X-AgentCommerce-Timestamp: current-unix-time-in-seconds
X-AgentCommerce-Signature-Version: 2
X-AgentCommerce-Nonce: unique-16-to-128-character-nonce
X-AgentCommerce-Signature: lowercase-hex-hmac-sha256
X-Idempotency-Key: unique-retry-key-for-writes
```

For version 2, concatenate these six values in order: `2`, uppercase HTTP method, signing path, timestamp, nonce and exact raw request body. Prefix each value with its decimal byte length and a colon, then calculate `HMAC-SHA256` using the signed REST request secret and encode the result as lowercase hexadecimal. Include `0:` for an empty body. The signing path is `/store/<resolved-store-code>` followed by the normalized API path and the exact query string, including `?`, if present. For example, when the resolved store code is `default`, `/rest/default/V1/...` signs as `/store/default/V1/...`; `/mcp` signs as `/store/<resolved-store-code>/mcp`. Use an empty body for GET or HEAD.

### Notes

- Legacy version 1 signatures remain available for reads: sign `timestamp + "." + raw_request_body` with HMAC-SHA256. They cannot authenticate commerce writes.
- A clock outside **Signature TTL (seconds)** is rejected. Keep server clocks synchronised. Use a fresh 16 to 128 character nonce containing ASCII letters, digits, underscores or hyphens for every version 2 request, including retries; a reused nonce is rejected. An idempotency key may be reused for the same write retry.
- The free module's partner JWT token exchange and Pro's opaque token callback (**External Token Exchange**) are custom integration paths, separate from shopper connections.

## Cloudflare and other firewalls

If your domain is served through Cloudflare, or sits behind any firewall or bot filter, its bot protection can answer AI assistants with a challenge page or a 403. The assistant then fails to connect with no message on its side, even though the store works in a browser.

### Why the AI agent gateway gets blocked

Assistants that shop through the Moogento AI agent gateway do not call your store directly. The gateway is a Cloudflare Worker, so every call it makes to your store:

- comes from Cloudflare's own network (ASN 13335), not from a home or office connection;
- carries no browser user agent, because a server is making the request, not a person.

To Cloudflare's bot protection that looks like an automated client. Bot Fight Mode and Super Bot Fight Mode (the rule shown as "manage definite bots"), and broad custom rules that challenge or block bots or scanners, answer the call with a Managed Challenge. A challenge is a page a person solves in a browser; a server cannot solve it. The gateway then reports the store as unavailable (in gateway logs: `conn_class` `upstream_auth`, upstream status 403). Magento never sees the request, so nothing appears in the AgentCommerce request logs or audit log.

The `/mcp` endpoint does not rely on bot protection for safety. Every gateway call is a signed request that AgentCommerce checks before it answers (see [Signed REST integrations](#signed-rest-integrations)), so letting these paths past bot protection does not open the store to anyone else.

### Find the rule that blocks the gateway

1. In the Cloudflare dashboard open your domain and go to **Security > Analytics**, then the **Events** tab.
2. Add two filters: **Path** equals `/mcp`, and **Source ASN** equals `13335`.
3. Expand the newest event. Read the **Service** (for example **Custom rules** or **Bot fight mode**), the **Ruleset** and the **Rule** name. That is the rule to change.

There can be more than one blocker in a row. After you fix the first, run the search again and re-read Events: a second rule may now be the one answering.

### Fix 1: skip Bot Fight Mode for the agent paths

If the Service is Super Bot Fight Mode (rule "manage definite bots"), add a custom rule that skips it for the agent paths only:

1. Go to **Security > Security rules** and select **Create rule > Custom rules**. Name it "Skip Bot Fight Mode for AI agent gateway".
2. Select **Edit expression** and paste:

```
(http.request.uri.path in {"/mcp" "/.well-known/agent-commerce" "/llms.txt"})
```

3. Under **Choose action** select **Skip**, and tick only **All Super Bot Fight Mode Rules**. Leave managed rules and rate limiting rules unticked.
4. Leave **Log matching requests** on, so the skips show in Security Events.
5. Select **Deploy**.

Skipping only Bot Fight Mode keeps the WAF managed rules (SQL injection and XSS protection) and your rate limits in place on these paths. Those three paths are the ones the gateway calls. To cover every AgentCommerce endpoint (signed REST, `/.well-known/ucp` and the Pro product feed) in one rule, use the wider expression in [Exempt every agent path](#exempt-every-agent-path) below. The wider rule already covers the gateway paths, so create one rule or the other, not both.

### Fix 2: exclude the agent paths from your own bot rules

If the Service is **Custom rules**, one of your own rules (for example a rule that challenges bad bots, WordPress probes or Git scanners) is catching the gateway. Edit that rule and append this to the end of its expression:

```
 and not (http.request.uri.path in {"/mcp" "/.well-known/agent-commerce" "/llms.txt"})
```

Wrap the existing expression in brackets first if it contains `or`, so the exclusion applies to all of it. Do this for every custom rule that blocks or challenges bots.

### No free custom rule slot

Each zone has a fixed number of custom rules: 5 on Free and 20 on Pro. If the list is full, look for two **Skip** rules that skip exactly the same things (same components, same logging). Combine their expressions into one rule with `or`, wrapping each in brackets, for example `(first expression) or (second expression)`, then delete the other rule. That frees a slot without changing what either rule does.

### Free plan

Bot Fight Mode on the Free plan cannot be skipped by a rule. The options are to turn Bot Fight Mode off (**Security > Settings**, filter by **Bot traffic**) or to upgrade to Pro, where Super Bot Fight Mode can be skipped with Fix 1. More detail is in [Exempt every agent path](#exempt-every-agent-path).

### Check it works

- Ask an AI assistant connected to your store to search for a product you know is in stock. Products in the answer mean the gateway reached the store.
- Or re-read **Security > Analytics > Events** with the same filters. New `/mcp` events should show your Skip rule (with logging on) and no Managed Challenge.

Other firewalls and bot filters (a host-level WAF, a security plugin, a reverse proxy with bot rules) need the same idea, and so does an HTTP password (see [Stores behind an HTTP password](#stores-behind-an-http-password-basic-auth)): let `/mcp`, `/.well-known/agent-commerce` and `/llms.txt` through bot checks, and keep the rest of their protection on.

### Stores behind an HTTP password (Basic Auth)

Staging and development sites often sit behind an HTTP password: the browser asks for a user name and password before the site loads. The gateway cannot answer that prompt, so the web server refuses it before Magento runs.

**How to recognise it.** The gateway reports `conn_class` `upstream_auth` with upstream status **401** (a Cloudflare challenge gives 403). The store's access log shows `POST /mcp` with status 401 and no body, and a `curl -i -X POST https://yourstore.com/mcp` response carries a `WWW-Authenticate: Basic` header.

**Fix on Apache 2.4.** In the `.htaccess` file in the store's web root, leave the existing password block as it is and add this line after it:

```apache
Require expr %{THE_REQUEST} =~ m#^[A-Z]+ /(mcp|\.well-known/agent-commerce|llms\.txt)(\?[^ ]*)? HTTP/#
```

Two `Require` lines at the same level mean "either is enough", so these three paths open without the password and the rest of the site keeps it. The `/mcp` endpoint still checks its own signed-request authentication.

- The rule reads `THE_REQUEST` (the original request line) on purpose. Magento rewrites every request to `index.php` and Apache checks the password again on the rewritten address, where a `SetEnvIf Request_URI` match no longer applies.
- On cPanel, do not edit inside the "Password Protected Directories" block that cPanel manages. Add the line after it, or cPanel may overwrite it.

**Fix on nginx.** Add a `location` block for `/mcp`, `/.well-known/agent-commerce` and `/llms.txt` with `auth_basic off;`, passing the request to Magento the same way as your main `location` block.

**Check it works.**

- The homepage still asks for the password.
- `/llms.txt` returns 200 without a password.
- An unsigned `POST /mcp` now returns Magento's JSON 401 "Agent authentication failed". That is expected: it means the request reached AgentCommerce, which then asks for a signed request. Apache's own 401 page means the line is not taking effect.

### Exempt every agent path

The **Setup Wizard** page shows a **Cloudflare** item when the store responds through Cloudflare. It requests `/.well-known/agent-commerce` with a non-browser user agent from your server, reports **OK**, **Blocked** or **Unknown**, and caches the result for a day (**Check again** refreshes it). Because the request comes from your own server, treat it as a guide: an assistant's network can be treated differently.

Exempt these paths for AI agents:

- `/mcp`
- `/.well-known/agent-commerce`
- `/.well-known/ucp`
- `/llms.txt`
- `/rest/.../V1/moogento/agentcommerce/*` (signed REST)
- `/agentconnect/feed/*` (Pro product feed)

**Pro, Business and Enterprise plans.** Super Bot Fight Mode can be skipped with a custom rule:

1. In the Cloudflare dashboard open your domain and go to **Security > Security rules**.
2. Select **Create rule > Custom rules** and name it "Allow AI agents (AgentCommerce)".
3. Select **Edit expression** and paste (replace `yourstore.com` with your host name, or drop the first `http.host` clause to cover the whole zone):

```
(http.host eq "yourstore.com") and (http.request.uri.path in {"/mcp" "/.well-known/agent-commerce" "/.well-known/ucp" "/llms.txt"} or http.request.uri.path contains "/V1/moogento/agentcommerce/" or starts_with(http.request.uri.path, "/agentconnect/feed/"))
```

4. Under **Choose action** select **Skip**. Tick **All Super Bot Fight Mode rules**. Leave **All managed rules** and **All rate limiting rules** unticked.
5. Under **More components to skip** tick **Browser Integrity Check** and **Security Level**. Tick **User Agent Blocking** only if a user agent rule is what blocks the agents. WAF managed rules stay on, so SQL injection and XSS protection still applies to these endpoints.
6. Move the rule to the top of the list (rules run in order) and select **Deploy**.
7. Return to the Setup Wizard page and select **Check again**.

**Free plan.** Bot Fight Mode cannot be skipped by a rule or limited to a path. To stop it challenging agents, go to **Security > Settings**, filter by **Bot traffic** and turn **Bot fight mode** off for the whole domain. Custom rules exist on every plan, so you can still add the rule above with the Skip action for **Browser Integrity Check** and **Security Level**, leaving managed rules unticked so WAF managed rules stay on. To keep bot protection on the rest of the site, upgrade to Pro or higher and use Super Bot Fight Mode with the Skip rule.

Cloudflare references: [Bot Fight Mode](https://developers.cloudflare.com/bots/get-started/bot-fight-mode/), [Super Bot Fight Mode](https://developers.cloudflare.com/bots/get-started/super-bot-fight-mode/), [Skip action](https://developers.cloudflare.com/waf/custom-rules/skip/), [skip options](https://developers.cloudflare.com/waf/custom-rules/skip/options/).

## Logs and server setup

### What it does

Audit logging records agent activity to `var/log/moogento_agentcommerce.log` and, with Pro, `var/log/moogento_agentcommercepro.log`.

### Setup

1. Turn on **Enable: Audit logging** and choose a **Log masking mode** in **General**.
2. Keep the **Developer: Debug** payload and internal-message switches off on a public store, because raw payloads can include personal data.
3. Route `/.well-known/agent-commerce`, `/llms.txt`, `/shop-with-ai` and `/mcp` to Magento. A CDN must not cache MCP responses. Behind Cloudflare, also exempt the agent paths from bot protection; see [Cloudflare and other firewalls](#cloudflare-and-other-firewalls).

### Notes

- If a reverse proxy sits in front of Magento, forward `Authorization` for MCP Bearer connections, the `X-AgentCommerce-*` signing headers for signed REST and MCP calls, and `X-Idempotency-Key` for retries on either transport.

---

## Other pages in this guide

- [AgentCommerce overview, setup and FAQs](/docs/agentcommerce)

<!-- docs-split: part-of="agentcommerce" -->
