- 六协议调试:HTTP/GraphQL/WebSocket/SSE/Socket.IO/MQTT
- 集合树/多标签/多环境变量/历史记录,localStorage 持久化
- 导入:OpenAPI 2/3/3.1、Postman、Apifox、Apipost、cURL、HAR、
Insomnia、Hoppscotch、Markdown(自动识别,21 个单测覆盖)
- 导出:OpenAPI 3.0 JSON/YAML、Postman v2.1、Markdown 文档、
全量备份;单请求生成 cURL/fetch/Python/Go 代码
- Gin 服务:HTTP 代理、NDJSON 流式代理(SSE 透传)、
WebSocket 隧道(浏览器自定义握手 Header)
- 内置产品官网 /home 与用户文档站 /docs(SSR,随二进制交付)
- lucide 图标体系 + 品牌标识(Logo/favicon),明暗双主题
- 环境变量:彩色徽标切换器、管理弹窗、{{ 自动补全
37 lines
989 B
Go
37 lines
989 B
Go
package proxy
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
var blockedHosts = map[string]struct{}{
|
|
"169.254.169.254": {},
|
|
"metadata.google.internal": {},
|
|
}
|
|
|
|
// ValidateURL applies MVP SSRF basics. Week 2 should add configurable CIDR
|
|
// deny-lists and DNS-rebinding protection before exposing this beyond localhost.
|
|
func ValidateURL(raw string) (*url.URL, error) {
|
|
u, err := url.Parse(raw)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("invalid url: %w", err)
|
|
}
|
|
if u.Scheme != "http" && u.Scheme != "https" {
|
|
return nil, fmt.Errorf("only http/https schemes are allowed")
|
|
}
|
|
if u.Hostname() == "" {
|
|
return nil, fmt.Errorf("url host is required")
|
|
}
|
|
host := strings.ToLower(strings.TrimSuffix(u.Hostname(), "."))
|
|
if _, blocked := blockedHosts[host]; blocked {
|
|
return nil, fmt.Errorf("blocked metadata host")
|
|
}
|
|
if ip := net.ParseIP(host); ip != nil && ip.Equal(net.ParseIP("169.254.169.254")) {
|
|
return nil, fmt.Errorf("blocked metadata address")
|
|
}
|
|
return u, nil
|
|
}
|