Skip to content

bcc-login 1.3.0: store the OIDC tokens sealed instead of in plain text - #267

Open
cs1m0n wants to merge 5 commits into
masterfrom
feature/sealed-oidc-tokens
Open

cs1m0n wants to merge 5 commits into
masterfrom
feature/sealed-oidc-tokens

Conversation

@cs1m0n

@cs1m0n cs1m0n commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

The access and ID tokens are no longer stored readable anywhere on the server. They're encrypted, and only the browser's WordPress login cookie holds what's needed to decrypt them. Static checks and a local WordPress test pass, but a real login through login.bcc.no hasn't been tried yet.

How it works

  • Each login's tokens are encrypted (XChaCha20-Poly1305) and stored as one row. The key comes from the random token in WordPress's own wordpress_logged_in_* cookie plus the AUTH salt in wp-config. WordPress stores only a hash of that token.
  • The database, its backups and staging copies therefore hold only data nobody can decrypt, and once the cookie is gone it can never be decrypted.
  • No new cookie: requests are about 46 bytes lighter, because the oidc_token_id cookie is gone.
  • Back-channel logout deletes a small per-session marker, which ends that login in every browser. The old ?state= style still works.

What changes for users and themes

  • Everyone logs in again once after the deploy. It's silent while their login.bcc.no session is still alive. Deploy off-peak.
  • The token endpoints and person UID/groups now need a WordPress login. Visitors who aren't logged in get '' (for example the analytics widget). Before, a leftover oidc_token_id cookie was enough.
  • The token endpoints no longer redirect to login when a session has expired. They return '', which widgets handle; before, their fetch failed on the redirect.
  • Old plaintext token rows are deleted right after the update, then daily (to catch restored backups or pushed databases), and from "Delete subscribers". The purge is skipped while bcc-signon is active, because it uses the same names.
  • Themes have a new PHP API: bcc_login()->get_client()->get_current_id_token_claims(), plus get_current_access_token() and get_current_id_token(). It's documented in docs/signon/getting-user-information.md.
  • Themes that still read the old transients keep working for logged-in users. A compatibility layer answers those reads without storing anything.

The core change is in includes/class-bcc-login-session-vault.php (new) and includes/class-bcc-login-client.php.

Checks

  • php -l passes on PHP 7.4 and 8.4. PHPStan level 1 and Psalm with taint analysis also pass, both set up like CI.
  • 47 checks passed in the DevKinsta bccinternational site, run with WP-CLI from a temporary copy in the container. They covered storage, wrong user or token, tampering, both back-channel logout styles, the endpoints, the theme layer and the purge. The site's plugin files weren't touched, and the test cleaned up after itself.
  • Realistic tokens sealed to 3,627 bytes, which confirms they wouldn't fit well in a cookie.
  • The local site's old plaintext token rows disappeared on their own between checks (its WP-Cron runs constantly). The test's purge only ever saw its own rows, and it was rolled back.
  • Still to test on staging with a real account: log in, then confirm no eyJ… tokens remain in wp_options; try the widgets, a real back-channel logout from Auth0, and log out.

Version: bumped to 1.3.0 in package.json, since this makes everyone log in again. CI releases it as 1.3.0 when merged.

Follow-ups

  • The bcckids theme (functions.php, template-parts/posts/theme-resources.php) still reads the old transients and puts the access token into iframe URLs. Once it uses the new API, the compatibility layer can be removed.
  • Back-channel logout still doesn't verify the logout_token signature. That was already the case before this change.

After Copilot's review (c70d776)

  • Tokens are stored per OIDC client (and scope). A site of a network that logs in with another client gets its own tokens, never another client's. The same person logging in again keeps their WordPress session, so moving between such sites doesn't log them out of the others.
  • Each session is tied to a generation of its sid marker. A marker created again by a later login can't bring back sessions that a back-channel logout ended.
  • The compatibility layer for the old oidc_* transient reads only works on pages the theme renders. Scripts that load WordPress themselves, like BCC Signon's access-token.php (which writes what it reads into the PHP session), get nothing.
  • Checks: PHPStan, Psalm taint analysis and a PHP 7.4 lint pass. The local WordPress test now has 66 checks, all passing, including one for each of these points.

🤖 Generated with Claude Code

cs1m0n and others added 2 commits November 30, 2026 16:34
The access and ID tokens of each login are encrypted (XChaCha20-Poly1305) in a site
transient, with a key derived from the session token in WordPress's login cookie and
the AUTH salt. The database, its backups and staging copies no longer hold a token
anyone can read. Back-channel logout (logout_token and the old ?state=) ends a session
by deleting a per-sid marker.

Also:
- Token endpoints and person UID/groups need a WordPress login.
- Endpoints skip the session-expired redirect, so widgets get '' instead.
- Plaintext token transients of older versions are purged after the update, daily and
  from "Delete subscribers".
- New PHP API for themes; reads of the old oidc_* transients keep working for
  logged-in visitors for now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Users log in again once after this update, as tokens are now stored sealed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cs1m0n cs1m0n self-assigned this Nov 30, 2026
@cs1m0n
cs1m0n requested review from adelinn and a balanced review from Copilot November 30, 2026 14:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved security flaws allow legacy endpoints to cache plaintext tokens, sessions to cross OIDC-client boundaries, and concurrent login callbacks to reactivate sessions revoked by back-channel logout.

3 open issues
What changed in this PR

BCC Login 1.3.0 replaces plaintext OIDC token storage with encrypted session storage tied to the browser’s WordPress login cookie. Existing users must log in again after deployment.

Changes:

  • Adds encrypted token storage and session-marker-based back-channel logout.
  • Routes token endpoints and theme APIs through the authenticated session, with legacy transient compatibility.
  • Adds legacy plaintext cleanup, documents the new APIs, and bumps the release version.
File Description
plugins/​bcc-login/​package.json Bumps version to 1.3.0.
plugins/​bcc-login/​includes/​class-bcc-login-visibility.php Allows token endpoints to return empty responses for expired sessions.
plugins/​bcc-login/​includes/​class-bcc-login-settings.php Adds plaintext-token cleanup to Delete subscribers.
plugins/​bcc-login/​includes/​class-bcc-login-session-vault.php Implements token encryption, storage, and revocation markers.
plugins/​bcc-login/​includes/​class-bcc-login-client.php Integrates the vault, token APIs, and compatibility filters.
plugins/​bcc-login/​includes/​class-bcc-login-cleanup.php Schedules and performs legacy plaintext-token deletion.
plugins/​bcc-login/​endpoints/​user-profile.php Reads the ID token through the session API.
plugins/​bcc-login/​endpoints/​logout.php Revokes sessions by SID or legacy state.
plugins/​bcc-login/​endpoints/​id-token.php Uses authenticated ID-token retrieval.
plugins/​bcc-login/​endpoints/​clear-cookies.php Deletes stored tokens before clearing cookies.
plugins/​bcc-login/​endpoints/​access-token.php Uses authenticated access-token retrieval.
plugins/​bcc-login/​bcc-login.php Loads the vault and exposes the login client.
docs/​signon/​getting-user-information.md Documents endpoint behavior, PHP APIs, and encrypted storage.

Review effort: Balanced

cs1m0n and others added 3 commits November 30, 2026 16:51
- Bind each session to the generation of its sid marker, so a marker created
  again by a later login doesn't bring back sessions a back-channel logout ended.
- Store the tokens per OIDC client (and scope): a site of a network that logs in
  with another client gets its own tokens and never those of another client. The
  same person logging in again keeps their WordPress session, so moving between
  such sites doesn't replace the login cookie (and other sites' tokens).
- Serve the old oidc_* transient reads only on pages the theme renders, so
  scripts that load WordPress themselves (like BCC Signon's access-token.php,
  which keeps what it reads in the PHP session) don't get the tokens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
load() only accepts sealed tokens while their sid marker exists with the
same generation, but save() didn't check that the marker was written
(set_site_transient() also returns false when the value doesn't change).
If the write was lost, every login succeeded and the next page found the
session invalid, which started a silent loop through login.bcc.no.

Read the marker back and fail the login, as when the tokens can't be
stored, if it's missing. If a login of the same sid at the same moment
wrote another generation, the tokens take that one instead of failing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013xX9Qfhaxav4Uigkz4HaF5
- The cleanup right after the update marked the old tokens as deleted
  even when a query failed. It now retries in an hour instead, and is
  only marked as done once it succeeded (or was skipped because BCC
  Signon stores its tokens under the same names, which it now reports as
  null rather than 0).
- A failed batch no longer skips clearing the cached options, as the
  rows of earlier batches are deleted.
- The back-channel logout answers 400 when it couldn't end the sessions
  (their marker is still there after deleting it) or can't handle the
  request (no sid or state), so login.bcc.no doesn't take it as done, and
  sends Cache-Control: no-store. The state is kept when its marker
  couldn't be deleted, so the logout can be retried.
- A login fails, before its tokens are stored, when the state for the
  old back-channel logout can't be stored, as it already did for the sid
  marker.
- An existing session that couldn't be extended to the new tokens'
  expiry isn't reused: a new session lasts as long as they do.
- Starting the login again because the tokens couldn't be loaded keeps
  them, so a failed read (e.g. the object cache briefly unavailable)
  doesn't lose them.
- The settings page says when the old tokens were kept because BCC
  Signon is active, and that a site of a network only removes its own
  expired transients.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013xX9Qfhaxav4Uigkz4HaF5

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants