限制Linux管理服务回环监听并补齐安全回归
This commit is contained in:
1 parent
0b74886c45
commit
1150c3904e
13 files changed
+233
-4
No files matched your search
@@ -54,6 +54,9 @@ func New(ctx context.Context, cfg config.Config) (*App, error) {
|
||||
}
|
||||
|
||||
func NewWithConfigPath(ctx context.Context, cfg config.Config, configPath string) (*App, error) {
|
||||
if err := cfg.ValidateServerListener(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !cfg.SetupReady {
|
||||
return nil, fmt.Errorf("系统尚未初始化,请先启动 scert serve 完成首次配置")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/config"
|
||||
)
|
||||
|
||||
func TestNewRejectsNonLoopbackBeforeCreatingResources(t *testing.T) {
|
||||
cfg := config.Default(t.TempDir())
|
||||
cfg.SetupReady = true
|
||||
cfg.Server.Host = "::"
|
||||
application, err := NewWithConfigPath(context.Background(), cfg, "")
|
||||
if application != nil || err == nil || !strings.Contains(err.Error(), "只允许监听回环") {
|
||||
t.Fatalf("正式服务入口未在创建资源前拒绝非回环监听:%v", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user