Most HIPAA programmes are built around policies, risk assessments and vendor contracts. The application code gets one line: "we encrypt data at rest and in transit". Yet a lot of protected health information (PHI) escapes through ordinary code paths that nobody thinks of as disclosures: a debug log, an error response, an analytics event, a URL, a cached page.
This post walks through those paths with examples, and maps each one to the HIPAA Security Rule safeguard it touches. It is written for engineers, it is general, and it is not legal advice: whether a given flow is a permitted disclosure is a question for your privacy officer and counsel.
A quick map of the rules that reach code
The HIPAA Security Rule in 45 CFR Part 164, Subpart C, covers electronic PHI (ePHI). The technical safeguards in 164.312 are the ones engineers touch most:
| Section | Safeguard | In code terms |
|---|---|---|
| 164.312(a)(1) | Access control | Every route that returns PHI checks who is asking |
| 164.312(b) | Audit controls | Access to PHI is recorded and can be examined |
| 164.312(c)(1) | Integrity | PHI cannot be altered or destroyed improperly |
| 164.312(d) | Person or entity authentication | You know who the caller is |
| 164.312(e)(1) | Transmission security | PHI is protected on the network |
Some implementation specifications are "required" (unique user identification, emergency access) and some are "addressable", including encryption at rest and in transit. Addressable does not mean optional: you implement it, or document why an equivalent measure is reasonable.
Two Privacy Rule ideas also matter in code. The minimum necessary standard (164.502(b)) says use or disclose only the PHI a purpose needs. And the de-identification safe harbor in 164.514(b) lists identifiers that make data identifiable, including names, email addresses, medical record numbers, device identifiers, URLs and IP addresses. A log line with a patient email and a diagnosis code is PHI, even if it never touches your database.
Where PHI leaks
1. Application logs
The most common one. A developer logs the whole object while debugging, and the log pipeline ships it to a third-party log service, a support tool and a long-retention bucket.
# Leaks: the whole patient record, diagnosis included, goes to the log pipeline
logger.info(f"updated patient {patient}")# Fixed: log an internal identifier and the action, not the record
logger.info("patient updated", extra={"patient_id": patient.id, "actor": user.id})Logs touch access control (who can read the log store), transmission security (where logs are shipped) and minimum necessary. Note the difference between debug logs and audit logs: 164.312(b) asks you to record activity on systems with ePHI, and an audit trail of who accessed which record is a safeguard, not a leak, as long as the audit store itself is protected.
2. Error messages
An unhandled exception that returns the stack trace, the failing SQL or the request body to the client can echo PHI back to whoever triggered it, including someone probing your API.
// Leaks: the error message can contain the query and the values in it
app.use((err, req, res, next) => {
res.status(500).json({ error: err.message, stack: err.stack });
});// Fixed: a generic response for the client, the detail in the protected server log
app.use((err, req, res, next) => {
logger.error({ err, requestId: req.id });
res.status(500).json({ error: "internal error", requestId: req.id });
});3. Analytics, tracking and session replay
Analytics SDKs, ad pixels and session replay tools capture page titles, URLs, form fields and custom events. On a patient portal, an event called appointment_booked with a property specialty: "oncology" sends health information to a vendor.
HHS OCR issued guidance on online tracking technologies in December 2022 and revised it in March 2024. In June 2024 a federal court vacated part of it, the part about tracking on unauthenticated public web pages. Tracking inside authenticated areas such as patient portals was not that part. In practice, disclosing PHI to a vendor needs a permitted purpose and, for a vendor working on your behalf, a business associate agreement (164.502(e)). Check whether your vendor offers one before anything else.
In code, that means: no analytics or replay on authenticated PHI pages unless the vendor is a business associate, and no PHI in event names, properties or page titles anywhere.
4. URLs and query strings
A URL like /results?mrn=448210&test=HIV ends up in web server and proxy logs, browser history, the Referer header sent to third-party scripts, and the analytics tool from point 3. URLs are on the safe harbor identifier list for a reason.
Keep identifiers and clinical terms out of paths and query strings. Use opaque identifiers in paths and send search criteria in a POST body. Set Referrer-Policy: no-referrer or same-origin on PHI pages.
5. Caches
An authenticated response with PHI and no cache headers can be stored by a browser, a shared proxy or a CDN that was configured to cache "everything under /api". The next caller can get someone else's record.
Cache-Control: no-storeSend it on every response that carries PHI, and check CDN rules so authenticated routes bypass the cache. Server-side caches need the same care: a cache key that leaves out the user or tenant serves one patient's data to another, which is an access control failure (164.312(a)(1)).
6. Prompts sent to a model
Support tools and clinical note features that send patient context to a hosted model API are a newer path. Unless that provider is a business associate under an agreement that covers the use, this is a disclosure like any other. Send the minimum, and strip identifiers you do not need.
Finding these paths in code
Vulkro has a hipaa profile that maps findings to the Security Rule safeguards a code scan can give evidence for, mostly the technical safeguards in 164.312:
vulkro compliance . --profile hipaa
vulkro report . --profile hipaa -o hipaa-report.html
vulkro compliance-pack . --framework hipaa -o hipaa-evidence/The privacy check classifies health fields such as mrn and diagnosis in request and response shapes, which is how the profile knows which endpoints touch PHI. Typical failures it reports are PHI endpoints with no detectable authentication, admin endpoints with no role check, PHI over plain HTTP, PHI responses without Cache-Control: no-store, and PHI access paths with no audit logging. Rule LLM06:2025 flags PII or PHI that flows into a model prompt. Automatic logoff is listed as informational, because a code scan cannot detect it, and a control with no mapped findings shows as not evaluated rather than passing.
FAQ
Is PHI in application logs a HIPAA violation?
Not automatically, but it is a common source of impermissible disclosure. Logs with PHI must be protected like any ePHI store, and shipping them to a vendor that is not a business associate is a disclosure. The simplest fix is to log identifiers and actions, not records.
Can we use analytics on a patient portal under HIPAA?
Only if the analytics vendor receives no PHI, or is a business associate with an agreement in place. HHS OCR guidance treats tracking on authenticated pages as likely to involve PHI. Check with your privacy officer before adding any third-party script to a portal.
Which HIPAA safeguards apply to developers?
Mainly the technical safeguards in 45 CFR 164.312: access control, audit controls, integrity, person or entity authentication and transmission security. The minimum necessary standard also shapes what code should log, send and return.
See the HIPAA reference and the compliance evidence use case, or start a 14-day trial. Related: what auditors accept from a scanner and OWASP API and LLM Top 10 in one codebase.