fix: replace hardcoded JWT secret and DB password with env vars (CWE-798)#161
Open
saaa99999999 wants to merge 1 commit into
Open
fix: replace hardcoded JWT secret and DB password with env vars (CWE-798)#161saaa99999999 wants to merge 1 commit into
saaa99999999 wants to merge 1 commit into
Conversation
…798) JwtSecret=233 and Password=rootroot in conf/app.ini replaced with JWT_SECRET/DB_PASSWORD environment variables with fatal-on-empty guard.
Author
|
Hi maintainer, thank you for reviewing this PR. This fix addresses CWE-798 (Use of Hard-coded Credentials) with two findings:
Could you please apply for a CVE ID from GitHub Advisory (Security tab > Draft a security advisory) for these vulnerabilities after merging? This is the correct process: the CVE should be requested on the official upstream repository (eddycjy/go-gin-example), not on the fork. Thank you! |
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.
Summary
go-gin-example 的 conf/app.ini 中硬编码了两个关键安全凭据:
Changes
pkg/setting/setting.go — 添加环境变量覆盖逻辑,密钥为空时 fatal exit:
if jwtSecret := os.Getenv("JWT_SECRET"); jwtSecret != "" {
AppSetting.JwtSecret = jwtSecret
}
if AppSetting.JwtSecret == "" {
fmt.Fprintf(os.Stderr, "fatal: JWT_SECRET is not set...")
os.Exit(1)
}
conf/app.ini — 移除硬编码值,置空由环境变量提供:
-JwtSecret = 233
+JwtSecret =
-Password = rootroot
+Password =
Data Flow
conf/app.ini:JwtSecret → setting.AppSetting.JwtSecret → util.jwtSecret → jwt.SignedString()/ParseToken()
conf/app.ini:Password → setting.DatabaseSetting.Password → models.Setup() → gorm.Open(DSN)
Verification
启动前设置环境变量:
export JWT_SECRET="$(openssl rand -base64 32)"
export DB_PASSWORD="your-db-password"