/

CVE-2026-48031

Severity:

CRITICAL RISK

(9.1)

Hardcoded JWT Secret (CWE-798) in Go REST API Boilerplate

CVE-2026-48031

Deferred

Vulnerability type

Category:

Hardcoded Cryptographic Secret

CWE:

CWE-798

Impact:

Authentication Bypass and Token Forgery

Severity:

CRITICAL RISK

(9.1)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A hardcoded JWT signing secret in the Go REST API boilerplate go-base allows attackers who can access the public repository to forge valid tokens for any user or role.

When the application falls back to the embedded "random" secret or weak environment values, authentication on protected endpoints can be completely bypassed, and unreliable secret handling may also cause denial-of-service on restarts.

Affected context

This vulnerability occurs in Go-based REST APIs that use JWT tokens for authentication and rely on a boilerplate repository where the signing key is hardcoded or trivially guessable.

It is most relevant in deployments that:

  • Use the default dev.env template or do not override the built-in secret
  • Expose the source code or environment configuration publicly
  • Depend on JWT validation for access control to admin or sensitive endpoints

Under these conditions, any party who knows or can read the static key can mint tokens that the server accepts as legitimate.

Exploit preconditions

  • Attack surface: Public HTTP endpoints protected by JWT-based authentication
  • Required access: Ability to read the source repository or otherwise learn the hardcoded or default signing secret
  • Trigger point: Submission of forged JWT tokens in Authorization headers or equivalent authentication channels
  • Why exploitation is possible: The application uses a fixed, predictable secret ("random") from configuration or code, so attackers can locally generate tokens signed with the same key and have them accepted as authentic, bypassing normal login and role checks.

Why this happens

The underlying bug class is the use of a hardcoded cryptographic secret for JWT signing, mapped to CWE-798: Use of Hard-coded Credentials.

Instead of deriving the signing key from a protected configuration source, the boilerplate template embeds "random" directly in both environment templates and runtime fallback logic.

This creates an insecure pattern where authentication integrity depends on a constant value that is trivially accessible and never rotated.

An attempted mitigation that only rejected the exact string "random" and introduced an ephemeral in-memory key added operational fragility without addressing the broader issue of secure key management and persistence.

Potential impact

  • Attackers can forge JWTs for arbitrary users, including administrative accounts.
  • Authentication and authorization on all protected endpoints can be completely bypassed.
  • Sensitive data exposure through unauthorized API access may occur.
  • Privilege escalation within the application context can happen.
  • Operational instability or denial-of-service may result from non-persistent, automatically regenerated keys that invalidate tokens on each restart.

General mitigation guidance

Effective mitigation focuses on removing hardcoded secrets and enforcing robust key management practices.

Typical defensive patterns include:

  • Deriving JWT signing keys exclusively from secure configuration sources managed outside of source control, such as secret stores or environment variables with restricted access.
  • Validating configuration at startup to ensure the secret meets minimum entropy and length requirements, rejecting weak or default values.
  • Implementing a clear rotation strategy for signing keys, with support for key identifiers (kid) and grace periods for old tokens where appropriate.
  • Decoupling development and production secrets, using dedicated non-public test keys for local environments and never committing them to version control.
  • Applying least privilege and access controls to any system that can read or modify JWT signing secrets, treating them as high-value credentials.

How teams detect issues like this

High-level detection approaches for hardcoded JWT secrets include:

  • Static analysis rules that flag assignments of constant strings to cryptographic keys, JWT signing functions, or authentication-related configuration variables.
  • Repository scanning for known weak values (e.g., "random", "secret", "changeme") in configuration files, environment templates, and command-line arguments.
  • Security-focused code reviews that treat any inline credential-like value as a defect, with checklists covering key generation, storage, and rotation.
  • CI/CD policy enforcement that rejects builds containing hardcoded secrets or missing references to regulated secret management systems.
  • Optional use of automated secret-detection tools integrated with version control to prevent introduction or persistence of static keys.

Sources

SourceLink
github.comgithub.com/dhax/go-base/commit/cc82b9740fa6b08e0fad409cd4b418e240dd0e00
github.comgithub.com/dhax/go-base/pull/31
github.comgithub.com/dhax/go-base/security/advisories/GHSA-mqq6-462x-jxmm

Frequently asked

questions

It is broadly exploitable in any deployment that uses the default or hardcoded JWT secret and exposes the API over the network. Anyone who can access the repository or learn the fixed key can forge tokens and gain unauthorized access.

An attacker only needs knowledge of the static signing secret, which can often be obtained by reading the public repository or shared configuration templates. No access to the running server beyond normal network reach is required.

The safest pattern is to remove all hardcoded secrets from code and templates, load JWT signing keys exclusively from secure secret management systems, enforce strong entropy requirements, and support planned key rotation without breaking existing valid sessions.

Prevention relies on institutionalizing secure credential practices: forbid credentials in source control, adopt automated secret scanning, require configuration-driven key management, and treat authentication-related secrets as critical assets with documented ownership, rotation, and access controls.

Find out what's already
exploitable in your codebase.