Hướng dẫn giải pháp Solution guide Application Services Application Services ~10 phút ~10 min Đồng bộ 2026-06-10 Synced 2026-06-10

Bảo vệ your forms từ spam và abuse (Free, Pro, và Business) Protect your forms from spam and abuse (Free, Pro, and Business)

Hướng dẫn chi tiết đồng bộ từ docs Cloudflare — mỗi section có backlink tới đúng vị trí trên trang gốc. Detailed guide synced from Cloudflare docs — each section links to the matching anchor on the official page.

← Danh mục ← Catalog

Giải thích nhanh Quick context

Thuộc nhóm Application Services — tập trung bảo vệ, tăng tốc và vận hành ứng dụng/web phía trước origin. Tutorial «Bảo vệ your forms từ spam và abuse (Free, Pro, và Business)» giúp bạn làm quen luồng triển khai thật — phù hợp đọc trước khi mở tài liệu gốc tiếng Anh. Đọc phần tóm tắt và lưu ý trước — sau đó mở docs gốc để copy lệnh và cấu hình chi tiết.

Block spam submissions, fake account creation, and card testing on your web forms using a layered defense.

Lưu ý trước khi làm Notes before you start

  • Đây là bản tóm tắt trên Orange Cloud Learning Hub — không thay thế tài liệu chính thức. This is a summary on Orange Cloud Learning Hub — it does not replace the official documentation.
  • Luôn mở liên kết «Tài liệu gốc» bên dưới khi cần lệnh CLI, snippet code và ảnh minh họa đầy đủ. Open the Official docs link below for CLI commands, code snippets, and full screenshots.
  • Docs Cloudflare cập nhật thường xuyên — đối chiếu ngày «Rà soát lần cuối» trên trang gốc khi triển khai production. Cloudflare docs change frequently — verify the Last reviewed date on the official page before production use.

Tổng quan Overview

Phần «Tổng quan» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Overview" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Contact, registration, and checkout forms are common targets for automated abuse. This guide covers form protection: verifying that visitors are human, limiting repeated submissions, and blocking known attack patterns. The core workflow uses features available on all plans. Pro and Business plan features are included as callouts.

Most procedures in this guide are configured per domain or zone. Select your domain in the Cloudflare dashboard before starting. Turnstile is the exception: widgets are configured at the account level.

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Thêm Turnstile vào forms Add Turnstile to your forms

Phần «Thêm Turnstile vào forms» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Add Turnstile to your forms" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Turnstile verifies visitors are human without visible challenges. This guide uses Managed mode, which automatically chooses between a non-interactive or checkbox challenge based on visitor risk level. For other widget modes, refer to Widget types.

Adding Turnstile involves three steps: create a widget in the dashboard, add the client-side snippet to your form page, and validate the token on your server before processing the submission.

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Tạo Turnstile widget Create a Turnstile widget

Phần «Tạo Turnstile widget» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Create a Turnstile widget" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗
  1. In the Cloudflare dashboard, go to the Turnstile page.

Go to Turnstile

  1. Select Add widget.
  2. Fill out the required information:

Widget name: A descriptive name for your widget. Hostname management: Domains where the widget will be used. * Widget mode: Choose from Managed, Non-Interactive, or Invisible.

  1. (Optional) Configure Pre-clearance support for single-page applications.
  2. Select Create to save your widget.
  3. Copy your sitekey and secret key, and store the secret key securely.

Store the sitekey and secret key. You will use the sitekey in the client-side snippet and the secret key for server-side validation.

Thêm client-side snippet Add the client-side snippet

Phần «Thêm client-side snippet» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Add the client-side snippet" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Add the Turnstile script and widget div element to each form you want to protect. Replace <YOUR-SITE-KEY> with the sitekey from the previous step.

text
<form id="contact-form" action="/submit" method="POST">

  <input type="text" name="name" placeholder="Name" required />

  <input type="email" name="email" placeholder="Email" required />

  <textarea name="message" placeholder="Message" required></textarea>

  <div class="cf-turnstile" data-sitekey="<YOUR-SITE-KEY>"></div>

  <button type="submit">Submit</button>

</form>


<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>

The widget renders in the form and generates a token when the visitor passes verification. The token is included in the form submission as the cf-turnstile-response field.

Validate token on your server Validate the token on your server

Phần «Validate token on your server» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Validate the token on your server" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Server-side validation is required. The client-side widget alone does not protect your forms because attackers can submit directly to your form endpoint. Tokens can only be validated once.

Call the Siteverify API before processing any form submission:

server.js

text
const SECRET_KEY = "<YOUR-SECRET-KEY>";


async function validateTurnstile(token, remoteip) {

  try {

    const response = await fetch(

      "https://challenges.cloudflare.com/turnstile/v0/siteverify",

      {

        method: "POST",

        headers: { "Content-Type": "application/json" },

        body: JSON.stringify({

          secret: SECRET_KEY,

          response: token,

          remoteip: remoteip,

        }),

      },

    );


    const result = await response.json();

    return result;

  } catch (error) {

    console.error("Turnstile validation error:", error);

    return { success: false, "error-codes": ["internal-error"] };

  }

}

Replace "<YOUR-SECRET-KEY>" with your Turnstile secret key. The endpoint returns a JSON object with a success field. Only process the form submission if success is true.

For validation examples in PHP, Python, Java, and C#, refer to Validate the token.

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Rate limit form submission endpoints Rate limit form submission endpoints

Phần «Rate limit form submission endpoints» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Rate limit form submission endpoints" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Some abuse scripts skip the browser entirely and POST directly to your form endpoints. Application Security rate limiting rules catch these requests because client-side verification only runs in a browser.

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Find your baseline request rate Find your baseline request rate

Phần «Find your baseline request rate» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Find your baseline request rate" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Before creating a rate limiting rule, check the normal submission rate for your form endpoints. Your rate limit threshold should be above this baseline to avoid blocking legitimate traffic.

  1. In the Cloudflare dashboard, go to the Analytics page.

Go to Analytics

  1. In the Traffic tab, select a time period with non-peak traffic, or with the lowest visitor activity.
  2. Use the Add filter button to narrow results to your form endpoint traffic.
  3. Note the typical request rate per IP address. Your rate limit should be above this baseline.

If you do not have enough traffic data to establish a baseline, start with a conservative threshold and adjust based on Security Events after deployment.

Enterprise: Request rate analysis

The Request rate analysis tab in Security Analytics displays request rate distributions for your top unique clients. For details, refer to Find appropriate rate limit.

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Tạo rate limiting rule Create a rate limiting rule

Tạo rule that limits how many times a single IP address can submit to your form endpoint within a given period. Adjust the path, threshold, and period for your site.

Read the "Create a rate limiting rule" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Create a rule that limits how many times a single IP address can submit to your form endpoint within a given period. Adjust the path, threshold, and period for your site.

  1. In the Cloudflare dashboard, go to the Security rules page.

Go to Security rules

  1. Select Create rule and choose Rate limiting rules.
  2. Enter a name for the rule (for example, "Rate limit contact form submissions").
  3. Under When incoming requests match, select Edit expression and enter: (http.request.uri.path eq "/contact" and http.request.method eq "POST")

Replace "/contact" with your form endpoint path.

  1. Under With the same characteristics, verify that IP is selected. On Free plans, this is preset to IP.
  2. Under When rate exceeds, enter 5 for Requests and select a value for Period. On Free plans, select 10 seconds. Pro and above plans offer additional periods. For available values by plan, refer to Rate limiting parameters.
  3. Under Then take action, select an action from the Choose action dropdown. On Free plans, select Block. On Pro and above, Managed Challenge is recommended because it allows legitimate users who trigger the limit to pass by completing a challenge.
  4. Under For duration, select a duration for the action. On Free plans, select 10 seconds. Pro and above plans offer longer durations. This is how long the action applies after the rate limit is triggered.
  5. Select Deploy.

Rate limiting rule parameters (counting characteristics, periods, number of rules) vary by plan. For the full availability matrix, refer to Rate limiting rules.

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Cấu hình custom response for blocked requests (Pro và above) Configure a custom response for blocked requests (Pro and above)

Phần «Cấu hình custom response for blocked requests (Pro và above)» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Configure a custom response for blocked requests (Pro and above)" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Instead of showing the default Cloudflare error page when a rate limit is reached, you can configure a custom response. For details, refer to Create a rate limiting rule in the dashboard.

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Thêm ứng dụng Security rules for known abuse patterns Add Application Security rules for known abuse patterns

Phần «Thêm ứng dụng Security rules for known abuse patterns» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Add Application Security rules for known abuse patterns" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Rate limiting alone does not catch targeted attack patterns like SQL injection or cross-site scripting (XSS) in form fields. Application Security custom rules and managed rulesets let you block these specific patterns targeting your form endpoints. Custom rules run before rate limiting rules and managed rulesets in the execution order.

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Challenge non-bot requests to form endpoints Challenge non-bot requests to form endpoints

Tạo custom rule that challenges POST requests to your form endpoints from sources that are not verified bots.

Read the "Challenge non-bot requests to form endpoints" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Create a custom rule that challenges POST requests to your form endpoints from sources that are not verified bots.

  1. In the Cloudflare dashboard, go to the Security rules page.

Go to Security rules

  1. Select Create rule \> Custom rules.
  2. Enter a name for the rule (for example, "Challenge spam form submissions").
  3. Under When incoming requests match, select Edit expression and enter:
text
(http.request.uri.path eq "/contact" and http.request.method eq "POST" and not cf.client.bot)

Replace /contact with your form endpoint path. The not cf.client.bot clause exempts verified bots (such as search engine crawlers) from the rule.

  1. Under Then take action, select Managed Challenge.

Start with Managed Challenge to observe which requests are flagged before switching to Block.

  1. Select Deploy.

After deploying, review Security Events to check whether the rule is matching legitimate traffic. If legitimate users are being challenged, narrow the expression or switch to a less aggressive action.

Pro plans and above: Managed rulesets

The Cloudflare Managed Ruleset protects against common web attack patterns, including form-based injection attacks (SQL injection, XSS). Verify the ruleset is deployed on the Security rules page under Managed rules. For plan availability, refer to Managed Rules.

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Turn on bot protection Turn on bot protection

Phần «Turn on bot protection» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Turn on bot protection" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Bot Fight Mode challenges requests that match known bot patterns across your entire domain. It is available on all plans and requires no configuration beyond turning it on.

  1. In the Cloudflare dashboard, go to the Security Settings page.

Go to Settings

  1. Filter by Bot traffic.
  2. Go to Bot fight mode.
  3. Turn Bot fight mode on.
  1. Log in to the Cloudflare dashboard ↗, and select your account and domain.
  2. Go to Security \> Bots.
  3. For Bot Fight Mode, select On.

Bot Fight Mode protects your entire domain without endpoint restrictions. You cannot create exceptions using custom rules to bypass Bot Fight Mode.

Pro, Business, and Enterprise

Super Bot Fight Mode provides more granular controls. You can configure how your domain responds to different categories of bot traffic (definitely automated, likely automated, verified bots) and create exceptions using custom rules with the Skip action. Enterprise customers with Bot Management can use cf.bot_management.score in custom rule expressions for path-specific bot protection.

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Monitor your form endpoints Monitor your form endpoints

Phần «Monitor your form endpoints» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Monitor your form endpoints" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

After deploying Turnstile, rate limiting rules, and Application Security rules, monitor your form endpoints to verify your rules are working and to detect new attack patterns.

Review Security Events Review Security Events

Phần «Review Security Events» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Review Security Events" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Security Events shows requests that Cloudflare security products acted on or flagged, including blocks, challenges, and skips. Filter by your form endpoint paths to see what is being blocked and what is getting through. A high volume of blocked or challenged requests to your form paths confirms the rules are active.

  1. In the Cloudflare dashboard, go to the Analytics page.

Go to Analytics

  1. Select the Events tab.
  2. Use the Add filter button to narrow results to your form endpoint traffic.
  3. Review the sampled logs. For each event, check:

Action taken: Whether the request was blocked, challenged, or allowed Source: The rule or feature that triggered the action IP address: Whether a single IP is generating many events URI path: Whether requests target your form endpoints specifically

If legitimate users are being challenged, narrow the rule expression or switch to a less aggressive action.

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Thiết lập security event alerts Set up security event alerts

Cấu hình a notification to receive alerts when there is an unusual spike in security events on your domain.

Read the "Set up security event alerts" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Configure a notification to receive alerts when there is an unusual spike in security events on your domain.

For alert types, trigger thresholds, and setup instructions, refer to Alerts for security events.

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Turn on client-side resource monitoring Turn on client-side resource monitoring

Phần «Turn on client-side resource monitoring» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Turn on client-side resource monitoring" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

If a third-party script is injected into your form page, it can exfiltrate submitted data, including payment information. Client-Side Security monitors third-party scripts on your pages for changes and potential supply chain attacks.

To enable monitoring:

  1. In the Cloudflare dashboard, go to the Security Settings page.

Go to Settings

  1. (Optional) Filter by Client-side abuse.
  2. Turn on Continuous script monitoring.

After enabling, review detected scripts on the Web assets page under the Client-side resources tab to identify any unexpected scripts on your form pages. For the full setup workflow, refer to Get started with client-side security.

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Xem bản đầy đủ trên developers.cloudflare.com (ảnh, tab cấu hình). View the full guide on developers.cloudflare.com (images, config tabs).

Tài liệu gốc ↗ Official docs ↗