Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of Hard-coded Credentials in token.go #1

Closed
gtqbhksl opened this issue Aug 22, 2024 · 1 comment
Closed

Use of Hard-coded Credentials in token.go #1

gtqbhksl opened this issue Aug 22, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@gtqbhksl
Copy link

pkg/token/token.go

var (
	config = Config{"Rtg8BPKNEf2mB4mgvKONGPZZQSaJWNLijxR42qRgq0iBb5", "identityKey"}
	once   sync.Once
)
...........
...........
// Sign 使用 jwtSecret 签发 token,token 的 claims 中会存放传入的 subject.
func Sign(identityKey string) (tokenString string, err error) {
	// Token 的内容
	token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
		config.identityKey: identityKey,
		"nbf":              time.Now().Unix(),
		"iat":              time.Now().Unix(),
		"exp":              time.Now().Add(100000 * time.Hour).Unix(),
	})
	// 签发 token
	tokenString, err = token.SignedString([]byte(config.key))

	return
}

In line 94 of the file 'pkg/token/token.go', hard-coded credentials (config.key) are used. This means that the key is written directly in the code or is provided to the program in some other way (such as a configuration file or environment variable). Hard-coded credentials are a very serious security risk because anyone who has access to the code or configuration can get hold of this key, potentially leading to unauthorized access or action. In addition, if the codebase is compromised or obtained by an attacker, hard-coded keys can also be used to forge legitimate tokens or other sensitive operations.

@dengmengmian dengmengmian self-assigned this Aug 23, 2024
@dengmengmian dengmengmian added the bug Something isn't working label Aug 23, 2024
@dengmengmian
Copy link
Member

dengmengmian commented Aug 23, 2024

ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants