Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › AI coding agents

Bot Protection for Web Apps: The Four-Layer System I Asked an AI Agent to Build

By Freedom251 Team · · 10 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

An AI coding agent can add practical bot-abuse defenses to a web app, but only if the task specifies what to inspect, what to change, and how to prove the changes work. The four-layer system in Jaber Said’s August 31, 2026 article combines request interception, API validation, a frontend honeypot, and deployment hardening. Its most important lesson is not that a prompt guarantees security: the first implementation missed key protections, and the author found bot User-Agents still receiving successful responses. The refined prompt named implementation points and required verification; Said reports that all 17 checklist items passed on the second run.

This is a practical baseline for deterring common automated abuse, not a replacement for application security or defenses against sophisticated, distributed attacks. The useful approach is to make the agent map the project first, apply controls that fit its framework and hosting, then test the actual responses and configuration yourself.

As an Amazon Associate I earn from qualifying purchases.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What does this four-layer bot-protection system do?

It puts several modest defenses at different points in a request’s path: an interceptor can reject obvious automation before route handlers run; API guards can reject malformed or unexpected submissions; a honeypot can catch simplistic form-filling bots; and deployment settings can reduce exposure or unnecessary work. No single layer is expected to identify every bot.

Said describes building the prompt after abnormal traffic and server-function activity affected two production apps hosted on Vercel: Vocab Top and Prompt Builder, which he described as having more than 7,000 templates. The incident illustrates why an apparent traffic spike matters beyond analytics: requests that reach server functions can consume application resources even when they do not represent real users.

#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter | 4Pack Type C Female to A Male Cable Converter for Apple Duo 17 16 15 14 Plus,iWatch Watch 12 11 10,iPad 9 8 Air,Airpods 5 4
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

The prompt’s premise is to have the coding agent inspect the project’s framework, runtime, hosting platform, routes, and forms before changing code. That inspection matters because a security feature placed in the wrong file, or applied only to the frontend while an API remains exposed, can look complete in a summary without protecting the relevant request path.

What should the AI agent inspect before changing code?

Start by asking the agent to map the app rather than immediately asking it to add generic security middleware. It should identify where requests enter, which endpoints accept user input, how the app is deployed, and which platform-specific mechanisms already exist.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Framework and runtime: determine the framework, language, runtime, and existing middleware or hooks.
  • Hosting and deployment: identify the deployment platform and how request headers, server functions, and static assets are served.
  • Routes and APIs: find endpoints that accept requests or trigger costly work, including routes not directly linked from the interface.
  • Forms: locate public forms and trace where their submitted data is handled.
  • Existing controls: inspect current validation, rate limiting, headers, cache policy, and source-map configuration before proposing replacements.

Ask for a list of the files and routes the agent intends to change, the purpose of each change, and the tests it will run. This makes omissions easier to catch: if the plan mentions deployment headers but says nothing about API routes or request interception, the implementation scope is incomplete before code is written.

Where does the request interceptor belong?

The first layer runs before route handlers so it can reject or limit requests early. The correct file or hook depends on the project; Said’s prompt maps common platforms to their native entry points and tells the agent to avoid new packages when built-in features suffice.

Platform or framework Implementation point named in the prompt
Next.js Root middleware.js or middleware.ts
Nuxt Server middleware
SvelteKit hooks.server.ts
Express app.use()
Flask before_request
Django A custom middleware class
Laravel HTTP middleware
Cloudflare Pages _middleware.ts
Nginx or Apache Native server rules

At that boundary, the system asks the app to apply four checks:

Rank #2
Sale
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter | USB C Dongle with 90W Max Power Delivery, 3×5Gbps USB A Data Ports, for MacBook, Dell, and More (Charger Not Included)
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
  1. Recognize known automation strings. Match known bot or automation User-Agent values and return a silent 404 for blocked requests. User-Agent is a signal, not proof of identity: clients can change it, so this check should not be treated as authentication.
  2. Preserve legitimate search crawling. Exempt legitimate search crawlers from the automation block so the rule does not indiscriminately shut out indexing. The verification plan should include an expected successful response for Googlebot; do not assume a User-Agent label alone proves a request is genuinely from a crawler.
  3. Check API request origin. For API requests, enforce an Origin or Referer policy appropriate to the app. This can screen unexpected browser-originated requests, but it is not a substitute for authorization or a reliable identity check for every type of client.
  4. Apply a per-IP sliding-window limit. The prompt’s default is 30 requests per IP per 60-second window, a configuration recommended by Said in 2026—not a measured universal optimum. Once the threshold is exceeded, return HTTP 429 and Retry-After: 60.

Rate limiting has an important implementation choice: where request counts are stored. An in-memory counter is simple, but its behavior depends on the runtime and deployment; it may not represent a shared count across separate instances. A distributed store or platform-level control can provide shared state, but adds configuration or operational complexity. Have the agent state what its implementation actually uses, what happens when state is unavailable, and whether the hosting model makes that choice suitable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How should API routes reject abusive or malformed submissions?

Middleware is not a reason to trust a request once it reaches an endpoint. Each relevant API route should validate its own input, in a deliberate order, and return a clear error for requests it cannot safely process.

  1. Check the content type. Require the expected type for the route before treating the body as JSON. The system maps an unexpected type to HTTP 415.
  2. Enforce a body-size limit. The prompt recommends an 8 KB cap, a threshold Said proposed in 2026. Reject oversized bodies with HTTP 413 before doing more expensive parsing or work.
  3. Recheck origin. Apply the route’s origin policy at the API boundary as well as at the interceptor, rather than assuming every request took the same path.
  4. Parse JSON inside error handling. Malformed JSON should produce HTTP 400, not an unhandled exception or an ambiguous server error.

These are request-shape checks, not business rules. A well-formed request can still ask the app to do something the user is not permitted to do, or trigger expensive behavior. The agent should preserve existing authorization and application-specific validation rather than imply that content type, size, and origin checks settle those questions.

What does the honeypot catch, and what can it miss?

A honeypot is an extra form field ordinary users are not meant to fill in. If it is populated, the app can silently accept and discard the submission instead of performing the normal action. This can catch unsophisticated bots that fill every field they encounter.

Said advises styling the field with zero opacity and pointer-events: none, because simple display: none or visibility: hidden treatment may be detectable by bots. The intended result is a field that is not visible or usable in an ordinary interaction but remains present in the form. After implementation, inspect the rendered form in browser developer tools and test that a normal submission is unaffected while a filled honeypot does not trigger the usual action.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

This is a low-friction signal, not a CAPTCHA or proof that a human submitted the form. A bot that recognizes the trap can avoid it, and an incorrectly configured field can create problems for legitimate users or assistive technology. Verify the actual rendered behavior instead of relying on the agent’s description of the markup.

Which deployment settings complete the system?

The fourth layer is a set of hosting and response-hardening tasks. These settings can reduce unwanted caching or browser-side exposure, but they do not by themselves determine whether an incoming request is automated.

  • API cache policy: use Cache-Control: no-store for API responses where storing responses is not appropriate, then verify the header on the deployed response.
  • Security headers: configure relevant headers, including HSTS, X-Content-Type-Options, X-Frame-Options, Content-Security-Policy, Referrer-Policy, and Permissions-Policy. Their values should fit the application; adding a header name without a workable policy is not sufficient.
  • Source maps: hide or disable public source maps where possible, and check whether deployed assets expose them. The verification playbook also names X-Robots-Tag: noindex as a signal to check for source maps; that header is not the same as preventing access to a publicly served file.
  • Function timeouts: use conservative timeouts suited to the app’s actual work, so a request cannot keep server functions running unnecessarily long. A timeout is a resource safeguard, not a substitute for limiting requests.
  • URL structure: keep routes and URLs clean, and make sure security rules cover the actual deployed paths rather than only the routes the agent inferred from the interface.

Have the agent identify where each setting is configured—application code, framework configuration, or hosting configuration—and test the deployed result. A source edit does not prove that the hosting platform applied the setting.

How do you test whether the defenses really work?

Test outcomes, not the agent’s summary. Said reports that his first production run implemented the easier deployment work but omitted middleware, honeypot fields, and API guards; in his tests, every bot User-Agent still received HTTP 200. After refining the prompt to name files and require explicit checks, he reports all 17 items on his verification checklist passed. Those are the author’s reported results for his apps, not independent measurements of effectiveness.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A useful verification run covers these eight families. Run them against a safe staging deployment or controlled test environment where possible, and inspect both the response and the app’s behavior.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray | Data transfer & Fast charging for MacBook, iPhone 17/16/15, iPad, Samsung Galaxy, Apple Watch
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
  1. Bot User-Agent handling: send a request carrying a User-Agent the rule is meant to block and confirm the configured blocked response, which may be 403 or 404. Test an ordinary browser request and Googlebot separately; the expected result for each allowed case is 200.
  2. Origin enforcement: make API requests with an allowed origin and with a missing or unexpected Origin/Referer, as applicable to the policy. Confirm the disallowed request is rejected and the allowed flow still works.
  3. Rate limiting: send requests from one test IP below and above the configured threshold. Confirm that the limit applies as intended and that an over-limit response is 429 with Retry-After: 60 for the stated 60-second configuration.
  4. Content type: submit a request to a JSON endpoint using an incorrect content type and check for 415.
  5. JSON parsing: submit malformed JSON with the expected content type and check for 400 rather than an unhandled server failure.
  6. Body-size handling: test bodies on either side of the configured cap and confirm an oversized body receives 413. The recommended cap in this system is 8 KB.
  7. Security headers and caching: inspect deployed responses for the headers the app is meant to send, especially Cache-Control: no-store on applicable API responses.
  8. Honeypot and source maps: inspect the form in browser developer tools, verify filled honeypot submissions are discarded, and check whether source maps are publicly reachable or configured for noindex.

Record the endpoint, request conditions, expected result, and observed result for each check. When a test fails, fix the corresponding layer and rerun it; a passing test for one route does not establish that all routes share the same middleware or policy.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What are the system’s limits, and when is another control needed?

Said describes the system as “deterrence, not a fortress.” The stated exclusions are sophisticated attackers using real browsers and human-like behavior, distributed attacks spread across many IPs, and zero-day or business-logic vulnerabilities. The four layers are most useful as a baseline against common, low-effort automated abuse; they should not be presented as a guarantee against those higher-capability threats.

The article names Cloudflare Turnstile and hCaptcha as possible escalations for human-verification challenges, Cloudflare Bot Management for more advanced bot controls, and AWS Shield for attack mitigation. Which control fits depends on the traffic and failure mode: an interaction challenge differs from platform-level bot management or infrastructure protection. The article does not establish current pricing, eligibility, geographic availability, or partner status for these services, so those details should be checked directly before selecting one.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The author also says the approach eliminates “90%+” of automated abuse for most independent developers and small teams. That is an author-reported outcome claim; no measurement method, sample, or independent result is supplied, so it should not be used as a promised reduction for another app.

What did the prompt-building attempt teach?

The central lesson is that coding agents tend to implement what they are explicitly asked to implement, not everything a developer mentally associates with “bot protection.” Said summarizes this as: “The AI agent will do exactly what you describe — nothing more, nothing less.”

Best Value
Sale
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

For a security-sensitive change, write the assignment as an implementation map and an acceptance test, not a broad aspiration. Name the request boundary, the API checks, the form behavior, the deployment settings, the expected status codes, and the routes to verify. Then inspect the diff for missing files, unexpected dependencies, and rules that are broader than intended. Finally, run the tests yourself: an agent’s explanation is evidence of what it thinks it changed, not evidence that deployed behavior matches the requirement.

Frequently Asked Questions

Can I use this prompt on a static website with no API routes?

The API-validation and server-function controls only apply if the site has endpoints or hosted functions to protect. Ask the agent to identify which layers are inapplicable rather than create middleware or form checks that the architecture cannot use.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does a robots.txt rule stop bots from submitting forms?

No. A crawler policy is not an access-control mechanism, and automated clients can ignore it. Protect submission endpoints at the request or application layer instead of treating a crawl directive as a block.

Should the rate limit be the same for every endpoint?

Not necessarily. A low-cost read route and an endpoint that triggers expensive work have different abuse consequences; ask the agent to identify route-specific costs and document any deviations from the example default.

What should I do if a legitimate user gets blocked?

Use logs and request context to identify which layer rejected the request, then adjust that rule narrowly and add a regression test for the legitimate flow. Avoid disabling every layer simply because one threshold or matching rule was too broad.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

AI coding agentsAPI securitybot protectionRate limitingweb application security

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.