fix(配置): 修改 URL 安全配置默认值为开发友好模式
调整以下配置的默认值以匹配 .env.example: - allow_insecure_http: false → true (允许 HTTP URL) - allow_private_hosts: false → true (允许本地/私有 IP) **改动说明:** - 默认允许 HTTP URL,方便开发测试环境使用 - 默认允许本地和私有 IP 地址 - 与 deploy/.env.example 中的推荐配置保持一致 - 更新相应的单元测试以验证新的默认值 **安全提示:** ⚠️ 这些默认值适合开发/测试环境 ⚠️ 生产环境建议显式配置更严格的安全策略 ⚠️ HTTP 存在明文传输风险,仅在可信网络中使用 **测试结果:** - ✅ 所有单元测试通过 - ✅ golangci-lint 无问题 相关文件: - backend/internal/config/config.go:451-452 - backend/internal/config/config_test.go:83-88 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -448,8 +448,8 @@ func setDefaults() {
|
||||
"raw.githubusercontent.com",
|
||||
})
|
||||
viper.SetDefault("security.url_allowlist.crs_hosts", []string{})
|
||||
viper.SetDefault("security.url_allowlist.allow_private_hosts", false)
|
||||
viper.SetDefault("security.url_allowlist.allow_insecure_http", false)
|
||||
viper.SetDefault("security.url_allowlist.allow_private_hosts", true)
|
||||
viper.SetDefault("security.url_allowlist.allow_insecure_http", true)
|
||||
viper.SetDefault("security.response_headers.enabled", false)
|
||||
viper.SetDefault("security.response_headers.additional_allowed", []string{})
|
||||
viper.SetDefault("security.response_headers.force_remove", []string{})
|
||||
|
||||
@@ -80,8 +80,11 @@ func TestLoadDefaultSecurityToggles(t *testing.T) {
|
||||
if cfg.Security.URLAllowlist.Enabled {
|
||||
t.Fatalf("URLAllowlist.Enabled = true, want false")
|
||||
}
|
||||
if cfg.Security.URLAllowlist.AllowInsecureHTTP {
|
||||
t.Fatalf("URLAllowlist.AllowInsecureHTTP = true, want false")
|
||||
if !cfg.Security.URLAllowlist.AllowInsecureHTTP {
|
||||
t.Fatalf("URLAllowlist.AllowInsecureHTTP = false, want true")
|
||||
}
|
||||
if !cfg.Security.URLAllowlist.AllowPrivateHosts {
|
||||
t.Fatalf("URLAllowlist.AllowPrivateHosts = false, want true")
|
||||
}
|
||||
if cfg.Security.ResponseHeaders.Enabled {
|
||||
t.Fatalf("ResponseHeaders.Enabled = true, want false")
|
||||
|
||||
Reference in New Issue
Block a user