Security Controls
Classificationβ
For clarity the primary definition resource for classification in these standards is HISO 10029:2022 Health Information Security Framework (HISF). In HSIF the scope is defined as follows: "This framework covers the security of all health information that is collected and used within New Zealand; and wherever it is stored. All personal health information is treated as MEDICAL IN CONFIDENCE and given an equal level of protection unless otherwise classified."
Where there is NOT an appropriate representation in HSIF regarding classification the New Zealand Government Protective Security Requirements (PSR) guidance is used
Endorsementsβ
PSR classification guidelines include the use of Endorsements. As per HSIF the primary classification for information covered by these API standards is IN-CONFIDENCE with the endorsement MEDICAL.
API providers MUST use the correct endorsement, following the guidelines in PSR, when undertaking classification analysis.
π‘Depending on the classification of the information that is presented in the APIs and the Risk Framework applied, different access controls will need to be applied. This section provides a summary of the controls that SHOULD be implemented when protecting Health APIs. The five areas that MUST be considered are:
-
Confidentiality
-
Integrity
-
Availability
-
Threat Protection
-
Monitoring, Logging and Auditing
Using the Resource Type definition detailed in FHIR, the controls above will be mapped to the different resources:
Resource Type | Data Type | Classification |
---|---|---|
Anonymous Read Access | UNCLASSIFIED | |
Business | MEDICAL IN-CONFIDENCE | |
Individual | MEDICAL IN-CONFIDENCE | |
Patient | MEDICAL IN-CONFIDENCE |
The following controls are recommended by the FHIR specification and MUST be implemented by the API provider:
Resource Type | Control Required |
---|---|
Anonymous Read Access |
|
Business |
|
Individual |
|
Patient |
|
API Provider controls for all APIsβ
The following is a list of controls and their applicability for all API Providers:
-
MUST enforce access controls at the API provider edgeπ‘
- Throttling to address Distributed Denial of Service (DDoS) attacksπ‘
- Message analysis to block HTTP attacks; parameter attacks such as cross-site scripting (XSS), SQL injection, command injection and cross-site request forgery (XSRF)π‘
- MUST use short-lived Access Tokensπ‘
- SHOULD use JWT Access and Refresh Tokensπ‘
- The Authorisation Server MUST provide a Token Revocation endpointπ‘
- The Authorisation Server MUST provide a Token Introspection endpointπ‘
- Token Signing MUST use EdDSA or ECDSA when protecting sensitive informationπ‘
- Token Encryption MUST use RSA-OAEPπ‘
- Supported hashing algorithms MUST be applied as per the NZISMπ‘
-
All communications to or from an API MUST utilise Transport Layer Security (TLS) 1.3 or higher.π‘ Other versions of TLS and SSL SHOULD be disabled. π‘ This provides a recognised level of confidentiality that covers all communications between all components. Also see NZISM
- API consumer applications MUST validate TLS certificate chains when making requests to protected resources, including checking the Certificate Revocation List (CRL).π‘
Confidentiality and Integrityβ
Confidentiality and integrity cover the handling of request and response data, both in transit and at rest. The aim is to protect the payload content from unauthorised access (eavesdropping), manipulation or faking of content. An API request needs to be received intact by the API, with validation as to the source of the request. Untampered API responses need to be received by the consuming application, with confirmation that they are legitimately from the API.
Data Classification | Control |
---|---|
UNCLASSIFIED |
|
MEDICAL IN-CONFIDENCE |
|
The following table details the data classification application for API Security using OAuth 2.0 and OpenID Connect:
Data Classification | API Security Control (Grant Flows) |
---|---|
UNCLASSIFIED | |
MEDICAL IN-CONFIDENCE |
Grant Type | Control Required | Status |
---|---|---|
Client Credentials with Scopes | client_secret_post token endpoint authorisation SHOULD be applied π‘ | Supported β |
Implicit grant | openid scope in the authentication requestπ‘client_secret_post or client_secret_jwt or private_key_jwt token endpoint authorisation SHOULD be appliedπ‘response_type SHOULD be id_token tokenπ‘state parameter MUST be used in the authorisation request and the API consumer MUST validate it in the responseπ‘nonce parameter MUST be used in the authorisation request and the API consumer MUST validate it in the id_token π‘ | Deprecated β οΈ |
Authorisation Code grant with PKCE | openid scope in the authentication requestπ‘private_key_jwt token endpoint authorisation MUST be appliedπ‘response_type MUST be code id_token π‘state parameter MUST be used in the authorisation request and the API consumer MUST validate it in the responseπ‘nonce parameter MUST be used in the authorisation request and the API consumer MUST validate it in the id_token π‘id_token SHOULD be used as a detached signatureπ‘c_hash , at_hash and s_hash valuesπ‘id_token MAY be usedπ‘ | Supported β |
Hash Valuesβ
In OpenID Connect, the c_hash
, at_hash
, and s_hash
values are used to enhance the security and integrity of the authorisation process.
In OpenID Connect, the c_hash
, at_hash
, and s_hash
values are used to enhance the security and integrity of the authorisation process.
c_hash
(Code Hash)β
- Used in the authorisation code flow when using
response_type=code id_token
andresponse_type=code id_token token
- The response to the client is a
code
and the firstid_token
(andaccess_token
if requested) - The
id_token
signature is validated by obtaining the JWKS from the the Authorisation Server JWK endpoint - Parsing the
id_token
, thec_hash
is found and using SHA-256 (defined in the header of theid_token
alg
) compares the code with thec_hash
- Provides authorisation code integrity.
at_hash
(Access Token Hash)β
- Used in the authorisation code flow when using
response_type=id_token token
andresponse_type=code id_token token
1 - The response to the client when the code is presented to the token endpoint is a JWT access token and and
id_token
- The
id_token
signature is validated by obtaining the JWKS from the the Authorisation Server JWK endpoint - Parsing the
id_token
, theat_hash
is found and using SHA-256 (defined in the header of theid_token
alg
) compares the access token with theat_hash
- Provides Access token integrity.
s_hash
(State Hash)β
- Used in the authorisation code flow and implicit flow when using
response_type=code id_token
the authorisation request includes astate
value created by the client - The response to the client is a code and and the first
id_token
- The
id_token
signature is validated by obtaining the JWKS from the the Authorisation Server JWK endpoint - Parsing the
id_token
, thes_hash
is found and using SHA-256 (defined in the header of theid_token
alg
) compares thestate
with thes_hash
. - Provides state integrity.
State (Integrity)β
state
is also a parameter that MUST be used during the authorisation grant stage to provide a level of security to address possible XSRF attacks.π‘The state
parameter is a string that is sent to the Authorisation Server by the client when requesting an authorisation code. It is sent back to the client with the Authorisation Code and MUST be verified by the API consumer application to confirm the authenticity of the response i.e. it came from the Authorisation Server to which the request was sent.π‘
Content Encryption (Confidentiality)β
If content needs only to be visible to specific consumer endpoints, use encryption. However, if content only needs to be guaranteed untampered and/or from a specific source (e.g. provider) then APIs SHOULD use content signing. Content encryption enables all or part of an API payload to be readable only by the target consumer(s). This is useful where the content being carried by the API is sensitive, and the API request or response transits multiple stopping points. Whilst TLS protects the payload in transit, it only applies to each point to point connection between components (e.g. mobile app to API gateway). If transit components are not totally under the providerβs control, it can be worthwhile performing payload encryption. E.g. it may be sensible to encrypt credit card details passed between consumer and provider backend systems.
It is also worth considering how much protection the information needs whilst at rest. Data at rest encryption is generally considered good practice and many cloud service providers offer this as standard. See NZISM for details.
Encryption is only worthwhile implementing when data sensitivity or data protection requirements drive it, as encryption can be computationally intensive. It also makes it more difficult for protection mechanisms, such as API gateways, to validate and transform API content. When only the integrity of the content passed needs to be ensured, consider using Content Signing instead.
There are many existing ways of encrypting message content, built into code libraries and development tools. It is REQUIRED that any content encryption adheres to the standard algorithms laid out in NZISM (HMAC Algorithms).π‘
Content Signing (Integrity)β
Content signing is used to assure content integrity and proof of authorship. It can apply to the entire payload of the API request/response or specific elements of that content e.g. credit card details. There are many approaches to content signing and the most appropriate approach is requirements dependent. Standard signing algorithms exist within coding libraries, and JWT has a payload that can contain verifiable (signed) JSON fields.
Signing has less of a computational overhead than encryption, but can still affect performance, so it is advisable that it be used only when and where needed. This is covered under:
Where Bearer Tokens are used, they MUST be JSON Web Tokens (JWT) signed using JSON Web Signatureπ‘ as defined in:
Non-Repudiation (Integrity)β
Non-repudiation covers the means to ensure that a consumer cannot deny making a request and, similarly, a provider cannot claim they did not send a response. To aid non-repudiation for APIs, it is important to ensure credentials are not shared between consumers and to perform comprehensive logging of API request/responses.
Digital signatures are useful for not just guaranteeing authenticity and integrity, but also supporting non-repudiation.
Availability and Threat Protectionβ
Availability in this context covers threat protection to minimise API downtime, looks at how threats against exposed APIs can be mitigated using basic design principles and how to apply protection against specific risks and threats.
Availability also covers scaling to meet demand and ensuring hosting environments are stable etc. These levels of availability are addressed across hardware and software stacks that support the delivery of APIs. There are no specific standards for availability, but availability is normally addressed under business continuity and disaster recovery standards. These standards recommend a risk assessment approach to define API availability requirements. Further information on business continuity and risks can be found at Standards New Zealand website
For cloud services, the New Zealand Government ICT website provides an assessment capability that includes a risk assessment tool which covers availability, business continuity and disaster recovery related questions.
As mentioned in section Consideration of Risks, there are various types of risk which impact APIs. This includes threats to availability as well as confidentiality and integrity.
Where the resources being exposed by an API are sensitive i.e. not public data, the following rules apply:
- Threat assessment MUST be assessed in the API development lifecycleπ‘
- Penetration testing MUST be performed once an API is developed and published (testable) and on a regular schedule post publicationπ‘
- Automated vulnerability testing tools MUST be used to give an indication of vulnerabilities in API implementationsπ‘
Below is a table of risk types and some approaches that SHOULD be used to help mitigate these threats:
Threat | Mitigation (OWASP) |
---|---|
Exposure of inappropriate API methods to access services | |
Denial of Service attacks | |
Malicious Input, Injection attacks and Fuzzing | |
Cross-Site Request Forgery | state and nonce parametersπ‘ |
Cross-Site Scripting Attacks |
Token Threat Mitigationβ
Securing OAuth 2.0 flows relies on the exchange of tokens between consuming applications and API provider servers. There is always the threat of these tokens being obtained illicitly, losing confidentiality and integrity of message content or the integrity of the sender of the token. This risk also applies to the transferring of API keys.
Threat | Mitigation |
---|---|
Token Manufacture or modification (fake tokens and man-in-the-middle attacks) | |
Token disclosure β man-in-the-middle attack. The Access Token is passed in clear text with no hashing, signing or encryption. | Communication Security: |
Token Redirects. Ensure the Authentication and Resource Servers are "paired", and the access token can only be used in the correct context | state parameter in the headerπ‘ |
Token replay β where the threat actor copies an existing token (e.g. refresh token or authorisation code) and reuses it on their own request |
Monitoring, Logging and Alertingβ
Appropriate controls:
- All API interactions MUST be loggedπ‘
- The request or response payload SHOULD NOT be loggedπ‘
- PII information MUST NOT be loggedπ‘
- Sensitive information in headers MUST NOT be logged (e.g. tokens, API Keys)π‘
- Full content logging MUST NOT be appliedπ‘
- The use and issuance of Access Tokens MUST be monitoredπ‘
-
Monitoring the OAuth 2.0 flow SHOULD be performed for suspicious activity and regularly auditing logs can help detect and prevent potential security breaches. This includes monitoring for anomalous requests, access attempts to unauthorised resources, and unusual client behavior.π‘
- Logs MUST be stored in a tamper-proof and secure locationπ‘
-
Detecting events that may indicate a malicious attempt to access an API MUST be logged and monitoredπ‘
- Correlating API requests with specific back-end system activity and the resulting API responses to support end-to-end tracing - capture timestamps, user/consumer information and actions performed SHOULD be loggedπ‘
- Logging of user actions (login, logout) SHOULD be monitoredπ‘
- Identifying specific API requests from consumers to help resolve API consumer problems SHOULD be monitoredπ‘
Traditional logging, alerting and incident management practices also apply to APIs. The following MUST be applied:
The following SHOULD be applied:
Footnotesβ
-
at_hash
is typically supplied when the access token is returned from the authorisation endpoint. As noted in Grant Types, these SHOULD NOT be used and is only listed here for completeness. β©