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.
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
| Field | Why |
|---|---|
user.first_name, last_name, display_name | name. PHI only when linked to a service |
user.job_title, department | occupational, not health |
user.metadata | arbitrary; you decide what goes in it |
user.external_id | an opaque IdP id. Could be anything, including a medical record number |
group.name, slug, scim_id | organisational |
application, organization configuration | not personal |
#Potentially PHI
| Field | Treatment |
|---|---|
user.email | stored, 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_hint | already a SHA-256 of the phone number or address. Not PHI even though the source was |
ip_hash | already a salted SHA-256. The raw IP is never stored |
actor_hash | already a salted SHA-256 of the email. The email itself is never in the audit log |
user_agent | truncated to 512 characters, stored on auth_attempt and audit_event |
user.scim.timezone, locale | location-adjacent, not location |
user.metadata | if 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
dana.okafor@acme.example → [EMAIL_3b1f0c9a7d2e]
203.0.113.42 → [IP_9c2e4a6b8d0f]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
{
"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
| Field | Needed to authenticate? | Kept |
|---|---|---|
email | yes — it is the subject identifier | yes |
first_name / last_name | no | yes, because a UI needs them. Flag it in your DPIA |
job_title / department | no | yes. Consider not sending it for a workforce tenant |
phone | no | never stored. SHA-256 only, and only if an MFA factor is enrolled |
| address | no | never stored. SCIM addresses is accepted and discarded |
| date of birth | no | not in the schema. SCIM birthDate is rejected |
| medical record number | no | not in the schema |
| diagnosis, treatment, provider | no | not in the schema |
external_id | yes — the JIT join key | yes. Audit it: an IdP that puts an MRN in sub puts an MRN in your tenant |
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 attribute | ulex'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 |
birthDate | rejected — 400 invalidValue. Not in the User schema |
roles[] | stored under user.metadata.roles |
entitlements[] | stored under user.metadata.entitlements |
urn:…:enterprise:2.0:User | accepted and stored under user.metadata.enterprise. This is where employeeNumber, manager and costCenter go. Do not put clinical data in it |
x509Certificates | discarded |
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.
{
"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,photosare never in a webhook payload. There is noprevious_phoneand there never will be.user.metadatais in the payload if it is set. If you put PHI inmetadata, you are sending PHI to every endpoint you registered. Treatmetadataas 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
curl -sS "$BASE/me" -H "$AUTH" | jq -r .tenant.regionA 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.
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.
curl -sS "$BASE/tenants/current" -H "$ADMIN" | jq '{allow_mocks, hipaa_enabled, environment: .environment}'{ "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.
{ "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.
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
| Mistake | Result | Fix |
|---|---|---|
Using an email that embeds an MRN, e.g. mrn-4417@clinic.example | the tenant holds PHI | use 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 sub | user.external_id is PHI | demand an opaque sub, or use oid on Entra |
Putting a diagnosis in user.metadata | PHI broadcast to every webhook endpoint and to every log line's neighbourhood | metadata is for identifiers and flags, not clinical data |
Treating a user_agent as harmless | it 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 BAA | export the usr_… id and resolve the email at read time |
| Using a non-BAA tenant for a real clinical identity | no BAA coverage | never |
allow_mocks: true on a clinical workload | an 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 logs | a second PHI store you did not assess | use 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.
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.
// 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);
});| Rule | Why |
|---|---|
Log sub, not the email | the email is the identifier; sub is the pseudonym |
| Log the action and the target | "who read what" needs both |
| Never log the target's contents | the log becomes a second PHI store |
| Retain for 6 years, or your state's longer rule | HIPAA has no explicit retention period for access logs; state law does |
| Log denials too | an attempted access is an access event |
| Write to storage you control | a vendor's log is a vendor's PHI copy |