安全: 修复凭据、遥测与账号数据清理风险
This commit is contained in:
+25
-11
@@ -656,6 +656,10 @@ func VoteCreate(ctx context.Context) {
|
||||
editURL := "/user/votes/" + fmt.Sprint(vote.ID) + "/edit"
|
||||
|
||||
if action == "publish" {
|
||||
if !canPublishVote(ctx) {
|
||||
ctx.Redirect(editURL)
|
||||
return
|
||||
}
|
||||
if err := validateForPublish(ctx, vote); err != nil {
|
||||
ctx.SetErrorFlash(err.Error())
|
||||
ctx.Redirect(editURL)
|
||||
@@ -875,6 +879,10 @@ func VoteUpdate(ctx context.Context) {
|
||||
|
||||
// action=publish:已保存为草稿,再执行发布校验;失败则保留草稿并停留在编辑页
|
||||
if action == "publish" {
|
||||
if !canPublishVote(ctx) {
|
||||
ctx.Redirect(editURL)
|
||||
return
|
||||
}
|
||||
// 用刚保存的内容刷新 vote 结构,供审核与结构校验读取最新标题/类型
|
||||
vote.Title = form.opts.Title
|
||||
vote.Description = form.opts.Description
|
||||
@@ -900,6 +908,22 @@ func VoteUpdate(ctx context.Context) {
|
||||
ctx.Redirect(editURL + "?saved=1")
|
||||
}
|
||||
|
||||
// canPublishVote 统一投票发布的站方处置检查:L2 起不得发布新的公开内容。
|
||||
// 查询失败时 fail-closed;错误提示在此统一设置,重定向目标由各发布入口保持原语义。
|
||||
func canPublishVote(ctx context.Context) bool {
|
||||
level, _, err := db.Restrictions.ActiveLevel(ctx.Request().Context(), ctx.User.ID)
|
||||
if err != nil {
|
||||
logrus.WithContext(ctx.Request().Context()).WithError(err).Error("Failed to query user restriction")
|
||||
ctx.SetInternalErrorFlash()
|
||||
return false
|
||||
}
|
||||
if db.RestrictionAtLeast(level, db.RestrictionL2) {
|
||||
ctx.SetErrorFlash(i18n.T(ctx.Lang(), "vote.err.restrictedPublish"))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// VotePublish 发布投票(draft → published)。草稿阶段跳过的结构校验与 fail-closed
|
||||
// 内容审核在此统一补齐,确保对外公开内容仍受管控。
|
||||
func VotePublish(ctx context.Context) {
|
||||
@@ -915,17 +939,7 @@ func VotePublish(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 站方处置:L2 起不得再发布新的公开内容(与「设公开」同口径)。
|
||||
// 此前投票链路完全没有处置校验:被处置的箱主仍能发新投票并进探索页曝露。
|
||||
level, _, err := db.Restrictions.ActiveLevel(ctx.Request().Context(), ctx.User.ID)
|
||||
if err != nil {
|
||||
logrus.WithContext(ctx.Request().Context()).WithError(err).Error("Failed to query user restriction")
|
||||
ctx.SetInternalErrorFlash()
|
||||
ctx.Redirect("/user/questions#votes")
|
||||
return
|
||||
}
|
||||
if db.RestrictionAtLeast(level, db.RestrictionL2) {
|
||||
ctx.SetErrorFlash(i18n.T(ctx.Lang(), "vote.err.restrictedPublish"))
|
||||
if !canPublishVote(ctx) {
|
||||
ctx.Redirect("/user/questions#votes")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user