Security

PHI handling

What ulex stores, what counts as PHI in an identity system, the pseudonymisation rules, exactly which fields are safe and which are not, how to configure a tenant for a regulated workload, and the mistakes that turn identity data into PHI.

PHI is individually identifiable health information. The part people get wrong in an identity system is that "identifiers" do not have to be health-related to count.

#The 18 identifiers

Under 45 CFR 164.514(b)(2), any of these, alone or in combination, makes data PHI:

Names; geographic subdivisions smaller than a state; all elements of dates except year directly related to an individual; phone numbers; fax numbers; email addresses; SSN; medical record numbers; health plan beneficiary numbers; account numbers; certificate or licence numbers; vehicle identifiers; device identifiers and serial numbers; web URLs; IP addresses; biometric identifiers; full-face photographs; any other unique identifying number or characteristic.

Warning

An email address is on that list. dana.okafor@acme.example is PHI if it is on a claim, a referral, or a record linked to a service. So is an IP address, and so is a user_agent string that correlates to a person across sites. The HIPAA Safe Harbor de-identification method is about removing all 18, not about the field names.

#What ulex stores, classified

#Not PHI on its own

FieldWhy
user.first_name, last_name, display_namename. PHI only when linked to a service
user.job_title, departmentoccupational, not health
user.metadataarbitrary; you decide what goes in it
user.external_idan opaque IdP id. Could be anything, including a medical record number
group.name, slug, scim_idorganisational
application, organization configurationnot personal

#Potentially PHI

FieldTreatment
user.emailstored, lowercased and trimmed. Pseudonymised in every log and every audit metadata, never logged in cleartext, never in an export's actor field
mfa_factor.target_hintalready a SHA-256 of the phone number or address. Not PHI even though the source was
ip_hashalready a salted SHA-256. The raw IP is never stored
actor_hashalready a salted SHA-256 of the email. The email itself is never in the audit log
user_agenttruncated to 512 characters, stored on auth_attempt and audit_event
user.scim.timezone, localelocation-adjacent, not location
user.metadataif you put a patient reference in there, it is PHI. ulex will not stop you; it will scrub it from logs

#The pseudonymisation rules

ulex applies three transformations. They are not optional and they are not configurable, because a configurable privacy control is one somebody will turn off.

#1. Logs: replace the identifier, keep the correlation

text
dana.okafor@acme.example   →  [EMAIL_3b1f0c9a7d2e]
203.0.113.42               →  [IP_9c2e4a6b8d0f]
ts
export function scrub(input: string): string {
  return input
    .replace(/[\w.+-]+@[\w-]+\.[\w.-]+\.[a-z]{2,}/gi, (m) => `[EMAIL_${sha256Prefix(m)}]`)
    .replace(/\b(?:\d{1,3}\.){3}\d{1,3}\b/g, (m) => `[IP_${sha256Prefix(m)}]`)
    .replace(/\b(?:[0-9a-fA-F]{1,4}:){2,7}[0-9a-fA-F]{1,4}\b/g, (m) => `[IP_${sha256Prefix(m)}]`);
}

The pseudonym is stable within a tenant, so you can still ask "all the events for this user". It is not correlatable across tenants, because the salt is per tenant.

#2. The audit log: never store the identifier at all

json
{
  "id": "aud_01M3PSVN7R3H0ECRPQVTDF1PY9",
  "action": "authentication.succeeded",
  "actor_id": null,
  "actor_hash": "sha256:3b1f0c9a7d2e4f6a8b0c2d4e6f8a0b2c4d6e8f0a2b4c6d8e0f2a4b6c8d0e2f4a",
  "actor_type": "user",
  "actor_display": "Dana Okafor",
  "ip_hash": "sha256:9c2e4a6b8d0f2a4c6e8b0d2f4a6c8e0b2d4f6a8c0e2b4d6f8a0c2e4b6d8f0a2c"
}

actor_display is a display name, not an email. The email is hashed. This is a stronger position than pseudonymisation: the email is not in the security record at all, so compromising the audit log does not become a contact list.

#3. The data you hold: only what authentication needs

FieldNeeded to authenticate?Kept
emailyes — it is the subject identifieryes
first_name / last_namenoyes, because a UI needs them. Flag it in your DPIA
job_title / departmentnoyes. Consider not sending it for a workforce tenant
phonenonever stored. SHA-256 only, and only if an MFA factor is enrolled
addressnonever stored. SCIM addresses is accepted and discarded
date of birthnonot in the schema. SCIM birthDate is rejected
medical record numbernonot in the schema
diagnosis, treatment, providernonot in the schema
external_idyes — the JIT join keyyes. Audit it: an IdP that puts an MRN in sub puts an MRN in your tenant
Warning

external_id is the field to watch. ulex maps the upstream sub or oid to it, and it is the join key across syncs. Some identity providers do put a domain-specific identifier there. Do not use a clinical or claims system as an upstream IdP, and if an IdP offers to send a patient reference as sub, decline it and use an opaque id.

#What is accepted and discarded

SCIM attributeulex's action
emails[]stored. The primary: true value becomes user.email
phoneNumbers[]discarded. Hashed into mfa_factor.target_hint only if a factor is enrolled
addresses[]discarded
imgs[], photos[]discarded
birthDaterejected — 400 invalidValue. Not in the User schema
roles[]stored under user.metadata.roles
entitlements[]stored under user.metadata.entitlements
urn:…:enterprise:2.0:Useraccepted and stored under user.metadata.enterprise. This is where employeeNumber, manager and costCenter go. Do not put clinical data in it
x509Certificatesdiscarded

Discarded means the value is accepted so the IdP's call succeeds, and is not written anywhere. A GET /users/{id} will not return it. An export will not contain it.

#Webhook payloads

The same rules apply to what ulex sends you.

json
{
  "event": "dsync.user.updated",
  "event_id": "evt_01M3PSW3WGDDFJFJHZ4QJNNFZD",
  "data": {
    "user": {
      "id": "usr_01M3PSWBPGS08FWV4NV7P9VNFN",
      "email": "pat@acme.example",
      "first_name": "Pat",
      "last_name": "Iyer",
      "status": "active"
    },
    "previous_attributes": { "department": "Customer Success" }
  }
}
  • phoneNumbers, addresses, photos are never in a webhook payload. There is no previous_phone and there never will be.
  • user.metadata is in the payload if it is set. If you put PHI in metadata, you are sending PHI to every endpoint you registered. Treat metadata as a broadcast channel.
  • The body is signed, so it is authentic and tamper-evident, and it is not encrypted. TLS is the confidentiality control.

#Configuring a tenant for a regulated workload

1
1. Pin the region
bash
curl -sS "$BASE/me" -H "$AUTH" | jq -r .tenant.region

A tenant's region is fixed at creation. There is no move. If your patients are in the EU, create the tenant in eu-west-1.

2
2. Set the retention floor
bash
curl -sS -X PATCH "$BASE/tenants/current" -H "$ADMIN" -H "$JSON" \
  -d '{"hipaa_enabled": true, "hipaa_baa_reference": "baa-2026-0114", "retention": {"audit_log_days": 2555, "session_days": 30}}'

audit_log_days cannot go below 365 and cannot be null. With hipaa_enabled: true the floor is 2,555, and the flag itself is refused without a hipaa_baa_reference — the BAA is a precondition, not paperwork to follow up on.

3
3. Do not use simulator endpoints in `prod`
bash
curl -sS "$BASE/tenants/current" -H "$ADMIN" | jq '{allow_mocks, hipaa_enabled, environment: .environment}'
json
{ "allow_mocks": false, "hipaa_enabled": true, "environment": "prod" }

allow_mocks: false in prod means no impersonation_only, no ulex_mint_access_token, no /simulator/authenticate. A tenant that runs real identities for a covered entity should have this off, and the change is audited.

4
4. Require phishing-resistant MFA for your highest-risk routes
json
{ "mfa": { "mode": "required", "methods": ["webauthn"], "remember_device_days": 0 } }

Then in your application, require acr === "urn:ulex:acr:phishing-resistant" on the routes that touch a chart.

5
5. Verify the chain before every access review
bash
curl -sS -G "$BASE/audit-events/export" -H "$ADMIN" -H "Accept: application/x-ndjson" \
  --data-urlencode 'format=ndjson' --data-urlencode 'since=2025-01-01T00:00:00.000Z' \
  --data-urlencode 'until=2026-01-01T00:00:00.000Z' -o audit.ndjson

#Mistakes that turn identity data into PHI

MistakeResultFix
Using an email that embeds an MRN, e.g. mrn-4417@clinic.examplethe tenant holds PHIuse a non-clinical address for staff, or the clinical address only if the tenant is covered by the BAA
An IdP that puts the MRN in subuser.external_id is PHIdemand an opaque sub, or use oid on Entra
Putting a diagnosis in user.metadataPHI broadcast to every webhook endpoint and to every log line's neighbourhoodmetadata is for identifiers and flags, not clinical data
Treating a user_agent as harmlessit is an identifier under 164.514(b)(2)it is stored, truncated, and never exported; do not log it yourself
Exporting user.email into a spreadsheet as a "user id"a second copy outside the BAAexport the usr_… id and resolve the email at read time
Using a non-BAA tenant for a real clinical identityno BAA coveragenever
allow_mocks: true on a clinical workloadan API key can log in as any user (and HIPAA tenants forbid allow_mocks: true)leave it off and enable hipaa_enabled: true
Reading a user's email into your own application logsa second PHI store you did not assessuse sub, and look the email up when you render a screen

#What your application must do

ulex's controls stop at the token. After that it is your system.

Warning

ulex's audit log records who authenticated. The HIPAA audit requirement is about who accessed what. Those are different questions and only your application can answer the second one.

ts
// Required: your own data-access log, keyed to the ulex sub.
app.get("/api/patients/:id/chart", requirePhishingResistant, async (req, res) => {
  const claims = await verifyAccessToken(req.headers.authorization);
  const chart = await db.chart(req.params.id);

  await audit.write({
    at: new Date().toISOString(),
    actor_sub: claims.sub!,          // the ulex usr_… id. This is the join key
    actor_acr: claims.acr,
    session_id: claims.sid,
    org_id: claims.orgId,
    action: "chart.read",
    target: { type: "chart", id: req.params.id, patient_ref: "REDACTED" },
    request_id: req.headers["x-ulex-request-id"],
    outcome: "success",
  });

  res.json(chart);
});
RuleWhy
Log sub, not the emailthe email is the identifier; sub is the pseudonym
Log the action and the target"who read what" needs both
Never log the target's contentsthe log becomes a second PHI store
Retain for 6 years, or your state's longer ruleHIPAA has no explicit retention period for access logs; state law does
Log denials tooan attempted access is an access event
Write to storage you controla vendor's log is a vendor's PHI copy

#Reference