Skip to content
Gaurav TiwariDocs

Security and Spam Protection

Version 5.2.5 Updated November 22, 2026

A headless form is public, like any form on a website. Protect it with a captcha, a private key and a few checks on your server route.

The key alone isn’t spam protection. Core Forms still runs its spam checks on each headless submission.

What the API Key Allows

The key is for submitting to forms you’ve marked as headless. It doesn’t sign in to WordPress, but treat it as a secret.

A leaked key can be abused. If that happens:

  1. Generate and save a new key in Core Forms > Settings > Headless / REST.
  2. Update every server and site that uses it.
  3. Move browser-based forms behind a proxy.
  4. Check the Spam view in Submissions.

Use placeholders when you share code or recordings. The Headless tab and Settings mask the key on screen until you show it, but the Copy buttons copy the real key.

Keep the Key Private

Post to a route on your own site and add X-Core-Forms-Key there. The Astro, Next.js, Cloudflare, Node.js and PHP starters include these checks:

  • Origin allowlist: rejects posts from other sites.
  • Body limit: 16 KB is enough for most contact forms. Core Forms itself allows 60 KiB of field data, so raise the limit for longer forms.
  • User-agent check: drops the simplest scripts. It’s easy to fake.
  • Plain values: accepts text, numbers and lists, and rejects nested objects.
  • Fixed form: sets id on the server, replacing any value from the browser. Keep this line if you write your own route.

Don’t add a second honeypot at the proxy. Names like url, company and phone attract browser autofill, and Core Forms already has a honeypot.

If the key must be in the browser, keep a captcha on, watch for spam and rotate the key when you see abuse.

CORS

A filled Allowed origins list is enforced on the form routes: browsers on other sites can’t read the schema or responses, and JSONP is off.

CORS is a browser rule. A script or server can still call the endpoints, so the list doesn’t replace the key or a captcha.

A proxy doesn’t need CORS because it calls WordPress from a server. A browser that fetches the schema or uses the embed does. The Storefront API isn’t governed by this list.

Configure the Captcha

For Turnstile:

  1. Turn on Cloudflare Turnstile in Core Forms > Modules.
  2. Save both keys in Core Forms > Settings.
  3. Edit the form, open Settings > Anti-spam and tick Enable Turnstile.
  4. Add your front end’s hostname to the widget in Cloudflare.

For reCAPTCHA v3:

  1. Turn on Google reCAPTCHA in Core Forms > Modules.
  2. Save both v3 keys. The check then applies to every form.
  3. Add your front end’s domain to the key in Google’s console.

Load the Captcha on Your Site

The drop-in embed loads both providers by itself. With your own markup or a proxy starter, save this as core-forms-captcha.js:

// Adds Turnstile or reCAPTCHA v3 tokens to headless Core Forms.
(function () {
  var recaptchaKey = document.currentScript && document.currentScript.dataset.recaptchaKey;
  var loading = {};

  function load(src) {
    if (!loading[src]) {
      loading[src] = new Promise(function (resolve, reject) {
        var script = document.createElement('script');
        script.src = src;
        script.onload = resolve;
        script.onerror = reject;
        document.head.appendChild(script);
      });
    }
    return loading[src];
  }

  function renderTurnstile(root) {
    root.querySelectorAll('.cf-turnstile-container:not([data-ready])').forEach(function (box) {
      box.dataset.ready = '1';
      load('https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit')
        .then(function () {
          if (!box.isConnected) return;
          box.dataset.widget = window.turnstile.render(box, { sitekey: box.dataset.sitekey });
        })
        .catch(function () {
          box.textContent = 'The spam check could not load. Please reload the page.';
        });
    });
  }

  document.addEventListener('cf:mounted', function (event) {
    renderTurnstile(event.target);
  });

  // Tokens work once, so get a fresh one after a failed submission.
  document.addEventListener('cf:error', function (event) {
    event.target.querySelectorAll('.cf-turnstile-container[data-widget]').forEach(function (box) {
      window.turnstile.reset(box.dataset.widget);
    });
  });

  if (recaptchaKey) {
    var api = 'https://www.google.com/recaptcha/api.js?render=' + encodeURIComponent(recaptchaKey);

    document.addEventListener('submit', async function (event) {
      var form = event.target;
      if (!form.matches('form.cf-form')) return;
      if (form.dataset.tokenReady) {
        delete form.dataset.tokenReady;
        return;
      }

      // Hold the submission until the token arrives.
      event.preventDefault();
      event.stopImmediatePropagation();
      if (form.dataset.tokenPending) return;
      form.dataset.tokenPending = '1';

      var token = '';
      try {
        await load(api);
        await new Promise(function (resolve) { window.grecaptcha.ready(resolve); });
        token = await window.grecaptcha.execute(recaptchaKey, { action: 'submit' });
      } catch (error) {
        // An empty token lets Core Forms return its own error message.
      }

      var input = form.querySelector('input[name="g-recaptcha-response"]');
      if (!input) {
        input = document.createElement('input');
        input.type = 'hidden';
        input.name = 'g-recaptcha-response';
        form.appendChild(input);
      }
      input.value = token;
      delete form.dataset.tokenPending;
      form.dataset.tokenReady = '1';
      form.requestSubmit();
    }, true);
  }

  renderTurnstile(document);
})();

Load it before core-forms-client.js. For Turnstile, the site key comes from the form’s HTML:

<script src="/core-forms-captcha.js" defer></script>

For reCAPTCHA v3, add your public site key:

<script src="/core-forms-captcha.js" data-recaptcha-key="YOUR_RECAPTCHA_SITE_KEY" defer></script>
Provider Field to send Token lifetime
Turnstile cf-turnstile-response 5 minutes
reCAPTCHA v3 g-recaptcha-response 2 minutes

Tokens work once. The script gets a fresh one for another attempt.

To test Turnstile on staging, use Cloudflare’s site key 1x00000000000000000000AA with the secret 1x0000000000000000000000000000000AA. Never use that pair on a live site.

Pass the Visitor IP

Core Forms records the IP address that connects to WordPress, which is your server for a proxied form. It ignores X-Forwarded-For. A proxy secret lets your server name the visitor instead.

  1. Click Generate next to Proxy secret under Core Forms > Settings > Headless / REST and save. You can also define CORE_FORMS_HEADLESS_PROXY_SECRET in wp-config.php.
  2. Store the secret on your server as CORE_FORMS_PROXY_SECRET.
  3. Add both headers to the request your proxy sends to WordPress.

On Cloudflare, the two lines are:

'X-Core-Forms-Proxy-Secret': env.CORE_FORMS_PROXY_SECRET,
'X-Core-Forms-Client-IP': request.headers.get('cf-connecting-ip') ?? '',
  • Take the IP from a source visitors can’t set: cf-connecting-ip on Cloudflare, the socket address or a header your own host overwrites.
  • The secret needs at least 32 characters and must differ from the API key.
  • A wrong secret returns 401. A missing or invalid IP returns 400.

Rules for Proxied Forms

Feature Without the proxy secret With the proxy secret
Rate limit All visitors share one IP. Set it to 0 and limit the proxy Counts each visitor
Prevent duplicates Identical answers from any visitor count as a repeat. Turn it off Checks each visitor
[CF_IP_ADDRESS] The server’s IP The visitor’s IP
Turnstile, reCAPTCHA and Akismet Receive the server’s IP Receive the visitor’s IP

The starters forward the visitor’s user agent either way.

Other Spam Checks

  • The honeypot is added for you. A filled one gets a success response, but nothing is saved or sent.
  • The global blocklist runs as usual. Mark as spam returns success and Reject returns an error.
  • Akismet runs when its module is on.
  • Math CAPTCHA puts a generated question in the HTML. Turnstile or reCAPTCHA suits cached and static pages better.

See Spam Protection for the settings.

Share

Was this helpful?

Still stuck? Open a support ticket