Repository navigation
test(plugin-auth): pin credential-at-rest posture for scim_token / client_secret - #8305
Merged
Merged
Conversation
…ient_secret Both columns already store a one-way SHA-256 digest, but nothing held them there: no test referenced storeSCIMToken or storeClientSecret anywhere in the repo, and @better-auth/scim defaults to storeSCIMToken: 'plain' (cleartext). A single option literal in auth-manager.ts was the only thing keeping a live IdP bearer out of an API-readable column, and the planned SCIM rc.2 migration (#3653) changes that exact call site's signature. The pin drives AuthManager's own plugin construction rather than calling scim({ storeSCIMToken: 'hashed' }) itself -- a test that passed the literal would certify the very regression it exists to catch. It reads the stored row at driver level, recomputes the expected digest with node:crypto, and pins the inner-base-token trap as an explicit negative case (hashing the full bearer must NOT match). A control arm measures upstream's cleartext default so the literal is demonstrably load-bearing. Fixes #8192 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PEVB6w7D7uCszR9Mw1BL73
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
📓 Docs Drift CheckNo hand-written docs reference the 0 changed package(s). ✅ |
os-zhuang
marked this pull request as ready for review
August 13, 2026 04:23
This was referenced Aug 13, 2026
This was referenced Aug 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8192
Not a defect fix. #8011 measured that both credential columns already store a one-way SHA-256 digest; this PR is the tripwire that holds that posture in place. Before it,
grep -rn 'storeSCIMToken|storeClientSecret' --include=*.test.ts packages/returned zero hits.The exposure being pinned
@better-auth/scim's own default isstoreSCIMToken: "plain"— cleartext. A single option literal inauth-manager.tsis the only thing between a live IdP bearer and a cleartext value in a column that is readable over the generic data API (sys_scim_providerdeclaresapiMethods: ['list']). The planned SCIM rc.2 migration (#3653) changes that exact call site's construction signature.What makes the pin non-vacuous
AuthManager, notscim(). The load-bearing choice. A test that callsscim({ storeSCIMToken: 'hashed' })itself pins its own literal and would stay green forever after the repo's literal was deleted — certifying exactly the regression it was written to catch. Every assertion runs against a plugin list built byAuthManager.buildPluginList().node:crypto. "Differs from the plaintext" would be satisfied by base64 of the plaintext.base64url("BASE:providerId:organizationId")while the stored digest covers the innerBASEalone, so hashing the full bearer must NOT match. Without that case a future rewrite could "simplify" the positive into the naive shape that fails on correct code.scim()with no option stores the bearer in cleartext. That is what makes the literal demonstrably load-bearing, and it is the permanent form of this card's ablation.Each positive case also asserts the credential still authenticates, so "hash it" cannot be satisfied by storing garbage.
Asymmetry found while building this
The two upstream helpers end differently on an unrecognised storage method:
storeSCIMToken()falls through toreturn scimToken(cleartext, silently), whilestoreClientSecret()ends inthrow new BetterAuthError. Soclient_secretcannot reach cleartext via a dropped literal at all — the only non-hashed value the plugin accepts is"encrypted", and only withdisableJwtPlugin, which its own validation cross-checks. That is recorded in the test header; it is why the SCIM row is the sharp one.Ablation — predicted first, then measured
storeSCIMToken: 'hashed'becomes'plain''mkDp7IWxEjL7ugQQn_kmpgup'vs the expected digest. 1 failed, 3 passedstoreClientSecretset to a pass-through custom hasher (a{ hash }object returning its input unchanged)'xRHyKIHKCyRKAuJlOFkcZJfMBZUsdYSx'. 1 failed, 3 passedNote the second mutation's shape:
'plain'is not usable as an ablation for the OAuth column, becausestoreClientSecret()throws on it rather than storing cleartext.The table includes the deliberate prediction that the AUTHENTICATES case stays green under the SCIM ablation —
verifySCIMTokenmirrors the configured storage method, so with'plain'it compares plaintext to plaintext and still succeeds. That case is a liveness arm, not a posture detector, and the ablation is what establishes the difference.No rebuild was needed for the ablations: the test imports
./auth-manager.jsrelatively, so vitest transforms the package's own source rather than a consumeddist/. Both mutations took effect immediately, which is itself the evidence.Restores were done with
git checkout BRANCH -- PATHfrom the commit; nogit stashat any point.Verification
pnpm --filter @objectstack/plugin-auth test— 47 files, 1093 tests, all pass (4 new).pnpm --filter @objectstack/plugin-auth typecheck— clean.registerObjectrequirespackageId, which several older harnesses omit). Fixed the type rather than raising the ledger; re-measure is back at the recorded 111 and reports "surplus: none".scripts/pm/dispatch-gates.mjs, run after a fullpnpm build. All green exceptcheck:objectui-pin-fresh, which is a stale.objectui-shain the repo state and untouched by this PR.Generated by Claude Code