Securing Medplum Binary files with securityContext

Medplum Binary resources can fall back to project-level access unless they carry a securityContext. This page explains the exposure, how to link files to a Patient, and how to check existing binaries.

On this page

Securing Medplum Binary files with securityContext: why uploaded files need their own access rules

A Medplum Binary resource without a securityContext falls back to project-level access, so any authenticated user with Binary permissions who knows the UUID could read it. That is the core exposure: a file can be restricted by the policies on the Patient or care team it belongs to only if the Binary is explicitly linked to that resource. Teams that store patient documents, scanned intake forms, referral letters, or imaging attachments in Medplum need this link in place from the first upload, because a file stored without it sits outside the compartment rules that protect the rest of the record.

The fix described in the Medplum docs is to set the Binary's securityContext to a reference to the resource that owns it, such as a Patient. The Binary then inherits the permissions of that referenced resource, so a user who can see the Patient can see the file and a user who cannot see the Patient cannot. Before go-live, confirm with your own Medplum version how uploads are created in your application, whether every upload path (web app, Bots, integrations and the Agent) sets the field, and whether a non-patient owner such as an Encounter or DiagnosticReport is the right anchor for your data. Then test with a user outside the care team who knows a file's UUID and confirm the read is refused.

How a Binary request is evaluated with and without securityContext

The request starts with an authenticated user asking for a Binary by its UUID. Without a securityContext, Medplum checks the user's project-level Binary permissions, so anyone with those permissions who knows the UUID can read the file. With a securityContext, the check follows the permissions of the referenced Patient or DocumentReference instead, which is the trust boundary to verify for every stored file.

Binary reads with and without a securityContext reference, with the trust boundary marked.

Which linking pattern fits each kind of file

This table compares the ways a Binary can be attached to access control in Medplum, from a securityContext that points to a Patient to project-level storage for non-patient files. Read each row against the kind of file you are storing, and check the access it grants and the step that must happen before the file is usable.

PatternWhen it fitsAccess it grantsMain trade-off
securityContext pointing to a PatientPatient photos, scanned intake forms or outside records that belong to one personUsers who can read that Patient's compartment can read the fileThe Patient must exist first, and the file needs a reference to it before it is usable
securityContext pointing to a DocumentReferenceClinical documents such as discharge summaries or lab reports that need their own metadata and statusUsers who can read the DocumentReference can read the fileSomeone must create the DocumentReference in the same workflow, so uploads without one stay unlinked
securityContext pointing to another clinical resourceFiles tied to an encounter, order or observation, such as a device image attached to a resultInherits the permissions of the referenced resourceAccess depends on that resource's policy, so review the policy before relying on it
Project-level Binary with no securityContextNon-patient content such as letterhead, form templates, logos or fixed imagesAny authenticated user with Binary permissions who knows the UUID can read itMust never hold patient data, and the UUID should be treated as reachable by anyone with Binary access
Binary left unlinked after uploadAlmost no legitimate case; often a result of a failed or partial workflowFalls back to project-level accessHides exposure, so search for existing unlinked binaries as part of your review

How to link a Binary to a Patient with securityContext

This sequence ties a stored file to the Patient it belongs to, so that the Binary inherits that Patient's access rules instead of relying on project-wide permissions. The result is a file that only users allowed to see the Patient can retrieve, and a test record showing that the link holds.

  1. Inventory existing Binary resources

    Before changing anything, list the Binary resources already in the project and note which ones have no securityContext set. Someone with access to the project should run a search for Binary resources and record each resource's ID, its content type and any reference to a patient or clinical resource in the surrounding data. Flag any file that clearly belongs to a patient but has no link. The step is complete when you have a written list that separates linked files from unlinked ones, and you know which unlinked files need an owner before they are updated.

  2. Identify the owning Patient or resource

    For each Binary that needs protection, find the Patient or other resource that owns the file, such as the Patient for a scanned consent form or an Observation for an attached report. Confirm the correct resource with the team that produced the file, because linking to the wrong Patient gives the file the wrong access rules. Record the resource type and ID. The step is complete when every file on your list has one confirmed owning resource, and any file without a clear owner is held back for review rather than linked by guess.

  3. Create or select the Binary

    For new files, upload the content as a Binary resource so it gets its own ID. For existing files, select the Binary resource already identified in the inventory. Keep the Binary's content unchanged during this step, since the task is to change access metadata only. Note the Binary's ID, because the next step needs it and the final test will request the file by that UUID. The step is complete when the Binary exists in the project and you have its ID written next to the owning resource ID.

  4. Set the securityContext reference

    On the Binary, set its securityContext to a reference pointing at the owning resource, using the field and reference format shown in the Medplum Binary security context documentation. Save the change with a user who has permission to update Binary resources. Read the Binary back and confirm that the securityContext reference is present and points to the intended Patient or resource. The step is complete when the saved Binary shows the correct reference, and the change is recorded in the audit history for the project.

  5. Test access with a user in the patient's scope

    Sign in as a user who is allowed to see the linked Patient, using the access policy or compartment rules that apply to that user. Request the Binary by its UUID and confirm that the file returns as expected. This check shows that the securityContext does not block legitimate access. The step is complete when the authorized user reads the file successfully and the result matches the content you uploaded.

  6. Test access with a user outside the patient's scope

    Sign in as a user who has Binary permissions but no access to the linked Patient, such as a user assigned to a different patient compartment or tenant. Request the same Binary by UUID. The request should be refused. If the file returns, the securityContext is not being enforced for that user, so stop, check the reference and the user's access policy, and repeat the test before continuing. The step is complete when the unauthorized user cannot retrieve the file.

  7. Document the link and repeat for each file

    Record each Binary ID, owning resource, test user and test result in the project's change log or security records, so that reviewers can see which files are linked and how the link was verified. Repeat the link and test steps for every file on the inventory list, and keep the unlinked files marked as open items until they have an owner. Confirm with the security or compliance lead which records they expect to see as evidence. The step is complete when every file on the list has a documented link and a passing test, or an open item with a named owner.

How to check existing Binaries for missing securityContext

Start the audit by inventorying every Binary resource in the project, then isolate the ones with no securityContext set. Binary resources are not covered by compartment policies in the way patient data is, so a file created before anyone set a context can sit at project-level access without anyone noticing. Run a search across the Binary resource type and record each result's ID, creation date, content type and the user or Bot that created it. Keep the output in a file you can sort and filter, because that file becomes the working list for every decision that follows. Confirm the exact search parameters and paging behavior against the current Medplum documentation and your server version before you rely on the results, since a search that silently truncates at a page limit will give you an incomplete inventory.

For each unlinked Binary, find the patient or other record it belongs to. Look for references from clinical resources such as DocumentReference, DiagnosticReport, Media or Communication, and from any custom resource your application uses to hold attachments. Each file then falls into one of three outcomes: link it to its owning resource and set securityContext so it inherits that resource's permissions, restrict it because no owner can be identified and access should be limited to a small administrative group, or delete it after confirming it is orphaned, a duplicate or a temporary upload that was never cleaned up. Record the decision and the reviewer for each file, because deletion and relinking both change what auditors and clinicians can later find. Mark any file whose owner is ambiguous for clinical review rather than guessing.

Review who holds Binary permissions before you touch the files, because the audit is only as strong as the accounts that can still read them. List the access policies and project memberships that grant Binary access, and remove any grant that does not match a current job. A broad grant that remains in place will expose newly uploaded files again, even after the historical backlog is cleaned up. For a project with a large number of Binaries, plan a scripted or batched review that pages through search results, writes its output to a log and applies changes in small groups with a verification read after each batch. Size the effort against your own data volume and a test run on a copy or staging project, and ask any partner quoting this work to show how the script handles paging, retries and rollback.

Security and operational risks when securityContext is missing

A Binary without a securityContext is governed by project-level access rather than by the record it belongs to. The cards below cover the risks that follow from that gap and the control to apply to each, so the team can check exposure before and after changing binary handling.

UUID exposure to any Binary reader

A Binary without a securityContext falls back to project-level access, so any authenticated user with Binary permissions who knows the UUID can read it. UUIDs often appear in logs, URLs, exports and support tickets, so treat them as sensitive. Control: list every Binary in the project, confirm each one has a securityContext, and restrict Binary read permissions to the roles that truly need file access.

Binary security docs

Over-broad project roles

Project-level roles that grant Binary read access to every clinical or administrative user expose unlinked files well beyond the patients those files describe. A role built for chart review may inherit file access it never needed. Control: review the access policies attached to each role, remove blanket Binary permissions, and test each role with a sample user before go-live.

Unlinked uploads from integrations and Bots

Interfaces, Bots and client applications can create Binary resources such as scanned documents, lab PDFs or images without linking them to a Patient or Encounter. Those files then sit under project-level rules with no clinical context. Control: require the upload path to set securityContext to the owning resource, and monitor for Binary creations that lack it.

Backups and exports carrying unlinked files

Database backups, bulk exports and warehouse syncs copy Binary metadata along with the records they came from. An unlinked file that was restricted in production may be readable in a restored or exported copy under looser rules. Control: include Binary linkage in restore tests and export reviews, and confirm that a restored environment applies the same access policies as production.

Audit trails for file reads

When a regulator, auditor or internal review asks who opened a specific file, the team needs read events tied to the Binary and the user. Without a securityContext, the access decision is harder to explain because it depends on project rules rather than on the patient record. Control: confirm that audit events for Binary reads are retained, that they identify the requesting user, and that a sample query can answer the question for one named file.

Revoking access after a role change

When a clinician changes teams or leaves, their access to linked files should change with the compartment or patient record they lost. Unlinked files keep following the project role, so a removed role may still reach them until the policy is edited. Control: after each role change, test a sample of previously accessible binaries with the affected user, and document the result.

Binary securityContext questions buyers ask before hiring help

What drives the cost of checking Binary securityContext in Medplum?

The cost follows the size of the review, not a fixed package. The main drivers are the number of existing Binary resources, the number of resource types that reference them, and how many integrations write files into Medplum. Each Binary needs its referencing resource traced, and each referencing type needs its access policy checked. A review that covers one project with a few file types is much smaller than one covering several projects, Bots that upload files and external systems that pull attachments. Ask any provider for a quote that lists the inventory step, the fix step and the retest step separately, and states which items are one-time work and which need ongoing review as new files arrive.

How long does a Binary securityContext audit take on a large dataset?

Duration depends mainly on data volume and on how cleanly files are linked today. A project with a small number of binaries that already point at a Patient or other resource can be reviewed quickly. A project with years of uploads, many unlinked files and several writing integrations takes longer, because each Binary has to be matched to an owner and each link has to be tested. No duration is fixed in advance. Ask for a timeline in the written scope that states the expected Binary count, how it was measured and which steps depend on data owners answering questions.

What does our team need to provide for a Binary security review?

Three things make the work faster and safer. First, test users with the same roles your production users hold, so access can be checked as each role really sees it. Second, a staging project that mirrors production, where fixes and retests run before any change reaches live data. Third, named data owners for each resource type who can confirm which Patient or other record a file belongs to and who should see it. Without data owners, the reviewer can detect that a Binary is unlinked but cannot decide whether it should be deleted, relinked or kept.

Can one internal engineer check Binary securityContext alone?

Yes, a capable Medplum engineer can do the work alone if they have admin access to the project, a staging copy and time to review the data with the people who own each record type. The technical steps are not large: list Binary resources, check whether each has a securityContext, trace the referencing resource, and test access with a non-admin user. The harder part is the judgment about which files belong to which patient and which access policies must change, and that usually needs more than one person. Plan for a second reviewer who did not write the upload code, and record each decision so the result can be explained to an auditor later.

When is it worth hiring a partner for Medplum file access controls?

A partner is most useful when the file count is high, several integrations or Bots write files, or the organization must show evidence to a compliance team on a fixed schedule. It is also useful when the internal team lacks time to build a repeatable check that can run again after each release. DeployOpen plans, implements, hardens and documents self-hosted platforms in the client's own infrastructure, and runs security testing that includes access control checks. DeployOpen does not issue audit reports or certifications. Independent auditors do that work, and the written scope should say which evidence DeployOpen prepares for them.

What evidence should we keep after fixing Binary securityContext?

Keep a before and after inventory that shows how many Binary resources existed, how many had a securityContext, and how many were linked, fixed or removed. Record the access policy used for each resource type, the test user roles, and the retest results. Store the decision log that says who approved each relink or deletion. Compliance reviewers usually ask how the organization knows the control works over time, so note the check schedule too. Confirm with your compliance lead which format they accept before the work starts.

Will fixing binaries break existing integrations or apps?

It can, which is why the review needs a staging project and a list of every writer and reader. Changing a Binary's securityContext or linking it to a resource changes who can read it, so an app that relied on broad project-level access may start receiving denied responses. Before changes reach production, identify each integration that uploads or downloads files, confirm the user or Bot it runs as has permission on the linked resource, and test the full read path. Schedule the change so that integration owners can respond if a call fails.

Does a Medplum version upgrade change how Binary access works?

Confirm this against the release notes for your target version before assuming either way. Medplum publishes releases on its GitHub releases page and an upgrade guide for self-hosted servers, and the upgrade guide notes that minor versions must be applied in sequence. Plan to re-test Binary access after any upgrade, whether or not the release notes mention it, because a changed access path would otherwise go unnoticed until a user reports a problem.

How DeployOpen scopes and delivers Medplum binary security reviews

DeployOpen plans and delivers the review of Binary resources in a self-hosted Medplum deployment, starting from the inventory of stored files and their links to clinical records. The work covers how securityContext is set, how existing binaries are checked, and how the result is documented for your security and compliance teams.

How we scope

  • Engagements are fixed-scope, with the Binary inventory, projects and resource types agreed in writing before work starts.
  • The written scope names which Binary-bearing workflows, such as uploads tied to Patient or Observation records, are in review.
  • Ongoing checks after the initial review are available as a retainer, scoped separately in writing.

How we build

  • We list existing Binary resources and record which ones lack a securityContext reference.
  • We set the securityContext on new and existing binaries so access follows the referenced resource's permissions.
  • We test access with users and Bots from each role to confirm that unlinked or out-of-scope files cannot be read.

How we hand over

  • You receive a written record of the binaries reviewed, the changes made and the tests run against them.
  • Documentation explains the linking pattern so your developers can apply it to future file uploads.
  • We walk your engineering and compliance staff through the evidence so they can repeat the checks themselves.

How we support

  • Support after handover covers questions on the linking pattern and retesting after Medplum upgrades.
  • Retesting is scheduled against your Medplum release and upgrade plan, which you confirm with us in writing.
  • Security findings from later reviews are handled under the same written scope and retainer terms.

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.