fish2018/pansou · error
[ ] 请求来源不被允许
Error message
[%s] 请求来源不被允许
What it means
The huban plugin's Search checks the caller-supplied referer against an allow-list (anti-hotlink protection); if the referer is not allowed, it refuses to perform the search. This mirrors the site's own Referer check — requests that look like they don't come from permitted origins are rejected.
Solutions
- Set the caller's Referer header to one of the plugin's allowed origins (see the allowed list near the check in huban.go).
- Run with DebugLog enabled to see which referer string was rejected and why.
- Update the allow-list configuration to include your legitimate origin.
- If referer checking is unwanted in your deployment, disable/bypass the check explicitly rather than sending arbitrary referers.
Example fix
// before
req.Header.Set("Referer", req.Host) // rejected by allow-list
result, err := p.Search(keyword, ext)
// after
req.Header.Set("Referer", "https://your-allowed-origin.example/")
result, err := p.Search(keyword, ext) Defensive patterns
Strategy: validation
Validate before calling
req.Header.Set("Referer", "https://allowed-origin.example/")
if !isRefererAllowed(req.Header.Get("Referer")) {
return errors.New("referer not in huban allow-list")
} Type guard
func isRefererAllowed(referer string) bool {
for _, a := range allowedReferers {
if strings.HasPrefix(referer, a) {
return true
}
}
return false
} Try / catch
results, err := p.Search(keyword, ext)
if err != nil {
if strings.Contains(err.Error(), "请求来源不被允许") {
return errors.New("configure an allowed Referer before calling huban search")
}
return err
} Prevention
- Always set a Referer matching one of the plugin's allowed origins
- Strip/rewrite user-supplied Referer at your proxy before it reaches the plugin
- Enable DebugLog once during setup to confirm the accepted referer value
- Document the allow-list in your deployment config so it is updated with origin changes
When it happens
Trigger: Calling p.Search(keyword, ext) (SearchWithResult path) with a referer header that fails the plugin's allowed-referer test; the plugin logs '拒绝来自 %s 的请求' when DebugLog is enabled and returns this error.
Common situations: Frontend/proxy forwarding a user's actual Referer through to the plugin; missing or wrong referer configuration; embedding the plugin behind a different domain than the allow-list expects.
Understand the failure class
Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/628f71c289044ac3.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/huban/huban.go:162
}
// 检查referer是否在允许列表中
allowed := false
for _, allowedReferer := range AllowedReferers {
if strings.HasPrefix(referer, allowedReferer) {
if DebugLog {
fmt.Printf("[%s] 允许来自 %s 的请求\n", p.Name(), referer)
}
allowed = true
break
}
}
if !allowed {
if DebugLog {
fmt.Printf("[%s] 拒绝来自 %s 的请求\n", p.Name(), referer)
}
return nil, fmt.Errorf("[%s] 请求来源不被允许", p.Name())
}
}
result, err := p.SearchWithResult(keyword, ext)
if err != nil {
return nil, err
}
return result.Results, nil
}
// SearchWithResult 带结果统计的搜索接口
func (p *HubanAsyncPlugin) SearchWithResult(keyword string, ext map[string]interface{}) (model.PluginSearchResult, error) {
return p.AsyncSearchWithResult(keyword, p.searchImpl, p.MainCacheKey, ext)
}
// searchImpl 搜索实现 - HTML解析版本
func (p *HubanAsyncPlugin) searchImpl(client *http.Client, keyword string, ext map[string]interface{}) ([]model.SearchResult, error) {
// 性能统计View on GitHub (pinned to beaa561337)