Security

Authentication

How ulex authenticates callers and subjects: API key format and storage, OAuth 2.1 with mandatory PKCE, the hosted UI, SAML, device flow, token exchange, and the six rules that keep credentials out of logs.

ulex has two authentication problems, and conflating them is the most common integration mistake.

ProblemWhoCredential
Acting on the tenantyour agent, your CI, your serviceAPI key (ulex_sk_…)
Acting as a humanyour application's end useraccess token, minted from an OIDC or SAML login

An API key cannot call /oauth2/userinfo. An access token cannot call POST /applications. Pick the right one for the call.

#API keys

#Format

text
ulex_sk_live_<32 chars>     hosted tenant API key (recommended)
ulex_sk_test_<32 chars>     sandbox/test prefix
ulex_sk_<32 chars>          generic prefix

Example: ulex_sk_live_7Qm2KpLx9Tb4Ns8RfWy3Zc1Hjf6Ee0Au

#Storage

PartStoredHow
The first 14 characters (prefix)in cleartextfor lookup
The remaining charactersneverscrypt, per-tenant salt, N=2^17
The whole keynevernot in the database, not in a log, not in the audit event

Returned exactly once, at creation:

json
{
  "api_key": {
    "id": "key_01M3PSVJA0YP2WDPM2RDR15MGH",
    "object": "api_key",
    "name": "agent-bootstrap",
    "prefix": "ulex_sk_live_7Qm2K",
    "scope": ["mcp:tools", "read:organizations", "write:organizations"],
    "expires_at": "2026-12-28T09:00:00.000Z"
  },
  "key": "ulex_sk_live_7Qm2KpLx9Tb4Ns8RfWy3Zc1Hjf6Ee0Au",
  "warning": "This is the only time the key is returned. Store it now."
}

scrypt with N=2^17 and a per-tenant salt: about 80 ms per verification on a Lambda, which is fast enough to do on every request and slow enough to make an offline attack on a leaked hash expensive.

#Never pass a secret as a tool argument

json
{ "name": "ulex_create_connection", "arguments": {
  "config": { "strategy": "okta_oidc", "oidc": { "client_secret": "env:ULEX_TEST_OKTA_SECRET" } }
} }

An argument is written to the audit log, to your transcript, to your vendor's request log, and to whatever is replaying that transcript next week. ulex accepts env:VAR_NAME for every secret-shaped field and reads the value from its own environment at request time, storing only the ciphertext.

Fields that accept env::

ConnectionField
oidcclient_secret
saml— (the certificate is public)
scimtoken
jwtjwks
password.ldapbind_password
password.radiusshared_secret
directoryscim_token, oauth.client_secret

#Rules

  1. One key per workload. A laptop and a CI job never share one.
  2. expires_in_days of 90 or less, always. A key with no expiry is a key you forget.
  3. Scope narrowly. mcp:tools plus the read:* scopes you need covers most agent work.
  4. ip_allowlist when the caller has fixed egress. CIDR, up to 50 entries.
  5. ulex:admin only in CI, from a protected runner, with ip_allowlist set.
  6. Revoke on suspicion. There is no cost to rotation; mint a new key, deploy, revoke the old one.
ts
const key = process.env.ULEX_API_KEY;
if (!key) throw new Error("ULEX_API_KEY is not set");

// Not this, ever.
const key = "ulex_sk_live_7Qm2KpLx9Tb4Ns8RfWy3Zc1Hjf6Ee0Au";

Revocation is immediate and total: the next call returns 401 api_key_revoked. There is no grace period, because a leaked key must be dead on the next request.

#OAuth 2.1

ulex is an OAuth 2.1 authorization server. What that removes matters:

RemovedConsequence for you
The implicit grantresponse_type=token is not implemented. response_type=id_token is rejected by default on https://ulexid.com unless allow_mocks: true (enabled by default in local in-memory mode)
The resource owner password credentials grantno password in a token request. Ever
response_mode=fragment for the code flowthe default is form_post, which keeps the code out of browser history

#PKCE is mandatory

require_pkce: true and pkce_methods: ["S256"] on every new application. There is no configuration that turns it off.

text
code_verifier  = 43–128 characters from the unreserved set
code_challenge = BASE64URL(SHA256(ASCII(code_verifier)))

RFC 7636 Appendix B test vector, which the simulator honours verbatim for mock_sso:

text
code_verifier  = dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk
code_challenge = E9MelhoQ2YvW96fl8sW7aTtZbGd0mY6Xl0e8Q1sCk

ulex_simulate_login uses that vector by default so an agent never has to get base64url-SHA256 right on the first attempt. Pass return_pkce: true for a generated pair.

#Client authentication

MethodUse
client_secret_postthe default. client_id and client_secret in the body
client_secret_basicHTTP Basic. URL-encode both halves before base64
private_key_jwtclient_assertion signed with a registered key. For a confidential client you do not want a shared secret
nonepublic client. PKCE becomes the entire defence, and it is mandatory

#Token lifetimes

CredentialLifetimeRotation
Authorization code60 ssingle use
Access token3,600 snone
Refresh token2,592,000 s (30 d)every use
ID token3,600 snone
Token-exchange result900 snone
Session86,400 s absolute, 604,800 s idlere-auth every 86,400 s

Refresh tokens rotate. Replaying a spent one revokes the whole family_id and returns invalid_grant with retryable: false. That is not a bug; it is how token theft is detected, and your app must restart the login flow rather than retry.

ts
// Persist the new pair atomically, before the new access token is used.
await db.transaction(async (tx) => {
  await tx.run("UPDATE sessions SET access_token=?, refresh_token=?, expires_at=? WHERE id=?",
    [next.access_token, next.refresh_token, next.expires_at, sessionId]);
});

#On a network timeout during refresh

Do not retry with the same refresh token. Introspect it first:

ts
const state = await introspect(refreshToken);
if (state.active) return useExistingAccessToken();   // the request actually landed
// else: the family was killed. Start a new login.

#Token exchange

bash
curl -sS -X POST "$BASE/oauth2/token/exchange" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d 'grant_type=urn:ietf:params:oauth:grant-type:token-exchange&
      subject_token_type=urn:ietf:params:oauth:token-type:access_token&
      subject_token='"$ACCESS_TOKEN"'&
      audience=client_01M3PSVV38V3BJQ4SDHQPT8WMJ&
      client_id=client_01M3PSV7J8TBSPHG95CYSEX32B&
      client_secret='"$CLIENT_SECRET"

Same sub, new sid, exp = now + 900, aud set to the downstream application. This is how you hand a user to a service without a browser.

#SAML

SAML authenticates a human. See SAML authentication and SAML SP integration.

ulex enforces, on every assertion, in this order: XML parse with DTDs and external entities disabled; Destination; InResponseTo; Issuer; signature against the connection's certificate with an enforced algorithm; the Conditions window against allowed_clock_skew_seconds; NameID resolution; attribute mapping; and Assertion/@ID replay registration.

The NameID is the ulex usr_… id and is stable across email changes. Key your local user table on it.

#The hosted UI

GET /api/v1/auth/{appId} and POST /api/v1/auth/{appId}/callback authenticate humans in a browser. They are not an API and an agent should never drive them. ulex_simulate_login runs the identical transaction server-side and returns JSON.

The session cookie is HttpOnly; Secure; SameSite=None; Domain=.ulexid.com. Only its SHA-256 is stored.

#MFA

Six factor types, four claims. See MFA and passkeys.

json
"amr": ["pwd", "otp", "mfa"],
"acr": "urn:ulex:acr:mfa"

Branch on acr, not amr. urn:ulex:amr:simulated — the marker on a token from ulex_mint_access_token — must never satisfy an MFA check. If it does, a compromised API key is a full account takeover.

#Cross-application SSO

One session per (user, tenant), held in a cookie scoped to cookie_domain. A silent reuse is recorded as sso.session_created. See Cross-app SSO.

#What is not authentication

  • A webhook signature proves ulex sent the request. It is not a way for you to call ulex.
  • The X-Ulex-Request-Id header is a correlation label. It is not a credential and it is not verified.
  • A client secret inside issued on a deployment receipt is a credential. Store it; do not log it.
  • A mcp.tool_invoked event proves a tool ran. It does not prove the caller was authorised; the insufficient_scope denial is the record of that check.

#Reference