Documentation
¶
Index ¶
- Variables
- func BuildCookieHeader(cookies []CookieItem) string
- func CheckReferer(allowedReferers []string, ctx *gin.Context) bool
- func ExtractHost(rawURL string) (string, error)
- func IsAllowed(allowedReferers []string, host string) bool
- func IsUnsafeHost(ctx context.Context, host string) bool
- func NewModuleLogger(moduleName string) *slog.Logger
- type CookieItem
- type DecryptResult
Constants ¶
This section is empty.
Variables ¶
var ErrUnsafeHost = errors.New("host resolves to a blocked (internal/loopback/link-local) address")
ErrUnsafeHost 表示目标主机解析到禁止访问的保留地址,已被 SSRF 防护拦截。
Functions ¶
func BuildCookieHeader ¶
func BuildCookieHeader(cookies []CookieItem) string
BuildCookieHeader 将 Cookie 列表拼接为 Cookie 请求头值
func CheckReferer ¶ added in v1.5.0
CheckReferer 提取请求中的 Referer 头,校验其 host 是否在白名单中。 若 Referer 为空、解析失败或不在白名单,返回 false。
func IsUnsafeHost ¶ added in v1.7.0
IsUnsafeHost 判断 host(域名或 IP 字面量,不带端口)是否禁止外连。 解析出的任一地址命中保留地址段即返回 true;解析失败或超时同样返回 true(fail-closed,宁可拒绝也不放过)。
func NewModuleLogger ¶ added in v1.4.0
NewModuleLogger 为指定模块创建一个带模块名的 slog.Logger。 所有通过该 logger 输出的日志会自动带上 "module=<name>" 属性。
用法示例:
var log = utils.NewModuleLogger("mymodule")
log.Info("started", "port", 8080)
// 输出: time=... level=INFO msg=started module=mymodule port=8080
Types ¶
type CookieItem ¶
type CookieItem struct {
Name string `json:"name"`
Value string `json:"value"`
Domain string `json:"domain,omitempty"`
Path string `json:"path,omitempty"`
Expires int64 `json:"expires,omitempty"`
HTTPOnly bool `json:"httpOnly"`
Secure bool `json:"secure"`
SameSite string `json:"sameSite,omitempty"`
}
CookieItem 单个 Cookie 条目
func CookieCloud ¶
func CookieCloud(ctx context.Context, host, uuid, password, cryptoType string) ([]CookieItem, error)
CookieCloud 从远端 CookieCloud 服务获取并解密 Cookie host: 服务地址,如 "https://cookie.example.com" uuid: 用户标识 password: 解密密码 cryptoType: 加密算法,空字符串或 "legacy" 为旧算法,"aes-128-cbc-fixed" 为新算法
func FilterCookiesByDomain ¶
func FilterCookiesByDomain(cookies []CookieItem, domain string) []CookieItem
FilterCookiesByDomain 筛选指定域名的 Cookie
type DecryptResult ¶
type DecryptResult struct {
CookieData map[string][]CookieItem `json:"cookie_data"`
}
DecryptResult cookie_decrypt 的返回值结构