Skip to content

Commit a5590f3

Browse files
authored
[Page Shield] Use APIRequest component (#21921)
1 parent 10ab055 commit a5590f3

File tree

2 files changed

+115
-89
lines changed

2 files changed

+115
-89
lines changed

src/content/docs/page-shield/policies/violations.mdx

+40-36
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,30 @@ sidebar:
55
order: 4
66
head: []
77
description: Page Shield reports any violations to your custom Page Shield policies.
8-
98
---
109

11-
import { Details, GlossaryTooltip } from "~/components"
10+
import { Details, GlossaryTooltip } from "~/components";
1211

1312
:::note
14-
1513
Only available to Enterprise customers with a paid add-on.
1614
:::
1715

18-
Shortly after you configure Page Shield policies, the Cloudflare dashboard will start displaying any violations of those policies. This information will be available for policies with any [action](/page-shield/policies/#policy-actions) (*Allow* and *Log*).
16+
Shortly after you configure Page Shield policies, the Cloudflare dashboard will start displaying any violations of those policies. This information will be available for policies with any [action](/page-shield/policies/#policy-actions) (_Allow_ and _Log_).
1917

2018
Information about policy violations is also available via [GraphQL API](/analytics/graphql-api/) and [Logpush](/logs/about/).
2119

2220
## Review policy violations in the dashboard
2321

2422
The policy violation information is available in **Security** > **Page Shield** > **Policies**. It includes the following:
2523

26-
* A sparkline next to the policy name, showing policy violations in the past seven days.
27-
* For policies with associated violations, an expandable details section for each policy, with the top resources present in policy violation events and a sparkline per top resource.
24+
- A sparkline next to the policy name, showing policy violations in the past seven days.
25+
- For policies with associated violations, an expandable details section for each policy, with the top resources present in policy violation events and a sparkline per top resource.
2826

2927
## Get policy violations via GraphQL API
3028

3129
Use the [Cloudflare GraphQL API](/analytics/graphql-api/) to obtain policy violation information through the following dataset:
3230

33-
* `pageShieldReportsAdaptiveGroups`
31+
- `pageShieldReportsAdaptiveGroups`
3432

3533
You can query the dataset for policy violations occurred in the past 30 days.
3634

@@ -41,36 +39,43 @@ For an introduction to GraphQL querying, refer to [Querying basics](/analytics/g
4139
### Example
4240

4341
```graphql title="Example GraphQL query"
44-
query PageShieldReports($zoneTag: string, $datetimeStart: string, $datetimeEnd: string) {
45-
viewer {
46-
zones(filter: {zoneTag: $zoneTag}) {
47-
pageShieldReportsAdaptiveGroups(limit: 100, orderBy: [datetime_ASC], filter: {datetime_geq:$datetimeStart, datetime_leq:$datetimeEnd}) {
48-
avg {
49-
sampleInterval
50-
}
51-
count
52-
dimensions {
53-
policyID
54-
datetime
55-
datetimeMinute
56-
datetimeFiveMinutes
57-
datetimeFifteenMinutes
58-
datetimeHalfOfHour
59-
datetimeHour
60-
url
61-
urlHost
62-
host
63-
resourceType
64-
pageURL
65-
action
66-
}
67-
}
68-
}
69-
}
42+
query PageShieldReports(
43+
$zoneTag: string
44+
$datetimeStart: string
45+
$datetimeEnd: string
46+
) {
47+
viewer {
48+
zones(filter: { zoneTag: $zoneTag }) {
49+
pageShieldReportsAdaptiveGroups(
50+
limit: 100
51+
orderBy: [datetime_ASC]
52+
filter: { datetime_geq: $datetimeStart, datetime_leq: $datetimeEnd }
53+
) {
54+
avg {
55+
sampleInterval
56+
}
57+
count
58+
dimensions {
59+
policyID
60+
datetime
61+
datetimeMinute
62+
datetimeFiveMinutes
63+
datetimeFifteenMinutes
64+
datetimeHalfOfHour
65+
datetimeHour
66+
url
67+
urlHost
68+
host
69+
resourceType
70+
pageURL
71+
action
72+
}
73+
}
74+
}
75+
}
7076
}
7177
```
7278

73-
7479
<Details header="Example curl request">
7580

7681
```bash
@@ -109,12 +114,11 @@ echo '{ "query":
109114
}
110115
}' | tr -d '\n' | curl --silent \
111116
https://api.cloudflare.com/client/v4/graphql \
112-
--header "Authorization: Bearer <API_TOKEN>" \
117+
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
113118
--header "Content-Type: application/json" \
114119
--data @-
115120
```
116121

117-
118122
</Details>
119123

120124
## Get policy violations via Logpush

src/content/docs/page-shield/reference/page-shield-api.mdx

+75-53
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sidebar:
55
order: 12
66
---
77

8-
import { GlossaryTooltip } from "~/components";
8+
import { GlossaryTooltip, APIRequest } from "~/components";
99

1010
You can enable and disable Page Shield, configure its settings, and fetch information about detected scripts and connections using the [Page Shield API](/api/resources/page_shield/methods/get/).
1111

@@ -71,10 +71,7 @@ The malicious script classification (`Malicious` or `Not malicious`) is not dire
7171

7272
This example obtains the current settings of Page Shield, including the status (enabled/disabled).
7373

74-
```bash
75-
curl "https://api.cloudflare.com/client/v4/zones/{zone_id}/page_shield" \
76-
--header "Authorization: Bearer <API_TOKEN>"
77-
```
74+
<APIRequest path="/zones/{zone_id}/page_shield" method="GET" />
7875

7976
```json output
8077
{
@@ -94,13 +91,11 @@ curl "https://api.cloudflare.com/client/v4/zones/{zone_id}/page_shield" \
9491

9592
This example enables Page Shield in the specified zone.
9693

97-
```bash
98-
curl --request PUT \
99-
"https://api.cloudflare.com/client/v4/zones/{zone_id}/page_shield" \
100-
--header "Authorization: Bearer <API_TOKEN>" \
101-
--header "Content-Type: application/json" \
102-
--data '{ "enabled": true }'
103-
```
94+
<APIRequest
95+
path="/zones/{zone_id}/page_shield"
96+
method="PUT"
97+
json={{ enabled: true }}
98+
/>
10499

105100
```json output
106101
{
@@ -120,10 +115,15 @@ This `GET` request fetches a list of scripts detected by Page Shield on hostname
120115

121116
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.
122117

123-
```bash
124-
curl "https://api.cloudflare.com/api/v4/zones/{zone_id}/page_shield/scripts?hosts=example.net&page=1&per_page=15" \
125-
--header "Authorization: Bearer <API_TOKEN>"
126-
```
118+
<APIRequest
119+
path="/zones/{zone_id}/page_shield/scripts"
120+
parameters={{
121+
hosts: "example.net",
122+
page: "1",
123+
per_page: "15",
124+
}}
125+
method="GET"
126+
/>
127127

128128
```json output
129129
{
@@ -173,10 +173,16 @@ For details on the available filtering, paging, and sorting parameters, refer to
173173

174174
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.
175175

176-
```bash
177-
curl "https://api.cloudflare.com/api/v4/zones/{zone_id}/page_shield/scripts?status=infrequent&hosts=example.net&page=1&per_page=15" \
178-
--header "Authorization: Bearer <API_TOKEN>"
179-
```
176+
<APIRequest
177+
path="/zones/{zone_id}/page_shield/scripts"
178+
parameters={{
179+
status: "infrequent",
180+
hosts: "example.net",
181+
page: "1",
182+
per_page: "15",
183+
}}
184+
method="GET"
185+
/>
180186

181187
```json output
182188
{
@@ -225,10 +231,13 @@ For details on the available filtering, paging, and sorting parameters, refer to
225231

226232
This `GET` request obtains the details of a script detected by Page Shield with script ID `8337233faec2357ff84465a919534e4d`.
227233

228-
```bash
229-
curl "https://api.cloudflare.com/api/v4/zones/{zone_id}/page_shield/scripts/8337233faec2357ff84465a919534e4d" \
230-
--header "Authorization: Bearer <API_TOKEN>"
231-
```
234+
<APIRequest
235+
path="/zones/{zone_id}/page_shield/scripts/{script_id}"
236+
method="GET"
237+
parameters={{
238+
script_id: "8337233faec2357ff84465a919534e4d",
239+
}}
240+
/>
232241

233242
```json output
234243
{
@@ -285,10 +294,14 @@ This `GET` request fetches a list of connections detected by Page Shield, reques
285294

286295
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.
287296

288-
```bash
289-
curl "https://api.cloudflare.com/api/v4/zones/{zone_id}/page_shield/connections?page=1&per_page=15" \
290-
--header "Authorization: Bearer <API_TOKEN>"
291-
```
297+
<APIRequest
298+
path="/zones/{zone_id}/page_shield/connections"
299+
parameters={{
300+
page: "1",
301+
per_page: "15",
302+
}}
303+
method="GET"
304+
/>
292305

293306
```json output
294307
{
@@ -329,10 +342,13 @@ For details on the available filtering, paging, and sorting parameters, refer to
329342

330343
This `GET` request obtains the details of a connection detected by Page Shield with connection ID `0a7bb628776f4e50a50d8594c4a01740`.
331344

332-
```bash
333-
curl "https://api.cloudflare.com/api/v4/zones/{zone_id}/page_shield/connections/0a7bb628776f4e50a50d8594c4a01740" \
334-
--header "Authorization: Bearer <API_TOKEN>"
335-
```
345+
<APIRequest
346+
path="/zones/{zone_id}/page_shield/connections/{connection_id}"
347+
method="GET"
348+
parameters={{
349+
connection_id: "0a7bb628776f4e50a50d8594c4a01740",
350+
}}
351+
/>
336352

337353
```json output
338354
{
@@ -363,10 +379,14 @@ This `GET` request fetches a list of cookies detected by Page Shield, requesting
363379

364380
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.
365381

366-
```bash
367-
curl "https://api.cloudflare.com/api/v4/zones/{zone_id}/page_shield/cookies?page=1&per_page=15" \
368-
--header "Authorization: Bearer <API_TOKEN>"
369-
```
382+
<APIRequest
383+
path="/zones/{zone_id}/page_shield/cookies"
384+
parameters={{
385+
page: "1",
386+
per_page: "15",
387+
}}
388+
method="GET"
389+
/>
370390

371391
```json output
372392
{
@@ -409,10 +429,13 @@ For details on the available filtering, paging, and sorting parameters, refer to
409429

410430
This `GET` request obtains the details of a cookie detected by Page Shield with ID `beee03ada7e047e79f076785d8cd8b8e`.
411431

412-
```bash
413-
curl "https://api.cloudflare.com/api/v4/zones/{zone_id}/page_shield/cookies/beee03ada7e047e79f076785d8cd8b8e" \
414-
--header "Authorization: Bearer <API_TOKEN>"
415-
```
432+
<APIRequest
433+
path="/zones/{zone_id}/page_shield/cookies/{cookie_id}"
434+
method="GET"
435+
parameters={{
436+
cookie_id: "beee03ada7e047e79f076785d8cd8b8e",
437+
}}
438+
/>
416439

417440
```json output
418441
{
@@ -453,22 +476,21 @@ All other scripts would trigger a policy violation, but those scripts would not
453476
For more information on <GlossaryTooltip term="content security policy (CSP)">Content Security Policy (CSP)</GlossaryTooltip> directives and values, refer to the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy).
454477

455478
:::note
456-
457479
For a list of CSP directives and keywords supported by Page Shield policies, refer to [CSP directives supported by policies](/page-shield/policies/csp-directives/).
458480
:::
459481

460-
```bash
461-
curl "https://api.cloudflare.com/api/v4/zones/{zone_id}/page_shield/policies" \
462-
--header "Authorization: Bearer <API_TOKEN>" \
463-
--header "Content-Type: application/json" \
464-
--data '{
465-
"description": "My first policy in log mode",
466-
"action": "log",
467-
"expression": "http.host eq myapp.example.com",
468-
"enabled": "true",
469-
"value": "script-src myapp.example.com cdnjs.cloudflare.com https://www.google-analytics.com/analytics.js '\''self'\''"
470-
}'
471-
```
482+
<APIRequest
483+
path="/zones/{zone_id}/page_shield/policies"
484+
method="POST"
485+
json={{
486+
description: "My first policy in log mode",
487+
action: "log",
488+
expression: "http.host eq myapp.example.com",
489+
enabled: "true",
490+
value:
491+
"script-src myapp.example.com cdnjs.cloudflare.com https://www.google-analytics.com/analytics.js 'self'",
492+
}}
493+
/>
472494

473495
```json output
474496
{

0 commit comments

Comments
 (0)