Skip to content

Commit b94725b

Browse files
committed
CCM-4566: address zap alerts
1 parent 114c1fd commit b94725b

File tree

10 files changed

+75
-108
lines changed

10 files changed

+75
-108
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ tmp/
3535
tests/locust/*.html
3636
postman/Integration.test.postman_environment.json
3737
sandbox/test-results.xml
38+
.vscode/*

azure/nightly-zap-scan-pipeline.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,14 @@ steps:
3535
parameters:
3636
secret_file_ids:
3737
- ptl/api-deployment/communications-manager/INTEGRATION_PRIVATE_KEY
38-
- ptl/azure-devops/communications-manager/PRODUCTION_PRIVATE_KEY
3938
secret_ids:
4039
- ptl/api-deployment/communications-manager/INTEGRATION_API_KEY
41-
- ptl/azure-devops/communications-manager/PRODUCTION_API_KEY
4240
- template: ./templates/teams-alert-setup.yml
4341
parameters:
4442
webhook_uri: 'ALERTS_DEV_API_WEBHOOK_URI'
4543
- bash: |
4644
export INTEGRATION_PRIVATE_KEY="$(Pipeline.Workspace)/secrets/$(INTEGRATION_PRIVATE_KEY)"
4745
export INTEGRATION_API_KEY="$(INTEGRATION_API_KEY)"
48-
export PRODUCTION_PRIVATE_KEY="$(Pipeline.Workspace)/secrets/$(PRODUCTION_PRIVATE_KEY)"
49-
export PRODUCTION_API_KEY="$(PRODUCTION_API_KEY)"
5046
make install-python && make zap-security-scan
5147
displayName: Run OWASP zap scan
5248
- task: PublishTestResults@2

docs/proxies.md

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ Source: [proxies/shared/partials/Partial.Target.PreFlowRequest.xml](https://gith
277277

278278
```mermaid
279279
flowchart
280-
S[Start] --> SRD["<a href='https://github.com/NHSDigital/communications-manager-api/blob/release/docs/proxies.md#set-response-defaults'>Set response defaults</a>"]
281-
SRD --> SBCI["Set the backend request correlation id
280+
S[Start] --> SBCI["Set the backend request correlation id
282281
283282
<em><a href='https://github.com/NHSDigital/communications-manager-api/blob/release/proxies/shared/policies/JavaScript.SetBackendCorrelationId.xml'>JavaScript.SetBackendCorrelationId</a></em>"]
284283
SBCI --> ADRP["Sets a default request path
@@ -348,20 +347,6 @@ flowchart
348347
405 --> E
349348
```
350349

351-
### Target PreFlow Response
352-
353-
This defines the actions carried out on all outgoing responses from the communications manager target.
354-
355-
Source: [proxies/shared/partials/Partial.Target.PreFlowResponse.xml](https://github.com/NHSDigital/communications-manager-api/blob/release/proxies/shared/partials/Partial.Target.PreFlowResponse.xml)
356-
357-
```mermaid
358-
flowchart LR
359-
S[Start] --> AD["Add CORS headers
360-
361-
<em><a href='https://github.com/NHSDigital/communications-manager-api/blob/release/proxies/shared/policies/AssignMessage.AddCors.xml'>AssignMessage.AddCors</a></em>"]
362-
AD --> E[End]
363-
```
364-
365350
### Create Message Batch
366351

367352
This flow manages the validating of incoming create message batches requests, plus mapping the incoming request and outgoing response so they match the schemas set out in the specification.

proxies/live/apiproxy/targets/target.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
<Request>
44
[% include './partials/Partial.Target.PreFlowRequest.xml' %]
55
</Request>
6-
<Response>
7-
[% include './partials/Partial.Target.PreFlowResponse.xml' %]
8-
</Response>
96
</PreFlow>
107
<Flows>
118
[% include './partials/Partial.Flows.CreateMessageBatchEndpoint.xml' %]

proxies/sandbox/apiproxy/targets/sandbox.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
<Request>
44
[% include './partials/Partial.Target.PreFlowRequest.xml' %]
55
</Request>
6-
<Response>
7-
[% include './partials/Partial.Target.PreFlowResponse.xml' %]
8-
</Response>
96
</PreFlow>
107
<Flows>
118
[% include './partials/Partial.Flows.CreateMessageBatchEndpoint.xml' %]

proxies/shared/partials/Partial.Target.PreFlowRequest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
[% include './partials/Partial.Component.SetResponseDefaults.xml' %]
21
<Step>
32
<Name>JavaScript.SetBackendCorrelationId</Name>
43
</Step>

proxies/shared/partials/Partial.Target.PreFlowResponse.xml

Lines changed: 0 additions & 3 deletions
This file was deleted.

scripts/publish_zap_compatible.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def scan_and_remove(obj, mappings):
3434
specification,
3535
(
3636
("format", "date"),
37-
("personalisation", None)
37+
("personalisation", None),
38+
("/callbacks", None)
3839
)
3940
),
4041
f

scripts/run_zap.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@ mv .python-version.ignore .python-version
1717

1818
# open the contents in INTEGRATION_PRIVATE_KEY and put it into INTEGRATION_PRIVATE_KEY_CONTENTS
1919
export INTEGRATION_PRIVATE_KEY_CONTENTS=$(cat $INTEGRATION_PRIVATE_KEY)
20-
export PRODUCTION_PRIVATE_KEY_CONTENTS=$(cat $PRODUCTION_PRIVATE_KEY)
2120

2221
docker build -t zap -f ./zap/Dockerfile .
2322

2423
# run zap in a container
2524
docker container run \
2625
--env INTEGRATION_PRIVATE_KEY_CONTENTS="$INTEGRATION_PRIVATE_KEY_CONTENTS" \
2726
--env INTEGRATION_API_KEY="$INTEGRATION_API_KEY" \
28-
--env PRODUCTION_PRIVATE_KEY_CONTENTS="$PRODUCTION_PRIVATE_KEY_CONTENTS" \
29-
--env PRODUCTION_API_KEY="$PRODUCTION_API_KEY" \
3027
-v $(pwd):/zap/wrk/:rw \
3128
-v $TEMP_DIR:/zap/tmp/:rw \
3229
-v $(pwd)/zap/comms-manager-json/:/home/zap/.ZAP/reports/comms-manager-json/:rw \

zap/zap.yaml

Lines changed: 71 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,20 @@ env:
1010
urls:
1111
- https://int.api.service.nhs.uk/comms # the actual url used for the scan is defined in the openapi job below
1212
authentication:
13-
method: 'script'
13+
method: script
1414
parameters:
1515
url: https://int.api.service.nhs.uk/oauth2/token
16-
script: 'scripts/authentication/get_bearer_token.js'
17-
scriptEngine: 'Graal.js'
16+
script: scripts/authentication/get_bearer_token.js
17+
scriptEngine: Graal.js
1818
verification:
19-
method: 'response'
20-
loggedOutRegex: '401 Unauthorized'
19+
method: response
20+
loggedOutRegex: 401 Unauthorized
2121
users:
2222
- name: Integration
2323
credentials:
2424
kid: local
25-
api_key: "${INTEGRATION_API_KEY}"
26-
private_key: "${INTEGRATION_PRIVATE_KEY_CONTENTS}"
27-
- name: ProdUnauthenticated
28-
urls:
29-
- https://api.service.nhs.uk/comms # the actual url used for the scan is defined in the openapi job below
30-
- name: ProdAuthenticated
31-
urls:
32-
- https://api.service.nhs.uk/comms # the actual url used for the scan is defined in the openapi job below
33-
authentication:
34-
method: 'script'
35-
parameters:
36-
url: https://api.service.nhs.uk/oauth2/token
37-
script: 'scripts/authentication/get_bearer_token.js'
38-
scriptEngine: 'Graal.js'
39-
verification:
40-
method: 'response'
41-
loggedOutRegex: '401 Unauthorized'
42-
users:
43-
- name: Prod
44-
credentials:
45-
kid: prod-1
46-
api_key: "${PRODUCTION_API_KEY}"
47-
private_key: "${PRODUCTION_PRIVATE_KEY_CONTENTS}"
25+
api_key: ${INTEGRATION_API_KEY}
26+
private_key: ${INTEGRATION_PRIVATE_KEY_CONTENTS}
4827
parameters:
4928
failOnError: true
5029
failOnWarning: true
@@ -54,46 +33,83 @@ jobs:
5433
# load our authentication and httpsender script
5534
- type: script
5635
parameters:
57-
action: 'add'
58-
type: 'httpsender'
59-
engine: 'Graal.js'
60-
name: 'add_bearer_token'
61-
file: 'scripts/httpsender/add_bearer_token.js'
36+
action: add
37+
type: httpsender
38+
engine: Graal.js
39+
name: add_bearer_token
40+
file: scripts/httpsender/add_bearer_token.js
6241
- type: script
6342
parameters:
64-
action: 'add'
65-
type: 'authentication'
66-
engine: 'Graal.js'
67-
name: 'get_bearer_token'
68-
file: 'scripts/authentication/get_bearer_token.js'
43+
action: add
44+
type: authentication
45+
engine: Graal.js
46+
name: get_bearer_token
47+
file: scripts/authentication/get_bearer_token.js
48+
49+
# configure the passive scan
50+
- type: passiveScan-config
51+
parameters:
52+
maxAlertsPerRule: 10
53+
scanOnlyInScope: true
54+
rules:
55+
- id: 10049
56+
name: Non-Storable Content
57+
threshold: Off
58+
# We do not want responses cached.
59+
# See https://github.com/NHSDigital/communications-manager-api/pull/548 for more information.
60+
61+
- id: 90005
62+
name: Sec-Fetch-Site Header is Missing
63+
threshold: Off
64+
# Sec-Fetch-* headers are only for requests.
65+
# See https://github.com/NHSDigital/communications-manager-api/pull/548 for more information.
66+
67+
- id: 10094
68+
name: Base64 Disclosure
69+
threshold: Off
70+
# The KSUIDs are sometimes detected as base64 strings.
71+
# See https://github.com/NHSDigital/communications-manager-api/pull/548 for more information.
72+
73+
- id: 110009
74+
name: Full Path Disclosure
75+
threshold: Off
76+
# Error responses include a link to the NHS developer catalogue.
77+
# ZAP is picking up 'developer' in the link.
78+
# See https://github.com/NHSDigital/communications-manager-api/pull/548 for more information.
79+
80+
- id: 90004
81+
name: Insufficient Site Isolation Against Spectre Vulnerability
82+
threshold: Off
83+
# CORS headers (including Cross-Origin-Resource-Policy) are only added to the response when the request has an origin specified.
84+
# See https://github.com/NHSDigital/communications-manager-api/pull/548 for more information.
85+
86+
- id: 10062
87+
name: PII Disclosure
88+
threshold: Off
89+
# Error responses include the apigee message id in the body.
90+
# Sometimes it can be detected as a Maestro credit card number.
91+
# This rule only checks for credit card details, no other PII.
92+
# See https://github.com/NHSDigital/communications-manager-api/pull/548 for more information.
6993

7094
# load the zap specific openapi specification
7195
- type: openapi
7296
parameters:
73-
apiFile: '/zap/wrk/build/communications-manager-zap.json'
97+
apiFile: /zap/wrk/build/communications-manager-zap.json
7498
targetUrl: https://sandbox.api.service.nhs.uk/comms
7599
context: Sandbox
76100
- type: openapi
77101
parameters:
78-
apiFile: '/zap/wrk/build/communications-manager-zap.json'
102+
apiFile: /zap/wrk/build/communications-manager-zap.json
79103
targetUrl: https://int.api.service.nhs.uk/comms
80104
context: IntegrationUnauthenticated
81105
- type: openapi
82106
parameters:
83-
apiFile: '/zap/wrk/build/communications-manager-zap.json'
107+
apiFile: /zap/wrk/build/communications-manager-zap.json
84108
targetUrl: https://int.api.service.nhs.uk/comms
85109
context: IntegrationAuthenticated
86-
- type: openapi
87-
parameters:
88-
apiFile: '/zap/wrk/build/communications-manager-zap.json'
89-
targetUrl: https://api.service.nhs.uk/comms
90-
context: ProdUnauthenticated
91-
- type: openapi
92-
parameters:
93-
apiFile: '/zap/wrk/build/communications-manager-zap.json'
94-
targetUrl: https://api.service.nhs.uk/comms
95-
context: ProdAuthenticated
96110

111+
# let the passive scan do it's stuff
112+
- type: passiveScan-wait
97113

98114
# run an active scan on sandbox
99115
- type: activeScan
@@ -123,31 +139,12 @@ jobs:
123139
delayInMs: 500
124140
threadPerHost: 1
125141

126-
# run an active scan on prod, using unauthenticated calls
127-
- type: activeScan
128-
parameters:
129-
policy: API
130-
context: ProdUnauthenticated
131-
scanHeadersAllRequests: true
132-
delayInMs: 500
133-
threadPerHost: 1
134-
135-
# run an active scan on prod, using authenticated calls
136-
- type: activeScan
137-
parameters:
138-
policy: API
139-
context: ProdAuthenticated
140-
user: Prod
141-
scanHeadersAllRequests: true
142-
delayInMs: 500
143-
threadPerHost: 1
144-
145142
# generate our custom JSON report
146143
- type: report
147144
parameters:
148-
template: 'comms-manager-json'
149-
reportDir: '/zap/tmp'
150-
reportFile: 'zap-report.json'
145+
template: comms-manager-json
146+
reportDir: /zap/tmp
147+
reportFile: zap-report.json
151148
risks:
152149
- high
153150
- medium
@@ -157,4 +154,4 @@ jobs:
157154
- high
158155
- medium
159156
- low
160-
- falsepositive
157+
- falsepositive

0 commit comments

Comments
 (0)