[Security] Hardcoded Default JWT Secret Leads to Authentication Bypass
Summary
The BETTER_AUTH_SECRET environment variable defaults to a weak, publicly-known value 'please-set-your-key-here' in lib/config.ts. When this environment variable is not explicitly set in deployment, the system uses this weak default to sign JWT session tokens. Any attacker aware of this default can forge valid JWT tokens, bypass authentication, and access the system as any user.
Details
In lib/config.ts:13-16, the Zod schema for BETTER_AUTH_SECRET defines a default value of 'please-set-your-key-here' when no environment variable is provided. In lib/config.ts:25-29, envSchema.parse() filters and parses process.env, using Zod defaults for unset variables. The parsed value flows to config.auth.secret (lib/config.ts:67-68). In lib/auth.ts:29, this secret is passed to better-auth's constructor. Better-auth uses JWT strategy for session management (lib/auth.ts:35-38), signing tokens with this secret. An attacker who knows the default secret can forge valid JWT session tokens and impersonate any user, achieving complete authentication bypass.
Core vulnerable code path:
// lib/config.ts:13-16
BETTER_AUTH_SECRET: z
.string()
.min(16, "Auth secret must be at least 16 characters")
.default("please-set-your-key-here"),This Zod schema defines the BETTER_AUTH_SECRET environment variable with a hardcoded default value 'please-set-your-key-here'. When the environment variable is not set, this weak, publicly-known value is used as the JWT signing secret.
// lib/config.ts:67-68
auth: {
secret: env.BETTER_AUTH_SECRET,The weak default secret flows through config.auth.secret to become the JWT signing key. No validation or rejection of weak secrets is performed at this point.
// lib/auth.ts:29-38
secret: config.auth.secret,
email: {
provider: "resend",
from: config.email.from,
resend,
},
session: {
strategy: "jwt",Better-auth uses config.auth.secret (the weak default) as the JWT signing key with JWT session strategy. This allows an attacker with the known default secret to forge valid JWT tokens.
POC
Prerequisites: (1) Target deployment does not set BETTER_AUTH_SECRET environment variable (uses the default). (2) Attacker has network access to the target application.
Step 1: Forge a JWT token using the known default secret 'please-set-your-key-here'. The attacker constructs a JWT payload in better-auth format with a known user ID and signs it using HS256 with the default secret.
Step 2: Use the forged JWT token to access protected endpoints. Example: GET /transactions/ with Cookie: taxhacker-session-token=<forged_jwt>
Expected result: The server accepts the forged JWT token and returns the user's transaction data, confirming authentication bypass.
Impact
Complete authentication bypass. An attacker can: (1) Access any user's financial data (transactions, files, settings). (2) Create, modify, or delete transactions. (3) Upload and download files. (4) Access all API endpoints. (5) Execute AI analysis. (6) Export user data. This is a fundamental security flaw that undermines all access control in the application.
Remediation
- Remove the default value from the Zod schema in lib/config.ts, making BETTER_AUTH_SECRET a required environment variable.
- Add a startup check that validates the JWT secret meets minimum entropy requirements.
- Update .env.example with a strong randomly generated default and clear warning.
- Implement a configuration validation at application startup that rejects weak or default secrets.
- Consider generating a secure random key automatically on first run.
Disclosure Notes
The default secret 'please-set-your-key-here' is visible in the public source code repository. All deployments that did not explicitly set BETTER_AUTH_SECRET are affected. The .env.example file also shows a weak secret 'random-secret-key' which should be replaced with a cryptographically strong value. No CVE ID has been assigned yet.
Supplemental Information
Affected products
- Ecosystem: self-hosted
- Package name: vas3k/TaxHacker
- Affected versions: main (all versions with the default secret)
- Patched versions: none confirmed
Severity
- Scoring method: CVSS v3.1
- Score: 9.8
- Vector string: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
Weaknesses
- CWE: CWE-798 Use of Hard-coded Credentials
Source: vas3k/TaxHacker