Skip to content

fix(auth): remove dead secret fallback in email-log id salt - #22

Merged
AndersonDesign1 merged 1 commit into
mainfrom
chore/react-doctor-cleanup
Jun 22, 2026
Merged

fix(auth): remove dead secret fallback in email-log id salt#22
AndersonDesign1 merged 1 commit into
mainfrom
chore/react-doctor-cleanup

Conversation

@AndersonDesign1

Copy link
Copy Markdown
Owner

What

getEmailLogId in src/auth/better-auth.ts used process.env.BETTER_AUTH_SECRET ?? "clientra-auth-email-log" to salt an HMAC log-correlation id. React Doctor flagged this as a hardcoded secret that "fails open."

Why it's safe / why fix anyway

  • The salt is only used to derive a non-reversible log-correlation id (keeps raw emails out of logs) — it is not an auth/signing key.
  • In production the module already throws at startup if BETTER_AUTH_SECRET is unset (better-auth.ts:27), so the literal-fallback branch was unreachable dead code there.
  • The fix reuses the already-validated rawAuthSecret and gives the dev-only path an explicitly named, non-secret salt — clearer intent, no misleading "secret" literal.

Impact

Clears the only React Doctor security error. Full-project score 49 → 87 ("Great"). The 6 remaining warnings are confirmed false positives (String.prototype.includes misread as array lookup; inline-function-call render helpers) plus vendored evilcharts/** — no action needed.

Checks

typecheck + lint pass locally.

🤖 Generated with Claude Code

getEmailLogId reused `process.env.BETTER_AUTH_SECRET ?? "<literal>"`, which
React Doctor flagged as a hardcoded secret that fails open. In production the
module already throws when BETTER_AUTH_SECRET is unset, so the literal branch
was unreachable there. Reuse the already-validated `rawAuthSecret` and give the
dev-only path an explicitly named, non-secret salt — the value is a
log-correlation HMAC salt, never a signing key.

Clears the only React Doctor security error; full-project score 49 -> 87.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@vercel

vercel Bot commented Jun 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clientra Ready Ready Preview, Comment Jun 22, 2026 3:16pm

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@AndersonDesign1, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 34 minutes and 52 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1ba2dff7-25e8-4f5f-ab8e-235c200ccd17

📥 Commits

Reviewing files that changed from the base of the PR and between dafba32 and cf3dfba.

📒 Files selected for processing (1)
  • src/auth/better-auth.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/react-doctor-cleanup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown

React Doctor found no issues. 🎉

Reviewed by React Doctor for commit cf3dfba.

@greptile-apps

greptile-apps Bot commented Jun 22, 2026

Copy link
Copy Markdown

Greptile Summary

  • Updates getEmailLogId in src/auth/better-auth.ts to reuse the validated auth secret when available.
  • Replaces the old hardcoded fallback with an explicitly named dev-only log-correlation salt.
  • Adds comments clarifying that the salt is for non-reversible email log IDs, not auth signing.

Confidence Score: 4/5

The change is narrowly scoped to auth email log ID salt handling, but one consistency issue remains when the configured auth secret includes surrounding whitespace.

The reviewed file is small and the affected behavior was exercised with a targeted runtime check, so the remaining risk is well understood and localized.

src/auth/better-auth.ts

T-Rex T-Rex Logs

What T-Rex did

  • Ran a targeted Node harness against the auth module to validate secret normalization behavior.
  • The runtime trace revealed the Better Auth configuration read the raw padded secret from process.env.BETTER_AUTH_SECRET.
  • The harness showed that the HMAC computed with the trimmed secret matched the email log, while the HMAC computed with the raw padded secret did not.
  • An attempt to run the Vitest harness was blocked by a local Node engine mismatch.
  • Compared before and after production logs to confirm that emailLogId updated to the new salt after normalization.
  • Verified production logs show a missing BETTER_AUTH_SECRET error, indicating that production fallback remains unreachable.

View all artifacts

T-Rex Ran code and verified through T-Rex

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
src/auth/better-auth.ts:50
**Normalize secrets consistently.** `rawAuthSecret` is trimmed here, but the Better Auth config still receives `process.env.BETTER_AUTH_SECRET` verbatim through `secret`. When the environment value has leading or trailing whitespace, production passes the startup check and Better Auth signs with the padded secret, while this helper derives email log IDs from the unpadded value. That silently changes correlation IDs for only this path. Use the same validated value for both the auth config and this helper, or keep both paths on the exact same raw value.

Reviews (1): Last reviewed commit: "fix(auth): remove dead secret fallback i..." | Re-trigger Greptile

Comment thread src/auth/better-auth.ts
// Salt for a non-reversible log-correlation id (keeps raw emails out of logs).
// In production `rawAuthSecret` is guaranteed set (we throw above otherwise);
// the dev-only constant is an explicit, non-secret salt — never a real key.
const secret = rawAuthSecret ?? "clientra-dev-email-log-salt";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Normalize secrets consistently. rawAuthSecret is trimmed here, but the Better Auth config still receives process.env.BETTER_AUTH_SECRET verbatim through secret. When the environment value has leading or trailing whitespace, production passes the startup check and Better Auth signs with the padded secret, while this helper derives email log IDs from the unpadded value. That silently changes correlation IDs for only this path. Use the same validated value for both the auth config and this helper, or keep both paths on the exact same raw value.

Artifacts

Repro: targeted auth secret normalization harness

  • Contains supporting evidence from the run (text/javascript; charset=utf-8).

Repro: runtime trace showing raw Better Auth secret and trimmed email HMAC salt

  • Keeps the command output available without making the summary code-heavy.

Repro: attempted Vitest harness blocked by local Node engine mismatch

  • Contains supporting evidence from the run (text/typescript; charset=utf-8).

View artifacts

T-Rex Ran code and verified through T-Rex

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/auth/better-auth.ts
Line: 50

Comment:
**Normalize secrets consistently.** `rawAuthSecret` is trimmed here, but the Better Auth config still receives `process.env.BETTER_AUTH_SECRET` verbatim through `secret`. When the environment value has leading or trailing whitespace, production passes the startup check and Better Auth signs with the padded secret, while this helper derives email log IDs from the unpadded value. That silently changes correlation IDs for only this path. Use the same validated value for both the auth config and this helper, or keep both paths on the exact same raw value.

How can I resolve this? If you propose a fix, please make it concise.

@AndersonDesign1
AndersonDesign1 merged commit a36b5a3 into main Jun 22, 2026
8 checks passed
@AndersonDesign1
AndersonDesign1 deleted the chore/react-doctor-cleanup branch June 22, 2026 15:23
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.

1 participant