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

安全问题--jwt 规则建议修改下 #82

Open
Lance621 opened this issue Oct 26, 2022 · 0 comments
Open

安全问题--jwt 规则建议修改下 #82

Lance621 opened this issue Oct 26, 2022 · 0 comments

Comments

@Lance621
Copy link

Lance621 commented Oct 26, 2022

type Claims struct {
Username string `json:"username"`
Password string `json:"password"`
jwt.StandardClaims
}
func GenerateToken(username, password string) (string, error) {
fmt.Println("GenerateToken")
nowTime := time.Now()
expireTime := nowTime.Add(3 * time.Hour)
claims := Claims{
username,
password,
jwt.StandardClaims{
ExpiresAt: expireTime.Unix(),
Issuer: "linglong",
},
}

按照这边的生成规则,会将用户账号密码保存到jwt token中,可以经过简单的解码进行账号密码的查看。

$ go test
GenerateToken
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwicGFzc3dvcmQiOiJwYXNzd29yZCIsImV4cCI6MTY2Njc2NjA3NSwiaXNzIjoibGluZ2xvbmcifQ.4Ia5g5e0EzkOUjJ-Xmnu59lX6JiJVnDVaw_p-7vBrtA
PASS
ok      linglong/pkg/utils      0.063s

$ .\jwt-hack.exe decode eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwicGFzc3dvcmQiOiJwYXNzd29yZCIsImV4cCI6MTY2Njc2NjA3NSwiaXNzIjoibGluZ2xvbmcifQ.4Ia5g5e0EzkOUjJ-Xmnu59lX6JiJVnDVaw_p-7vBrtA
   d8p 8d8   d88 888888888          888  888 ,8b.     doooooo 888  ,dP
   88p 888,o.d88    '88d     ______ 88888888 88'8o    d88     888o8P'
   88P 888P`Y8b8   '888      XXXXXX 88P  888 88PPY8.  d88     888 Y8L
88888' 88P   YP8 '88p               88P  888 8b   `Y' d888888 888  `8p
-------------------------
time="2022-10-26T11:36:19+08:00" level=info msg="Decoded data(claims)" header="{\"alg\":\"HS256\",\"typ\":\"JWT\"}" method="&{HS256 SHA-256}"
time="2022-10-26T11:36:19+08:00" level=info msg="Expiraton Time" EXP=1666766075 TIME="1970-01-01 08:00:01.666766075 +0800 CST"
{"exp":1666766075,"iss":"linglong","password":"password","username":"admin"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant