mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🔒 改进访问授权验证码安全性 Fix https://github.com/siyuan-note/siyuan/issues/5452
This commit is contained in:
parent
9f7d2182be
commit
20930e0f69
2 changed files with 17 additions and 12 deletions
|
|
@ -63,7 +63,7 @@ func LoginAuth(c *gin.Context) {
|
||||||
|
|
||||||
var inputCaptcha string
|
var inputCaptcha string
|
||||||
session := util.GetSession(c)
|
session := util.GetSession(c)
|
||||||
if session.NeedCaptcha() {
|
if util.NeedCaptcha() {
|
||||||
captchaArg := arg["captcha"]
|
captchaArg := arg["captcha"]
|
||||||
if nil == captchaArg {
|
if nil == captchaArg {
|
||||||
ret.Code = 1
|
ret.Code = 1
|
||||||
|
|
@ -71,6 +71,11 @@ func LoginAuth(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
inputCaptcha = captchaArg.(string)
|
inputCaptcha = captchaArg.(string)
|
||||||
|
if "" == inputCaptcha {
|
||||||
|
ret.Code = 1
|
||||||
|
ret.Msg = Conf.Language(21)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if strings.ToLower(session.Captcha) != strings.ToLower(inputCaptcha) {
|
if strings.ToLower(session.Captcha) != strings.ToLower(inputCaptcha) {
|
||||||
ret.Code = 1
|
ret.Code = 1
|
||||||
|
|
@ -84,9 +89,9 @@ func LoginAuth(c *gin.Context) {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = Conf.Language(83)
|
ret.Msg = Conf.Language(83)
|
||||||
|
|
||||||
session.WrongAuthCount++
|
util.WrongAuthCount++
|
||||||
session.Captcha = gulu.Rand.String(7)
|
session.Captcha = gulu.Rand.String(7)
|
||||||
if session.NeedCaptcha() {
|
if util.NeedCaptcha() {
|
||||||
ret.Code = 1 // 需要渲染验证码
|
ret.Code = 1 // 需要渲染验证码
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,7 +104,7 @@ func LoginAuth(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
session.AccessAuthCode = authCode
|
session.AccessAuthCode = authCode
|
||||||
session.WrongAuthCount = 0
|
util.WrongAuthCount = 0
|
||||||
session.Captcha = gulu.Rand.String(7)
|
session.Captcha = gulu.Rand.String(7)
|
||||||
if err := session.Save(c); nil != err {
|
if err := session.Save(c); nil != err {
|
||||||
logging.LogErrorf("save session failed: " + err.Error())
|
logging.LogErrorf("save session failed: " + err.Error())
|
||||||
|
|
|
||||||
|
|
@ -22,16 +22,16 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SessionData represents the session.
|
var WrongAuthCount int
|
||||||
type SessionData struct {
|
|
||||||
ID int
|
func NeedCaptcha() bool {
|
||||||
AccessAuthCode string
|
return 3 < WrongAuthCount
|
||||||
WrongAuthCount int
|
|
||||||
Captcha string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sd *SessionData) NeedCaptcha() bool {
|
// SessionData represents the session.
|
||||||
return 3 < sd.WrongAuthCount
|
type SessionData struct {
|
||||||
|
AccessAuthCode string
|
||||||
|
Captcha string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save saves the current session of the specified context.
|
// Save saves the current session of the specified context.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue