[Security] Fix hardcoded JWT secrets, database credentials, and deprecated JWT library (CWE-798 + CWE-1104)#66
Open
saaa99999999 wants to merge 1 commit into
Conversation
Replace hardcoded JWT signing keys (SECRET_APP/SECRET_API) and database passwords (root/root, postgres/postgres) with empty placeholders that require user configuration. Add startup validation for JWT secrets with minimum 32-character length requirement and rejection of known default values. Add environment variable tags (APP_JWT_SECRET, API_JWT_SECRET) to Token struct for cleanenv override support. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Security Audit Report ??fiber-boilerplate (sujit-baniya)
Manual code audit discovered 3 security vulnerabilities (1 Critical, 1 High, 1 Medium).
CRITICAL-1: CWE-798 Hardcoded JWT Signing Keys (CVSS 9.1)
Location:
config.sample.yml:55-56,config.yml:55-56Data Flow:
Description:
Both
config.sample.ymlandconfig.ymlship with hardcoded JWT signing keysSECRET_APPandSECRET_API. These are plain-English strings published in the public repository. The same keys are used for both signing and verification (HS256 symmetric algorithm), meaning anyone who reads the repository can forge valid JWT tokens for any user ID. TheTokenstruct also lackedenvtags, so environment variables could not override the hardcoded YAML values via cleanenv.PoC:
Fix:
config.sample.yml+config.yml: Replaced hardcoded secrets with empty strings, forcing user configurationconfig/token.go:12-13: Addedenv:"APP_JWT_SECRET"andenv:"API_JWT_SECRET"tags for cleanenv environment variable overrideconfig/token.go:18-41: AddedValidateSecrets()with minimum 32-character length check and rejection of known default values ("SECRET_APP", "SECRET_API", "secret", "changeme", empty)config/config.go:47-50: Startup validation callsValidateSecrets()after config loading, exits with error if secrets are weakBefore ??After:
config.sample.yml:55-56:config/token.go:12-13:HIGH-2: CWE-798 Hardcoded Database Credentials (CVSS 7.5)
Location:
config.sample.yml:6-8,config.sample.yml:13-15,config.yml:6-8,config.yml:13-15Data Flow:
Description:
Default database credentials (
root/rootfor MySQL,postgres/postgresfor PostgreSQL) are hardcoded in both the sample and active config files. WhileDatabaseDriverhasenvtags (DB_USER,DB_PASS) for environment variable override, the YAML defaults mean anyone deploying with the default config has guessable database credentials.Fix:
config.sample.yml+config.yml: Replaced hardcodedusername/passwordwith empty strings for both MySQL and PostgreSQL driver configurationsBefore ??After:
MEDIUM-3: CWE-1104 Use of Unmaintained Third-Party Components ??Deprecated JWT Library (CVSS 5.9)
Location:
go.mod:11,config/token.go:7,rest/middlewares/auth.go:15Description:
The project uses
github.com/form3tech-oss/jwt-go v3.2.5, which is an archived, unmaintained fork of the originalgithub.com/dgrijalva/jwt-go(also deprecated). The maintained community successor isgithub.com/golang-jwt/jwt. The archived library receives no security patches and has known issues:Recommendation:
Migrate to
github.com/golang-jwt/jwt/v5:Then replace imports:
Changes in this PR (4 files)
envtags for cleanenv override; AddedValidateSecrets()with minimum length + known-default rejectionValidateSecrets()at startup; fatal exit on weak secretCVSS 3.1 Vectors
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N??9.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N??7.5 (requires network access to DB)CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:N??5.9Manual security audit of JWT signing and database configuration