TechBuzzPro

Cloudflare Zone Security 12 Read-Only Checks with Curl

· 5 min read · Apps & Browsers

In this article
  1. Prerequisites: What You Need Before Running the Checks
  2. The 12 Read-Only Checks and Their Curl Commands
  3. How to Interpret the JSON Responses
  4. Why Run These Checks? Security Auditing and Automation
  5. Common Pitfalls and How to Avoid Them
  6. Costs and Rate Limits
  7. Frequently Asked Questions

You can run 12 read-only Cloudflare zone security checks with curl by querying the Cloudflare API v4 using a read-only API token and the GET method. These checks verify your zone's security settings, DNS records, SSL/TLS configuration, and active threats without making any changes. Below are the specific endpoints and commands you can use, along with context on how they work and what to look for.

Prerequisites: What You Need Before Running the Checks

To run these checks, you need a Cloudflare account with a zone (domain) added. You also need an API token with read-only permissions. Create one in the Cloudflare dashboard under My Profile > API Tokens > Create Token. Use the template "Read all resources" or manually select the permissions: Zone > Read for all the relevant categories. The token must be passed in the Authorization header as Bearer <TOKEN>.

You also need your Zone ID, which is found on the zone's overview page in the dashboard. Replace ZONE_ID in the examples with your actual ID. All commands use the Cloudflare API base URL https://api.cloudflare.com/client/v4.

The 12 Read-Only Checks and Their Curl Commands

Each check is a separate API call. The following list shows the endpoint, what it returns, and the curl command. All commands are read-only (GET requests) and do not modify any settings.

  • 1. Security Level – Returns the security level setting (e.g., medium, high).
    curl -X GET "https://api.cloudflare.com/client/v4/zones/ZONE_ID/settings/security_level" -H "Authorization: Bearer TOKEN"
  • 2. SSL/TLS Mode – Shows the SSL mode (off, flexible, full, strict).
    curl -X GET "https://api.cloudflare.com/client/v4/zones/ZONE_ID/settings/ssl" -H "Authorization: Bearer TOKEN"
  • 3. Browser Integrity Check – Indicates if the browser integrity check is on or off.
    curl -X GET "https://api.cloudflare.com/client/v4/zones/ZONE_ID/settings/browser_check" -H "Authorization: Bearer TOKEN"
  • 4. Under Attack Mode – Shows if the zone is currently under attack mode (always on/off).
    curl -X GET "https://api.cloudflare.com/client/v4/zones/ZONE_ID/settings/security_level" -H "Authorization: Bearer TOKEN" (Note: this is not a separate endpoint; the security level setting includes the "I'm Under Attack" mode as a value.)
  • 5. WAF (Web Application Firewall) Status – Returns the WAF status (enabled/disabled) and its rulesets.
    curl -X GET "https://api.cloudflare.com/client/v4/zones/ZONE_ID/firewall/waf/packages" -H "Authorization: Bearer TOKEN"
  • 6. Firewall Rules – Lists all active firewall rules for the zone.
    curl -X GET "https://api.cloudflare.com/client/v4/zones/ZONE_ID/firewall/rules" -H "Authorization: Bearer TOKEN"
  • 7. Page Rules (Security-Related) – Shows all page rules, including those that affect security settings.
    curl -X GET "https://api.cloudflare.com/client/v4/zones/ZONE_ID/pagerules" -H "Authorization: Bearer TOKEN"
  • 8. Rate Limiting Rules – Lists all rate limiting rules configured for the zone.
    curl -X GET "https://api.cloudflare.com/client/v4/zones/ZONE_ID/rate_limits" -H "Authorization: Bearer TOKEN"
  • 9. IP Access Rules – Shows IP access rules (allow/block/challenge) for the zone.
    curl -X GET "https://api.cloudflare.com/client/v4/zones/ZONE_ID/firewall/access_rules/rules" -H "Authorization: Bearer TOKEN"
  • 10. DNS Records (Security-Relevant) – Lists all DNS records, including those that could affect security (e.g., MX, TXT for SPF).
    curl -X GET "https://api.cloudflare.com/client/v4/zones/ZONE_ID/dns_records" -H "Authorization: Bearer TOKEN"
  • 11. Zone Settings (Security Headers) – Returns all zone settings, including security headers like HSTS and Always Use HTTPS.
    curl -X GET "https://api.cloudflare.com/client/v4/zones/ZONE_ID/settings" -H "Authorization: Bearer TOKEN"
  • 12. Active Threats (Analytics) – Shows recent security events and threats (requires analytics permission).
    curl -X GET "https://api.cloudflare.com/client/v4/zones/ZONE_ID/security/events" -H "Authorization: Bearer TOKEN"

Note: The "Under Attack Mode" is not a separate endpoint; it's a value of the security level setting. The above list includes 12 distinct checks, but you can combine some endpoints to get more data.

How to Interpret the JSON Responses

The API returns JSON with a success field (true/false) and a result object. For example, the SSL check returns:

{"result":{"id":"ssl","value":"full","modified_on":"..."},"success":true}

The value field tells you the current setting. For the WAF packages, the response includes a list of packages with detection_mode and status (e.g., "enabled"). For DNS records, look for type and content fields to spot misconfigurations like missing SPF records.

Why Run These Checks? Security Auditing and Automation

These read-only checks are useful for security audits, compliance reviews, and automated monitoring. You can script them to periodically verify that your security settings haven't changed unintentionally. For example, you might want to ensure SSL mode is always "full" or "strict" and that WAF is enabled. Running these via curl allows you to integrate them into CI/CD pipelines or monitoring tools like Nagios or Zabbix.

They also help you identify potential misconfigurations: a DNS record pointing to an old IP, a firewall rule that's too permissive, or rate limiting rules that are too lenient. By checking these regularly, you can catch issues before they become security incidents.

Common Pitfalls and How to Avoid Them

  • Using the wrong token permissions – If you get a 403 error, your token lacks read access. Ensure the token has at least Zone:Read for the specific resource.
  • Forgetting the Zone ID – The Zone ID is not the domain name; it's a 32-character hex string. Find it on the zone overview page.
  • Rate limiting on the API – Cloudflare API has rate limits (1200 requests per 5 minutes). If you run many checks, space them out.
  • Parsing JSON without jq – Use jq to extract fields easily: curl ... | jq '.result.value'.
  • Assuming "read-only" means no analytics – The security events endpoint requires the Analytics:Read permission; without it, you'll get an error.

Costs and Rate Limits

Using the Cloudflare API is free, but there are rate limits. For free plans, the limit is 1200 requests per 5 minutes per user. If you exceed this, you'll get a 429 error. For enterprise plans, limits are higher. To avoid hitting limits, schedule your checks to run at intervals, and consider using the per_page parameter to limit the number of results returned.

Frequently Asked Questions

Can I run these checks without an API token?

No, all Cloudflare API endpoints require authentication. You can use a Global API key, but it's safer to create a read-only token. The token must be passed in the Authorization header.

What does the "Under Attack Mode" check actually show?

The security level setting can be set to "I'm Under Attack!" which is a high-security mode that challenges all visitors. The API returns this as the value of the security level setting. So the check is the same as the security level check.

Why do I get a 403 error when running the WAF check?

Your token likely lacks the Firewall:Read permission. Go to your token settings and add the permission. Also ensure you're using the correct Zone ID.

Can I use these checks to modify security settings?

No, these are GET requests only. To modify settings, you would use POST or PUT requests, but that's beyond the scope of read-only checks. Always test changes in a staging environment first.

How do I check if my SSL is set to "strict"?

Run the SSL check and look at the value field. If it says "strict", then it's set correctly. If it says "full" or "flexible", you may want to change it to "strict" for better security.