fix: 修复 SpamBlock 配置越权 (#352)
This commit is contained in:
parent
87d3ce35d3
commit
da55756917
@ -63,6 +63,9 @@ func (s *SpamBlock) SettingsHtml(ctx *context.Context, url string, requestData s
|
|||||||
}
|
}
|
||||||
return fmt.Sprintf(index, s.cfg.ApiURL, s.cfg.ApiTimeout, s.cfg.Threshold)
|
return fmt.Sprintf(index, s.cfg.ApiURL, s.cfg.ApiTimeout, s.cfg.Threshold)
|
||||||
}
|
}
|
||||||
|
if !ctx.IsAdmin {
|
||||||
|
return "No Access Privileges"
|
||||||
|
}
|
||||||
|
|
||||||
var cfg SpamBlockConfig
|
var cfg SpamBlockConfig
|
||||||
var tempCfg map[string]string
|
var tempCfg map[string]string
|
||||||
|
|||||||
18
server/hooks/spam_block/spam_block_test.go
Normal file
18
server/hooks/spam_block/spam_block_test.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Jinnrry/pmail/utils/context"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSettingsHtmlRejectsNonAdminSave(t *testing.T) {
|
||||||
|
s := &SpamBlock{}
|
||||||
|
result := s.SettingsHtml(&context.Context{}, "SpamBlock/save", `{"url":"https://model.example.com/predict"}`)
|
||||||
|
if result != "No Access Privileges" {
|
||||||
|
t.Fatalf("non-admin save result = %q, want access denial", result)
|
||||||
|
}
|
||||||
|
if s.cfg.ApiURL != "" {
|
||||||
|
t.Fatal("non-admin save changed the configuration")
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user