Securing Binary resources and bulk export files in HAPI FHIR

Binary resources and bulk export files often hold the most sensitive clinical content on a HAPI FHIR server. This page explains how to restrict them with securityContext, export job settings and storage protections.

On this page

Why Binary and bulk export files need their own access rules

A team that stores clinical documents, images or exported NDJSON files on a self-hosted HAPI FHIR server needs a clear answer to one question: who can read each of those files? The answer does not come for free from the resource rules the team has already written. HAPI FHIR states that it does not provide a single one-size-fits-all security layer. It offers building blocks such as authentication interceptors, the AuthorizationInterceptor, consent and search narrowing interceptors, CORS support and BALP audit logging, and each of these must be configured for the data it protects. Binary content and export output are easy to miss in that design because they sit beside the structured resources the rules were written for.

Binary and export files are a separate access surface. A Binary resource carries raw content such as a PDF or image, so a rule that allows reads of clinical resource types does not say anything about the bytes behind a Binary read. Bulk export is also a job that produces files, and those files may be fetched by a different client or stored for longer than the request that created them. This page covers three levers: Binary.securityContext on individual resources, the settings that control who may start and read bulk export jobs, and protections on the storage where the files live. Each lever needs an owner and a test.

Before building anything, confirm with your team which of your interceptors and rule sets currently evaluate Binary reads and export job requests, and which ones only inspect structured resources. The HAPI FHIR security documentation at HAPI FHIR security introduction is the starting point for that review. Confirm the behavior against the exact version you run, since the building blocks and their defaults can differ across releases, and record the gaps before you write any rules.

Protection options for Binary and export files and when each fits

This table compares four ways to protect Binary resources and bulk export files on a HAPI FHIR server, with the case where each fits and its trade-off. Read it as a set of layers rather than a menu, since most deployments combine a server-side rule with storage-level controls.

OptionWhere it fitsTrade-offWhat to confirm
Binary.securityContext linked to a patient or compartmentDocuments and images that belong to one patient, where the record's ownership is already knownProtection depends on the link being set correctly at write time, and unlinked Binary resources need a separate ruleWhich resource types and writers set securityContext, and how the link is validated on create and update
AuthorizationInterceptor rules that deny Binary reads by defaultServers where most clients should never download raw files, and only named roles or applications need themDefault deny is strict, so legitimate clinical or integration reads must be added as explicit allow rules and testedWhether your rules cover Binary reads, Binary search, and any operation that returns Binary content
Restricting or disabling bulk export for non-privileged clientsDeployments where bulk export is used only by a few backend systems or analytics pipelinesBlocking export protects against large-scale extraction but can break approved research or payer workflows that depend on itWhich clients need the bulk export operations, and whether export output files are reachable by other clients
Storage-level encryption and access controls for the blob or file locationAny deployment where exported files or stored binaries sit in a file system, object store or database volume outside the FHIR APIStorage controls do not apply FHIR-level rules, so a client with storage access can read files the API would refuseThe storage location in use, who holds storage credentials, and whether encryption keys are managed separately from the server

Setting up Binary and export protection in order

This sequence moves a HAPI FHIR server from unprotected document and export files to a state where every Binary resource and bulk export output has a governing resource, a security context, an authorization rule and a tested location. Each step closes with a check so the team can confirm the protection before moving on.

  1. Inventory Binary resources and export outputs

    The clinical or compliance lead and the server owner list every place the server stores or emits non-structured content: Binary resources for documents, images and attachments, and the files written by bulk export jobs. For each source, record the content type, the patient data it likely contains, who creates it and who must read it. Confirm with the team which of these outputs hold protected health information and which are operational only. The step is done when the inventory has one row per content source, each marked as PHI or not, and the owner has signed off on the list.

  2. Decide the governing resource for each binary

    A Binary resource has no compartment of its own, so access must be decided by a resource that points to it, such as a DocumentReference, Media, DiagnosticReport or Observation. For each inventory row, the architect chooses the governing resource, the patient reference that ties it to a compartment, and the rule for who may see it. Write the decision down, including what happens to a Binary that no governing resource references. The step is done when every PHI Binary type has a named governing resource and an orphan-handling rule that the team has agreed.

  3. Set securityContext when writing binaries

    The developer of the write path sets Binary.securityContext to a reference to the governing resource at creation time, so the binary inherits the same access decision as its parent. Test the write path with a sample upload from each client that creates binaries, and confirm the stored resource carries the reference. Ask the team to confirm how existing Binaries without a securityContext will be found and corrected, since this may require a data migration or a reindex on a database that is already in use. The step is done when new writes carry the reference and the list of legacy Binaries is known.

  4. Write AuthorizationInterceptor rules for Binary and export

    The authorization engineer adds rules to the AuthorizationInterceptor that cover read and vread on Binary, and the $export operation at system, patient and group levels. Binary rules should allow access only when the caller is permitted to read the governing resource, and export rules should limit who can start an export and which resource types it may include. Confirm the rule set with the security owner before deployment, since a rule that is too broad leaks data and one that is too narrow blocks clinical workflows. The step is done when the rule file is reviewed and checked into version control, and it loads without errors on a test instance.

  5. Configure the export file location and access

    The platform engineer sets where the server writes bulk export files and who can read them from the storage layer. Restrict the export directory or bucket to the server's service account, disable public listing, and keep the download path behind the FHIR server so the authorization rules apply. Confirm with the infrastructure team how file location settings are changed, since updates to the export configuration usually need a server restart to take effect. Also confirm the retention and deletion approach for export files with the data owner. The step is done when only the server identity can write and read the export path and a file written outside the server is not reachable from the network.

  6. Verify with positive and negative requests

    The security tester runs a fixed set of requests against a test environment that mirrors production. Positive tests use a user with rights to a patient and confirm they can read that patient's Binary and start an export. Negative tests use a user without the right, an unauthenticated client, and a user for another patient, and confirm each receives a denial with no content returned. Also request a Binary without a securityContext and an export file path guessed directly on storage. Record the results, fix any gaps and repeat the run after changes. The step is done when every negative test is denied, every positive test succeeds, and the results are filed for the audit record.

  7. Confirm operations and change control

    The operations lead documents how the protection will be maintained after go-live. This covers how new binary types are added to the inventory, how rule changes are reviewed, which configuration changes need a restart, and which database changes, such as data corrections on existing Binary rows, must be confirmed with the database owner before they run. Schedule the negative test set to run after each upgrade or rule change. The step is done when the runbook names an owner for each control and the team has agreed the change process.

Security and operational risks around Binary and export files

Binary resources and bulk export files sit outside the resource-level rules many teams write first, so they tend to be the weakest path into a HAPI FHIR server. The cards below cover the access, storage, retention, credential, backup and audit gaps that connect them, with the control to check for each.

Binary reads bypass resource rules

A Binary resource holds raw content such as a PDF, image or scanned document, and it is not the same as the DocumentReference that points to it. Rules written for Patient or Observation may not cover Binary reads at all, so a caller could fetch the file directly by ID. Set securityContext on each Binary so it refers to the compartment or resource that governs it, then test a direct Binary read with a user who lacks access to the linked patient.

HAPI FHIR security docs

Export files readable after the job

Bulk export writes NDJSON output files that remain on disk or in object storage after the job finishes. If those files sit on shared storage with broad read permissions, the bulk export authorization model is undone at the file layer. Confirm where the output is written, who can list that location, and whether the files are removed or moved to a restricted bucket once the client has retrieved them.

Unclear export retention

Export output is often kept longer than anyone intended because no one owns the cleanup. Decide how long files live, who approves that period, and what triggers deletion, then document it in the same place as the export configuration. Ask your team to confirm whether any retention setting applies to exported files in the version you run, and to test cleanup on a non-production server before relying on it.

File store credentials in configuration

Export and Binary storage often need access keys for object storage or a file system mount. When these are placed in application properties, Helm values or container environment variables, they can leak through configuration repositories, logs or support bundles. Keep store credentials in a secrets manager, scope them to a single bucket or path with read and write only where needed, and rotate them on a schedule your security team sets.

Backups lose the access model

A database restore can bring back resource rows while the files they point to are missing, stale or stored under a different path. The reverse also happens: files are restored with permissions copied from a snapshot that no longer matches the security context in the database. Back up the database and the file store together, record the mapping between Binary IDs and storage keys, and test a restore that checks both a Binary read and an export download under the original rules.

Gaps in file download audit

Audit logging does not follow a file download automatically. BALP audit logging is a building block the operator must configure, and it needs to cover Binary reads and export retrieval, not only resource searches. Confirm that each download produces an AuditEvent with the user, client and resource identified, that these records go to a repository the application cannot edit, and that someone reviews them for unusual volumes of file access.

HAPI FHIR security docs

Setting securityContext and access on bulk export jobs

Bulk export is where a HAPI FHIR deployment can quietly create the largest copy of protected data, so the first decision is to treat each export job and its output files as governed records rather than transient API responses. A $export request returns data as NDJSON files that a client downloads from URLs the server supplies, which means the people who can start a job, read its status and fetch its files together determine who can see the data. Before go-live, the operator should map each of those three actions to a named role and confirm which of them the authorization layer in front of the server actually checks.

Confirm the following in the HAPI FHIR version you run, using the HAPI FHIR documentation on versions and the server's own export documentation. Ask where output files are written (local disk, a shared volume, or object storage), who can read that location outside the server, and whether the server exposes the file URLs to any authenticated caller or only to the client that started the job. Ask whether the export job records which client and user requested it, and whether the job's status and output can be scoped to that requester. Also confirm how export-related operations interact with your authorization rules, because a rule that allows a broad type-level read may not cover the export operation as you intend.

Restrict export requests by client and by scope, not only by network path. Decide which client applications may request system-wide, group or patient-level exports, and which should be denied. Test each rule with real requests from every client type, then confirm that a second client cannot poll for or download another client's job output using a guessed or reused job identifier. Where the version in use cannot tie output to the requester, plan a compensating control: a short retention window for output, an exclusion of export from non-administrative clients, or a gateway policy that limits export endpoints. Verify the retention and deletion behavior with a test job, because the operator, not the server, usually owns cleanup of files left on storage. Treat anything you cannot confirm from documentation as an open item in the design, not as an assumption.

Questions teams ask before securing Binary and export files

What does securing Binary and export files cost, and what drives the effort?

The cost is set by the number of file types, the number of access rules, and how many storage locations and export paths must be covered. Each Binary resource that carries a security context needs its rule defined and tested, and each bulk export job needs its output location and access checks handled. Work typically splits into design of the access model, server configuration, storage hardening, and testing. A quote should list each of these as separate line items so you can see what is one-time work and what recurs. Ongoing costs usually come from retesting after upgrades and from reviewing rules as document types change. Ask for the written scope before work starts, since DeployOpen agrees scope, deliverables and timelines in writing for most engagements.

How long does a scoped project take?

Duration depends mainly on how many file types, Binary resource categories and export patterns the project covers, and on how many rules each one needs. A narrow scope with one document type and one export destination takes far less time than a scope covering clinical images, scanned forms and several bulk export consumers. Storage access, identity integration and environment approvals also add time when they sit outside the project team's control. DeployOpen does not publish fixed durations, so the timeline comes from the written scope. Ask for milestones tied to specific file types and export jobs so progress is visible.

What must our team provide before the work starts?

Three inputs shape almost every engagement. First, a data inventory listing which Binary resources exist, what they contain, and which users and systems need to read them. Second, a working identity provider with the claims or groups that the access rules will use. Third, storage access for the platform, including the bucket or volume layout, encryption settings and credentials the server will use. Without these, the rules cannot be written against real data and the storage review has nothing to test. Also provide the HAPI FHIR version and deployment method so the configuration matches your environment.

Can our internal team secure Binary and export files on its own?

A team with HAPI FHIR server experience, familiarity with its authorization interceptors, and access to storage administration can often do the work internally, especially for a small number of file types. The harder parts are usually writing rules that match real request patterns without blocking legitimate reads, and reviewing storage protections with someone who has not built the setup. Teams that build internally should plan for an independent review and retest before go-live. Confirm the exact interceptor and configuration behavior against the HAPI FHIR documentation for your version, since capabilities can change between releases.

How are retesting and audit evidence handled?

Retesting covers each Binary resource type and export job in scope, run against the same rules and storage settings that go into production. After a HAPI FHIR upgrade, a configuration change or a new file type, the affected tests run again. Evidence typically includes the access rule set, test cases with expected and actual results, storage configuration records, and export job logs showing who requested an export and where the output was written. DeployOpen prepares these systems, controls and evidence for compliance assessments, but it does not issue audit reports or certifications. Independent auditors and certification bodies make those determinations, so confirm with your assessor which evidence format they expect before testing begins.

Which risks should we plan for when files and exports leave the server?

The main risks are a Binary read that bypasses the rules applied to other resources, an export file stored where too many people can read it, and an export job that a user can start for data they should not receive. Each risk maps to a check: confirm that Binary access rules apply to every read path, restrict the storage location and its permissions, and confirm who can start and retrieve export jobs. Storage risks also include unencrypted volumes and over-broad service credentials. Review these with the people who own the storage platform, since their settings often decide whether the server rules hold.

Does DeployOpen work inside our own infrastructure?

Yes. DeployOpen plans, implements, hardens and documents self-hosted open-source platforms inside the client's own cloud accounts, data centers or air-gapped networks. The Binary and export work runs against your HAPI FHIR server, your identity provider and your storage, so the files and exports stay under your control. Confirm during scoping which environments, accounts and access levels the team will need, and how credentials will be issued and removed at the end of the engagement.

Limits to confirm in your environment before going live

Binary access and bulk export files sit at the edge of what a HAPI FHIR server controls directly. The checks below cover the version, storage, identity, network path and retention questions that decide whether the controls you designed actually hold in production. Confirm each one against the vendor documentation and your own environment before go-live.

Confirm the HAPI FHIR version

Check that the HAPI FHIR release you run documents the Binary security context and bulk export behavior you plan to rely on. Behavior can change between releases, so read the release notes for the exact version rather than assuming the current docs apply. Note the JDK requirement of your target version as well, since the upgrade path can change the runtime you must support. Re-test the Binary and export rules after every upgrade.

Required for 8.2.0
JDK 17
HAPI FHIR versions

Verify storage and export encryption

Ask whether the database, the Binary storage location and the export output location each encrypt data at rest, and who holds the keys. Export files often land in a different location from the database, so a control applied only to the database leaves the files exposed. Confirm encryption in transit between the server and that storage, and confirm that backups and snapshots of the export location carry the same protections.

Check client context from the identity provider

Confirm how your identity provider passes the user and client identity into the HAPI FHIR request, such as through a validated bearer token whose claims feed an AuthorizationInterceptor rule. If the token does not carry the patient or scope information your Binary rules need, those rules will either fail closed or be bypassed. Test with a real token from each client type that reaches Binary or export endpoints.

Block direct paths through the proxy

Check whether your reverse proxy, API gateway or ingress forwards Binary and bulk export paths directly to clients or to storage URLs. A rule that protects the FHIR endpoint does not protect a file path that a proxy serves on its own. Confirm that only the intended routes are exposed, that export files are not published as static content, and that the proxy does not cache protected responses.

Set export file retention

Decide how long exported files stay on disk or in object storage, who can delete them, and whether deletion is logged. Export output can contain a full population of records, so leftover files widen the exposure long after the job finishes. Ask your team to define retention in writing, confirm that the server and storage cleanup actually removes files on that schedule, and test that a deleted file is no longer retrievable through any Binary path.

How a Binary or export request passes the access checks

A request for a Binary resource or an exported file starts at the client and enters through the reverse proxy, which forwards it to the HAPI FHIR server. The AuthorizationInterceptor decides whether the caller may perform the operation before the server reads anything, and the Binary.securityContext reference is then checked against the caller's permissions. Only after both checks does the server fetch the data from the database or file storage, and every access should leave an audit record. Check that storage sits inside its own trust boundary and that no path reaches the files without passing the server.

Each Binary or export read passes the server's access checks before storage is touched.

How DeployOpen scopes and delivers Binary and export protection

DeployOpen plans, builds, tests and documents access controls for Binary resources and bulk export files on a self-hosted HAPI FHIR server in infrastructure you control. Work follows a written, fixed scope that covers the Binary access rules, export job settings, storage protections and the evidence your security and compliance teams need to review.

How we scope

  • We inventory which Binary resources, document types and export files hold patient data and who needs them.
  • We map each Binary and export path to its access rule, storage location and audit requirement in the written scope.
  • We confirm the identity provider, authorization approach and storage platform with your team before any build starts.

How we build

  • We configure Binary.securityContext handling and test it against read, search and vread requests from each role.
  • We set export job access, output location and file retention, then validate that exported files follow the same rules.
  • We apply storage-level controls such as encryption, restricted bucket or volume access and separate credentials for the export path.

How we hand over

  • We deliver test cases, request traces and configuration records showing which callers can read which Binary and export files.
  • We document the operating procedures for adding document types, rotating storage credentials and clearing old export files.
  • We walk your security and compliance reviewers through the evidence so they can assess the controls independently.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers after the initial handover.
  • Retesting after HAPI FHIR upgrades or identity provider changes can be included in the written scope.
  • Support covers fixes to rules and storage settings that your team identifies during routine operation.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.