Client-side security API·续

Some fields displayed in the example response may not be available, depending on your Cloudflare plan.

Fetch list of detected connections

This GET request fetches a list of connections detected by Cloudflare's client-side security, requesting the first page with 15 items per page.

By default, the response will only include connections with active status when you do not specify a status filter parameter in the URL query string.

<details>

<summary>

Required API token permissions

</summary>

At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:

  • <code>Page Shield</code>
  • <code>Domain Page Shield Read</code>
  • <code>Domain Page Shield</code>
  • <code>Page Shield Read</code>
  • <code>Zone Settings Write</code>
  • <code>Zone Settings Read</code>

</details>

List detected connectionsbash

curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/page_shield/connections?page=1&per_page=15" \
    --request GET \
    --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
{
    "result": [
        {
            "id": "0a7bb628776f4e50a50d8594c4a01740",
            "url": "https://malicious.example.com",
            "added_at": "2022-09-18T10:51:10.09615Z",
            "first_seen_at": "2022-09-18T10:51:08Z",
            "last_seen_at": "2022-09-02T09:57:54Z",
            "host": "example.net",
            "domain_reported_malicious": true,
            "malicious_domain_categories": ["Malware", "Spyware"],
            "url_reported_malicious": false,
            "malicious_url_categories": [],
            "first_page_url": "https://example.net/one.html",
            "status": "active",
            "url_contains_cdn_cgi_path": false
        }
        // (...)
    ],
    "success": true,
    "errors": [],
    "messages": [],
    "result_info": {
        "page": 1,
        "per_page": 15,
        "count": 15,
        "total_count": 16,
        "total_pages": 2
    }
}

For details on the available filtering, paging, and sorting parameters, refer to the API reference.

Get details of a detected connection

This GET request obtains the details of a connection detected by Cloudflare's client-side security with connection ID 0a7bb628776f4e50a50d8594c4a01740.

<details>

<summary>

Required API token permissions

</summary>

At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:

  • <code>Page Shield</code>
  • <code>Domain Page Shield Read</code>
  • <code>Domain Page Shield</code>
  • <code>Page Shield Read</code>
  • <code>Zone Settings Write</code>
  • <code>Zone Settings Read</code>

</details>

Get a detected connectionbash

curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/page_shield/connections/0a7bb628776f4e50a50d8594c4a01740" \
    --request GET \
    --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
{
    "result": {
        "id": "0a7bb628776f4e50a50d8594c4a01740",
        "url": "https://malicious.example.com",
        "added_at": "2022-09-18T10:51:10.09615Z",
        "first_seen_at": "2022-09-18T10:51:08Z",
        "last_seen_at": "2022-09-02T09:57:54Z",
        "host": "example.net",
        "domain_reported_malicious": true,
        "malicious_domain_categories": ["Malware", "Spyware"],
        "url_reported_malicious": false,
        "malicious_url_categories": [],
        "first_page_url": "https://example.net/one.html",
        "status": "active",
        "url_contains_cdn_cgi_path": false
    },
    "success": true,
    "errors": [],
    "messages": []
}

Fetch list of detected cookies

This GET request fetches a list of cookies detected by Cloudflare's client-side security, requesting the first page with 15 items per page.

By default, the response will only include cookies with active status when you do not specify a status filter parameter in the URL query string.

<details>

<summary>

Required API token permissions

</summary>

At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:

  • <code>Page Shield</code>
  • <code>Domain Page Shield Read</code>
  • <code>Domain Page Shield</code>
  • <code>Page Shield Read</code>
  • <code>Zone Settings Write</code>
  • <code>Zone Settings Read</code>

</details>

List detected cookiesbash

curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/page_shield/cookies?page=1&per_page=15" \
    --request GET \
    --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
{
    "result": [
        {
            "id": "beee03ada7e047e79f076785d8cd8b8e",
            "type": "first_party",
            "name": "PHPSESSID",
            "host": "example.net",
            "domain_attribute": "example.net",
            "expires_attribute": "2024-10-21T12:28:20Z",
            "http_only_attribute": true,
            "max_age_attribute": null,
            "path_attribute": "/store",
            "same_site_attribute": "strict",
            "secure_attribute": true,
            "first_seen_at": "2024-05-06T10:51:08Z",
            "last_seen_at": "2024-05-07T11:56:01Z",
            "first_page_url": "example.net/store/products",
            "page_urls": ["example.net/store/products/1"]
        }
        // (...)
    ],
    "success": true,
    "errors": [],
    "messages": [],
    "result_info": {
        "page": 1,
        "per_page": 15,
        "count": 15,
        "total_count": 16,
        "total_pages": 2
    }
}

For details on the available filtering, paging, and sorting parameters, refer to Make API calls.

This GET request obtains the details of a cookie detected by Cloudflare's client-side security with ID beee03ada7e047e79f076785d8cd8b8e.

<details>

<summary>

Required API token permissions

</summary>

At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:

  • <code>Page Shield</code>
  • <code>Domain Page Shield Read</code>
  • <code>Domain Page Shield</code>
  • <code>Page Shield Read</code>
  • <code>Zone Settings Write</code>
  • <code>Zone Settings Read</code>

</details>

Get a detected cookiebash

curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/page_shield/cookies/beee03ada7e047e79f076785d8cd8b8e" \
    --request GET \
    --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
{
    "result": {
        "id": "beee03ada7e047e79f076785d8cd8b8e",
        "type": "first_party",
        "name": "PHPSESSID",
        "host": "example.net",
        "domain_attribute": "example.net",
        "expires_attribute": "2024-10-21T12:28:20Z",
        "http_only_attribute": true,
        "max_age_attribute": null,
        "path_attribute": "/store",
        "same_site_attribute": "strict",
        "secure_attribute": true,
        "first_seen_at": "2024-05-06T10:51:08Z",
        "last_seen_at": "2024-05-07T11:56:01Z",
        "first_page_url": "example.net/store/products",
        "page_urls": ["example.net/store/products/1"]
    },
    "success": true,
    "errors": [],
    "messages": []
}

Create a content security rule

This POST request creates a content security rule (previously called a policy) with Log action, defining the following scripts as allowed based on where they are hosted:

  • Scripts hosted in myapp.example.com (which does not include scripts in example.com).
  • Scripts hosted in cdnjs.cloudflare.com.
  • The Google Analytics script using its full URL.
  • All scripts in the same origin (same HTTP or HTTPS scheme and hostname).

All other scripts would trigger a rule violation, but those scripts would not be blocked.

For more information on Content Security Policy (CSP) directives and values, refer to the MDN documentation ↗︎.

Note

For a list of CSP directives and keywords supported by content security rules, refer to Supported CSP directives.

<details>

<summary>

Required API token permissions

</summary>

At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:

  • <code>Page Shield</code>
  • <code>Domain Page Shield</code>
  • <code>Zone Settings Write</code>

</details>

Create a content security rulebash

curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/page_shield/policies" \
    --request POST \
    --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
    --json '{
        "description": "My first content security rule in log mode",
        "action": "log",
        "expression": "http.host eq \"myapp.example.com\"",
        "enabled": "true",
        "value": "script-src myapp.example.com cdnjs.cloudflare.com https://www.google-analytics.com/analytics.js '\''self'\''"
    }'
{
    "success": true,
    "errors": [],
    "messages": [],
    "result": {
        "id": "<RULE_ID>",
        "description": "My first content security rule in log mode",
        "action": "log",
        "expression": "http.host eq \"myapp.example.com\"",
        "enabled": "true",
        "value": "script-src myapp.example.com cdnjs.cloudflare.com https://www.google-analytics.com/analytics.js 'self'"
    }
}

To create a content security rule with an Allow action instead of Log, use "action": "allow" in the request body. In the case of such rule, all scripts not allowed by the rule would be blocked.

Was this helpful?

YesNo

On this page

Client-side security API·续 - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/client-side-security/reference/api/#page","headline":"Client-side security API","description":"Manage resource monitoring, settings, and detected scripts using the client-side security API.","url":"https://developers.cloudflare.com/client-side-security/reference/api/","inLanguage":"en","image":"https://developers.cloudflare.com/client-side-security/reference/api/og.png?v=0d8f5a6d8e4febfb","dateModified":"2026-04-15","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}


description: Format of the Content Security Policy report-only HTTP header added by Cloudflare. title: CSP HTTP header format image: https://developers.cloudflare.com/client-side-security/reference/csp-header/og.png?v=c0d758266d3f0b0d


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/client-side-security/llms.txt
Use this file to discover all available pages before exploring further.