Skip to content

Commit

Permalink
docs: add comments
Browse files Browse the repository at this point in the history
add comments for preprocessing code modifications of the auditplan token

@LinXiaoTao
  • Loading branch information
winfredLIN committed Sep 7, 2023
1 parent 198afba commit e4660b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sqle/api/controller/v1/audit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ func CreateAuditPlan(c echo.Context) error {
}

// generate token
// 为了控制JWT Token的长度,保证其长度不超过数据表定义的长度上限(255字符)
// 因此使用MD5算法将变长的 currentUserName 和 Name 转换为到固定长度
j := utils.NewJWT(utils.JWTSecretKey)
t, err := j.CreateToken(utils.Md5(currentUserName), time.Now().Add(tokenExpire).Unix(),
utils.WithAuditPlanName(utils.Md5(req.Name)))
Expand Down
2 changes: 2 additions & 0 deletions sqle/api/middleware/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func ScannerVerifier() echo.MiddlewareFunc {
}
projectName := c.Param("project_name")
apnInParam := c.Param("audit_plan_name")
// 由于对生成的JWT Token的负载使用MD5算法进行预处理,因此在验证的时候也需要对param中的apn使用MD5处理
// 为了兼容老版本的JWT Token需要增加不经MD5处理的apnInParam和apnInToken的判断
if apnInToken != apnInParam && apnInToken != utils.Md5(apnInParam) {
return echo.NewHTTPError(http.StatusInternalServerError, errAuditPlanMisMatch.Error())
}
Expand Down

0 comments on commit e4660b0

Please sign in to comment.