Bolstering the Security of DHIS2 Public Portal Middlewares - Novel Approach and Best Practices

This abstract has been accepted at the 2024 DHIS2 Annual Conference


Bolstering the Security of DHIS2 Public Portal Middlewares - Novel Approach and Best Practices

Bolstering DHIS2 P DHIS2, a cornerstone in global Health Information Management Systems, provides centralized health data and analytics crucial for informed healthcare decisions. The rise in the need to share some of this data with partners, donors and the public who do not have direct access to the various DHIS2 instances, has led to an innovative approach of DHIS2 implementers, mostly health Ministries, building public portals for open and easy data sharing. These portals act as bridges, fetching data from DHIS2 through custom built a middleware from the DHIS2 API, with the goal of safeguarding the DHIS2 instances from direct exposure to the public internet. However, the non authenticated nature of public portals poses security challenges, shifting the onus onto Middleware to fortify defenses against potential threats. This paper addresses this challenge by proposing a robust and more secure approach for building custom middlewares finally to authenticate requests from DHIS2 public portals (leveraging the novel NextJS Server Actions), which had been almost impossible to implement securely in the past without exposing the DHIS2 instance credentials to the client public portal. The proposed security measures include Leveraging the new NextJS 14 Server Actions and other important measures that are a must for a robust and secure middleware: 1. Leverage the new NextJs Server Actions (‘use server’, ‘use client’) alongside a custom middleware: The NextJS client app (Public data visualization portal) leverages its server action capabilities by making authenticated request to the middleware with an API Key that is only known by the middleware. If the middleware validates the request and API Key to be valid, then the requested data is fetched from the DHIS2 API and sent back to the NextJs public portal, which passes the data to its client component that invoked the server action. It is important to note that, the API key cannot be exposed in this case, as it is handled by the Server Action that made the request on behalf of the client component (‘use client’). This approach ensures that only requests coming from the portal are authenticated, and bad actors cannot abuse the middleware and gain unauthenticated access to it even if they know the its IP. The full paper and links to the proof of concetp code can be found in the attached documents.

Primary Author: Baboucarr Ceesay


Keywords:
DHIS2 Public Portals, Data Visualization, Middleware, Security, API, React, Next.js

3 Likes