Page Shield API
You can enable and disable Page Shield, configure its settings, and fetch information about detected scripts and connections using the Page Shield API.
To authenticate API requests you need an API token. For more information on the required API token permissions, refer to Roles and permissions.
You can obtain the complete endpoint by appending the Page Shield API endpoints to the Cloudflare API base URL:
The {zone_id}
argument is the zone ID (a hexadecimal string). You can find this value in the Cloudflare dashboard or using the Cloudflare API’s /zones
endpoint.
The {script_id}
argument is the script ID (a hexadecimal string). This value is included in the response of the List Page Shield scripts operation for every detected script.
The {connection_id}
argument is the connection ID (a hexadecimal string). This value is included in the response of the List Page Shield connections API operation for every detected connection.
The following table summarizes the available operations:
Operation | Method + URL stub | Notes |
---|---|---|
Get Page Shield settings | GET zones/{zone_id}/page_shield | Fetch Page Shield settings (including the status). |
Update Page Shield settings | PUT zones/{zone_id}/page_shield | Update Page Shield settings. |
List Page Shield scripts | GET zones/{zone_id}/page_shield/scripts | Fetch a list of detected scripts. |
Get a Page Shield script | GET zones/{zone_id}/page_shield/scripts/{script_id} | Fetch the details of a script. |
List Page Shield connections | GET zones/{zone_id}/page_shield/connections | Fetch a list of detected connections. |
Get a Page Shield connection | GET zones/{zone_id}/page_shield/connections/{connection_id} | Fetch the details of a connection. |
List Page Shield cookies | GET zones/{zone_id}/page_shield/cookies | Fetch a list of detected cookies. |
Get a Page Shield cookie | GET zones/{zone_id}/page_shield/cookies/{cookie_id} | Fetch the details of a cookie. |
List Page Shield policies | GET zones/{zone_id}/page_shield/policies | Fetch a list of all configured CSP policies. |
Get a Page Shield policy | GET zones/{zone_id}/page_shield/policies/{policy_id} | Fetch the details of a CSP policy. |
Create a Page Shield policy | POST zones/{zone_id}/page_shield/policies | Creates a CSP policy with the provided configuration. |
Update a Page Shield policy | PUT zones/{zone_id}/page_shield/policies/{policy_id} | Updates an existing CSP policy. |
Delete a Page Shield policy | DELETE zones/{zone_id}/page_shield/policies/{policy_id} | Deletes an existing CSP policy. |
-
The malicious script classification (
Malicious
orNot malicious
) is not directly available in the API. To determine this classification, compare the script’sjs_integrity_score
value with the classification threshold, which is currently set to 50. Scripts with a score value lower than the threshold are considered malicious. -
The API provides two separate properties for malicious script/connection categories:
malicious_domain_categories
andmalicious_url_categories
, related to thedomain_reported_malicious
andurl_reported_malicious
properties, respectively. The Cloudflare dashboard displays all the categories in a single Malicious category field. For more information, refer to Malicious script and connection categories.
This example obtains the current settings of Page Shield, including the status (enabled/disabled).
This example enables Page Shield in the specified zone.
This GET
request fetches a list of scripts detected by Page Shield on hostname example.net
, requesting the first page with 15 items per page. The URL query string includes filtering and paging parameters.
By default, the response will only include scripts with active
status when you do not specify a status
filter parameter in the URL query string.
Some fields displayed in the example response may not be available, depending on your Cloudflare plan.
For details on the available filtering, paging, and sorting parameters, refer to the API reference.
This GET
request fetches a list of infrequently reported scripts on hostname example.net
, requesting the first page with 15 items per page. The URL query string includes filtering and paging parameters.
Some fields displayed in the example response may not be available, depending on your Cloudflare plan.
For details on the available filtering, paging, and sorting parameters, refer to the API reference.
This GET
request obtains the details of a script detected by Page Shield with script ID 8337233faec2357ff84465a919534e4d
.
Some fields displayed in the example response may not be available, depending on your Cloudflare plan.
This GET
request fetches a list of connections detected by Page Shield, 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.
For details on the available filtering, paging, and sorting parameters, refer to the API reference.
This GET
request obtains the details of a connection detected by Page Shield with connection ID 0a7bb628776f4e50a50d8594c4a01740
.
This GET
request fetches a list of cookies detected by Page Shield, 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.
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 Page Shield with ID beee03ada7e047e79f076785d8cd8b8e
.
This POST
request creates a Page Shield 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 inexample.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 policy violation, but those scripts would not be blocked.
For more information on Content Security Policy (CSP) directives and values, refer to the MDN documentation ↗.
To create a policy with an Allow action instead of Log, use "action": "allow"
in the request body. In the case of such policy, all scripts not allowed by the policy would be blocked.