Operate Session Cookie Encryption & Key Rotation
Use these procedures to rotate keys, investigate failures, and respond to incidents. See the overview for the design and the reference for configuration and error details.
Incident Response: Revoking a Compromised Keyβ
Pushing a new HSID-JWE-SECRET version is not the same operation as revoking the old one, and conflating the two
is the single most important pitfall in this design for an actual key-compromise incident.
pushNewSecretVersion(a new Key Vault secret version) makes a new version current for future encryptions. It does not touch the old version'senabledstate at all. The old (possibly compromised) version is picked up by the normal grace-period sweep like any routine rotation, and β by design, to protect legitimate in-flight sessions β stays enabled and decryptable for the full configuredgrace-period(16 minutes by default) after being superseded.disableSecretVersion(an explicit disable of a specific, existing version) is a separate Key Vault operation. Disabling an existing version does not fire aSecretNewVersionCreatedEvent Grid event (no new version was created), so pods do not learn about it near-instantly the way they do for a new-version push. Instead, every pod's owndisableExpiredPreviousVersions()sweep re-reads each version'senabledstate from Key Vault unconditionally, on every tick, before any grace-period math runs β so a version Security force-disables converges across every pod within onegrace-period-check-croninterval (1 minute by default), completely independent of the 16-minute grace period.
Practical consequence: if a key is genuinely compromised, Security must do both of the following, not just the first:
- Push a new version (
az keyvault secret set --name HSID-JWE-SECRET --value <new-base64-key>) so new sessions stop using the compromised key. - Explicitly disable the compromised version (
az keyvault secret set-attributes --name HSID-JWE-SECRET --version <compromised-version> --enabled false) so every pod stops honoring it within about a minute, instead of the full grace period.
Step 2 does mean any legitimate, still-valid session encrypted with the compromised version is invalidated early too (forcing re-authentication) β that's the correct trade-off during an actual compromise, and is exactly why this isn't done automatically for routine rotations.
Local Debugging: Session Cookie Decrypt CLIβ
SessionCookieDecryptCli (src/test/java/.../tools, never ships in the deployable jar) decrypts a compact JWE
outside a running instance, using the same nimbus-jose-jwt classes as CredentialService:
mvn -q test-compile org.codehaus.mojo:exec-maven-plugin:3.1.0:java \
-Dexec.mainClass=com.optum.wallet.authorization.tools.SessionCookieDecryptCli \
-Dexec.classpathScope=test \
-Dexec.args="<compact-jwe> <base64-aes-256-key>"
Both arguments can be supplied via SESSION_COOKIE / SESSION_COOKIE_KEY env vars instead (keeps them out of the
process arg list visible via ps/CI logs β this does not hide them from shell history).
The key is the raw Base64 AES-256 value for the Key Vault secret version named in the cookie's kid header:
az keyvault secret show --name HSID-JWE-SECRET --version <kid> --query value -o tsv
The CLI never calls Key Vault itself. Treat any key that has passed through a shell/chat/ticket as compromised β rotate it, don't reuse it.
Troubleshootingβ
A key was just compromised β how do I revoke it right now?β
Pushing a new version is not enough by itself β see
Incident Response: Revoking a Compromised Key. You must also
explicitly disable the compromised version (az keyvault secret set-attributes ... --enabled false) for every pod
to stop honoring it within ~1 minute instead of the full grace period.
A rotation didn't get picked up by all podsβ
Check:
- Event Grid subscription for
Microsoft.KeyVault.SecretNewVersionCreatedonHSID-JWE-SECRETis active (validation handshake logged once when the subscription was created). KEY_ROTATION_EXTERNAL_VERSION_DETECTEDin the logs of the pods that should have reacted.- Even without Event Grid, every pod self-heals within
latest-version-ttl(default 1 minute) via its own TTL-based refresh.
An old key version isn't being disabledβ
Check:
KEY_ROTATION_GRACE_PERIOD_SWEEP_COMPLETED/KEY_ROTATION_PREVIOUS_VERSION_DISABLEDlogs.- Whether the version has a successor yet β the newest version is never a disable candidate, and grace is measured from when a version was superseded, not from its own
createdOn. KEY_ROTATION_PREVIOUS_VERSION_DISABLE_FAILEDfor a Key Vault-side error (e.g. RBAC).
Customers are getting logged out / 401s right after a rotationβ
This should never happen within the configured grace period β if it does:
- Confirm
grace-period >= latest-version-ttl + max(OIDC state TTL, checkout session TTL)β startup would otherwise fail viaSessionCookieEncryptionSafetyValidator, so this points at a live misconfiguration bypassing that check (e.g. the Key Vault rotation-interval override was changed without redeploying, decoupling actual behavior from what the safety validator checked at startup). - Check for
LEGACY_KID_LESS_COOKIE_REJECTEDβ akid-less cookie from before a cutover deploy, with nolegacy-versionconfigured for that transition window.