保存显式授权范围与认证加固中间检查点

This commit is contained in:
xuans committed 2026-09-15 21:54:04 +08:00
1 parent 7f567ea23a
commit 49ede22861
28 files changed
+961 -148

No files matched your search

+15 -21
View File
@@ -106,6 +106,9 @@ type Server struct {
authMu sync.RWMutex
loginAttempts map[string]loginAttempt
loginMu sync.Mutex
loginSources map[string]loginSource
loginPending map[string]int
loginInFlight int
loginPrunedAt time.Time
now func() time.Time
httpServer *http.Server
@@ -144,6 +147,8 @@ func New(deps Dependencies) *Server {
resetLimiter: newResetRateLimiter(),
authSessions: make(map[string]authSession),
loginAttempts: make(map[string]loginAttempt),
loginSources: make(map[string]loginSource),
loginPending: make(map[string]int),
now: time.Now,
}
router.Use(server.requestMiddleware())
@@ -361,10 +366,17 @@ func (s *Server) ready(c *gin.Context) {
continue
}
checked[reference] = struct{}{}
if _, err := reader.Get(ctx, reference); err != nil {
credentials, err := reader.Get(ctx, reference)
if err != nil {
s.writeReadinessFailure(c, "credential_unavailable")
return
}
if reference == dnsReference && cfg.DNS.Provider == dnsprovider.Aliyun {
if _, err := dnsprovider.ParseAliyunScope(credentials); err != nil {
s.writeReadinessFailure(c, "dns_scope_required")
return
}
}
}
for _, path := range []string{cfg.Server.TLSCert, cfg.Server.TLSKey} {
@@ -460,19 +472,10 @@ func (s *Server) createDomain(c *gin.Context) {
s.writeError(c, http.StatusBadRequest, "域名配置无效", err)
return
}
if err := s.validateDomainAliyunAuthorization(c.Request.Context(), item.Name); err != nil {
if err := s.validateDomainAliyunAuthorization(c.Request.Context(), append([]string{item.Name}, item.SANs...)...); err != nil {
s.writeError(c, http.StatusBadRequest, err.Error(), err)
return
}
for _, san := range item.SANs {
if san == item.Name {
continue
}
if err := s.validateDomainAliyunAuthorization(c.Request.Context(), san); err != nil {
s.writeError(c, http.StatusBadRequest, err.Error(), err)
return
}
}
if err := s.repository.Create(c.Request.Context(), item); err != nil {
if repository.IsConflict(err) {
s.writeError(c, http.StatusConflict, "域名已经存在", err)
@@ -507,19 +510,10 @@ func (s *Server) updateDomain(c *gin.Context) {
s.writeError(c, http.StatusBadRequest, "域名配置无效", err)
return
}
if err := s.validateDomainAliyunAuthorization(c.Request.Context(), item.Name); err != nil {
if err := s.validateDomainAliyunAuthorization(c.Request.Context(), append([]string{item.Name}, item.SANs...)...); err != nil {
s.writeError(c, http.StatusBadRequest, err.Error(), err)
return
}
for _, san := range item.SANs {
if san == item.Name {
continue
}
if err := s.validateDomainAliyunAuthorization(c.Request.Context(), san); err != nil {
s.writeError(c, http.StatusBadRequest, err.Error(), err)
return
}
}
item.ID = existing.ID
item.CreatedAt = existing.CreatedAt
item.Status = "pending"