fix: replace hardcoded credentials with env var functions (CWE-798)#98
Open
saaa99999999 wants to merge 2 commits into
Open
fix: replace hardcoded credentials with env var functions (CWE-798)#98saaa99999999 wants to merge 2 commits into
saaa99999999 wants to merge 2 commits into
Conversation
Replace hardcoded JWT secret key ("secret key") and MySQL DSN in
easy_note/pkg/consts with functions reading from environment variables
(JWT_SECRET_KEY and DB_DSN), panicking on empty values.
CWE-798: Use of Hard-coded Credentials
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
00df799 to
f2bc8ab
Compare
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.
The easy_note demo has two hardcoded credentials in its constants file: a JWT signing key and a MySQL DSN with username and password.
What was there
easy_note/pkg/consts/consts.go:21,28:
The JWT signing key "secret key" is used in cmd/api/mw/jwt.go:
The DSN "gorm:gorm@tcp(...)" exposes the database username and password. Anyone reading the public repo can:
What changed
Replaced constants with functions that read from env vars, exiting cleanly if not set:
Call site updated from consts.SecretKey to consts.SecretKey().
CWE-798