Skip to content

Commit 154c770

Browse files
committed
First pass at a best practices document (fixes #188)
1 parent 945567a commit 154c770

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

docs/best-practices.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Implementation Best Practices
2+
3+
This page serves as best practice guidance for CDS Hooks implementers. The best practices outlined here are not mandatory implementation rules; rather, they are suggested guidance. This is a living, in progress document and the best practices outlined here should not be considered absolute or complete.
4+
5+
## Security
6+
7+
Implementing the CDS Hooks security model requires perhaps the most thought and consideration for implementers. Security topics are never binary, are often complex, and robust implementations should factor in concepts such as risk and usability. Implementers should approach their security related development with thoughtful care.
8+
9+
The CDS Hooks specifications already provides some guidance in this space. The information here is supplemental to the existing specification documentation.
10+
11+
The CDS Hooks security model leverages several existing RFCs. These should be read and fully understood by all implementers.
12+
13+
- [rfc7519: JSON Web Tokens (JWT)](https://tools.ietf.org/html/rfc7519)
14+
- [rfc7517: JSON Web Key (JWK)](https://tools.ietf.org/html/rfc7517)
15+
- [rfc7515: JSON Web Signature (JWS)](https://tools.ietf.org/html/rfc7515)
16+
- [rfc7518: JSON Web Algorithms (JWA)](https://tools.ietf.org/html/rfc7518)
17+
18+
### CDS Clients
19+
20+
Implementers of CDS Clients should:
21+
22+
**Maintain a whitelist of CDS Service endpoints that may be invoked.**
23+
24+
Only endpoints on the whitelist can be invoked. This ensures that CDS Clients invoke only trusted CDS Services. This is especially important since CDS Clients may send an authorization token that allows the CDS Service temporary access to the FHIR server.
25+
26+
**Issue secure FHIR access tokens.**
27+
28+
*If* a CDS Clients generates access tokens to its FHIR server, the tokens should:
29+
30+
- Be unique for each CDS Service endpoint.
31+
- Be very short-lived.
32+
- Provide the minimum necessary access for the CDS Service. This includes both SMART scopes as well as the patient(s)/data that can be accessed.
33+
34+
### CDS Services
35+
36+
#### JWT
37+
38+
Upon being invoked by a CDS Client, the CDS Service should first process the given JWT to determine whether to process the given request. In processing the JWT, CDS Services should:
39+
40+
1. Ensure that the `iss` value exists in the CDS Service's whitelist of trusted CDS Clients.
41+
2. Ensure that the `aud` value matches the CDS Service endpoint currently processing the request.
42+
3. Ensure that the `exp` value is not before the current date/time.
43+
4. Ensure that the `tenant` value exists in the CDS Service's whitelist of trusted tenants (may not be applicable to all CDS Services).
44+
5. Ensure that the JWT signature matches the public key on record with the CDS Service. See additional notes below.
45+
6. Ensure that the `jti` value doesn't exist in the short-term storage of JWTs previously processed by this CDS Servie.
46+
47+
Once the JWT has been deemed to be valid, the `jti` value should be stored in the short-term storage of processed JWTs. Values in this storage only need to be kept for the maximum duration of all JWTs processed by this CDS Service. If the CDS Clients are adhering to best practices, this should be no more than an hour.
48+
49+
Verifying the JWT signature is a critical step in establishing trust of the caller of the CDS Service. As part of the whitelist of trusted CDS Clients, information on the public key(s) used by the CDS Client should also be stored. In some cases, this public key may be shared out-of-band. In other cases, the public key may be available at a remote endpoint and cycled on a regular basis. It is this latter case in which CDS Services should maintain their own rotating cache of public keys for the CDS Client.
50+
51+
CDS Services should never store, share, or log JWTs to minimize the risk of theft and replay attacks. Information within the JWT (for instance, `iss`, `tenant`, `jti`) can be logged safely and is especially useful for analytics.
52+
53+
If a CDS Service deems a JWT to be invalid for any reason, it should not leak the details of why the JWT failed validation back to the caller. If the caller were a malicious threat actor, leaking detailed information as to what was invalid may give the threat actor guidance on how to shape future attacks. Instead, responding to the request with a HTTP 401 Unauthorized response status code without any additional information is sufficient.
54+
55+
#### FHIR Access
56+
57+
CDS Services should never store, share, or log the FHIR access token (`fhirAuthorization.access_token`) given to it by the CDS Client. The access token should be treated as an extremely sensitive, transient piece of data.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ nav:
2020
- 'medication-prescribe 2' : 'hooks/medication-prescribe.md'
2121
- 'order-review 3' : 'hooks/order-review.md'
2222
- Quick Start: 'quickstart.md'
23+
- Best Practices: 'best-practices.md'
2324
- Examples: 'examples.md'
2425
- Community: 'community.md'
2526

0 commit comments

Comments
 (0)