Api Proxy Safety logo

Api Proxy Safety

CommunityPopular
doccker
api-proxy-safety

网关/代理/WAF/CDN 中间件的安全关键词匹配实现规范,防止纯子串匹配误判正常响应内容中的技术术语(如 Cloudflare、502、error)

Overview

Publisherdoccker
Repositorycc-use-exp
Skill nameapi-proxy-safety
Stars
1.1K
Forks
116
Bundled files
Instructions only
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by doccker on GitHub. Read the source before you install it.

Installation

Install the Api Proxy Safety AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/doccker/cc-use-exp/tree/main/.claude/skills/api-proxy-safety
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/doccker/cc-use-exp.git /tmp/cc-use-exp
mkdir -p .claude/skills
cp -r /tmp/cc-use-exp/.claude/skills/api-proxy-safety .claude/skills/api-proxy-safety
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Api Proxy Safety in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Api Proxy Safety on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Api Proxy Safety is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

API 代理安全关键词匹配规范

网关/WAF/CDN 中间件实现关键词匹配时,避免纯子串匹配导致正常响应内容被误判。


核心问题

纯子串匹配的误判

go
// ❌ 误判:纯子串匹配,长正文中的正常用词也会命中
var pseudoSuccessPatterns = []string{
    "cloudflare",
    "502 bad gateway",
    "bad gateway",
    "reconnecting",
    "upstream error",
}

当业务响应正文包含这些关键词的字面值(如文章主题就是 "Cloudflare"),纯子串匹配会触发误判,导致:

  • 正常响应被当作伪成功错误
  • 触发站点切换 / 上游降级
  • 错误标记模型/节点不可用

关键事实:关键词出现在长正文中 ≠ 响应存在问题。


解决方案:强/弱特征拆分 + 分层判定

将关键词按风险特征拆分为两组,并配合 HTTP 元数据做分层判定:

分层判定原则(推荐)

使用正文关键词匹配前,先通过 HTTP 元数据排除绝大多数正常响应:

判定层检查项优先级
1. HTTP status2xx=正常, 5xx/429/某些403=错误最高
2. Content-Typetext/event-stream 保持流式处理, application/json 检查 schema↑
3. 响应 schema / 错误字段JSON 中 error.code / error.message / success:false 等↑
4. 正文关键词匹配强/弱特征,仅作为启发式证据,不作为唯一事实最低

正文关键词只是启发式证据:正常用户内容可能包含技术术语字面值(如 Cloudflare、502、bad gateway),关键词命中不必然等于响应错误,必须结合 status/schema 做综合判断。

强特征(任何长度命中)

完整错误语句或 HTML 错误页特征。这些模式极长且内容特殊,正常用户内容中几乎不可能出现,可任意长度命中:

特征说明
exceeded retry limit, last status: 429 too many requests完整 429 错误句
must be enabled in your dashboard first完整仪表盘引导句
unexpected status 502 bad gateway: error code: 502完整 502 错误句(含 UUID)
<html / <title>5 / cf-ray:HTML 错误页特征
go
var pseudoSuccessChatStrongPatterns = []string{
    "exceeded retry limit, last status: 429 too many requests",
    "must be enabled in your dashboard first",
    "unexpected status 502 bad gateway: error code: 502",
    "reconnecting...",
    "<html",
    "<title>5",
    "cf-ray:",
}

弱特征(仅 ≤512 字节内容命中)

单词级或短语级关键词。极短内容(≤512 字节)中命中才判为错误,避免长正文中技术术语误判:

特征说明
429 too many requests短版 429
502 bad gateway / bad gateway短版 502
upstream error / upstream connect error上游错误
just a momentCDN 挑战
cloudflareCDN 品牌名
must be enabled in your dashboard first短版引导句
go
var pseudoSuccessChatWeakPatterns = []string{
    "429 too many requests",
    "502 bad gateway",
    "bad gateway",
    "upstream error",
    "upstream connect error",
    "just a moment",
    "cloudflare",
    "must be enabled in your dashboard first",
}

判定逻辑

go
func containsPseudoSuccessInChatResponse(content string) bool {
    // 先检查 HTTP status 和响应 schema(应有上层调用保证)
    // 正文关键词仅作为启发式证据

    // 强特征:任何长度命中
    for _, p := range pseudoSuccessChatStrongPatterns {
        if strings.Contains(strings.ToLower(content), p) {
            return true
        }
    }
    // 弱特征:仅 ≤512 字节命中
    if len(content) > 512 {
        return false
    }
    low := strings.ToLower(content)
    for _, p := range pseudoSuccessChatWeakPatterns {
        if strings.Contains(low, p) {
            return true
        }
    }
    return false
}

不同场景的匹配策略

场景策略原因
聊天响应正文(长文本)强特征任意长度 + 弱特征仅 ≤512 字节命中正文可能包含技术术语字面值
错误消息(短文本)全量匹配,无需长度限制error message 本身很短,且不含正常用户内容
流式响应片段(分块)参考 HTTP streaming 分类目标实现等待完整块再匹配,或按内容格式切割后匹配

隐含缺陷判定

实现关键词匹配时,用以下问题自检:

  • 匹配的关键词在正常用户内容中是否可能出现?
  • 如果出现,是否按正文长度做了分级?
  • 同样关键词出现在短错误消息 vs 长正常文章里,判定逻辑是否不同?
  • 是否有回归测试覆盖长正文误判场景?

自测案例:

内容长度正确判定说明
"exceeded retry limit, last status: 429 too many requests"短错误强特征命中
"Cloudflare(文章主题)..." + 4657 字正文长正常弱特征+超长→不命中
"502 Bad Gateway"(纯错误)短错误弱特征+短→命中
"502 Bad Gateway: 配置 Nginx 反向代理时..." + 完整博客长正常弱特征+超长→不命中,无强特征

与相关 skill 的边界

skill关系
external-system-debugging本 skill 的上游:面对 CDN/WAF 网关行为异常时,先走外部系统方法论抓真实数据,再回来看匹配逻辑实现是否正确
api-design-safety本 skill 聚焦代理中间件的安全匹配实现,而非 API 本身的设计规范
ops-safety本 skill 不涉及运维操作安全、危险命令等

规则溯源

> 📋 本回复遵循:`api-proxy-safety` - [章节]

Frequently asked questions

What does the Api Proxy Safety AI skill do?

网关/代理/WAF/CDN 中间件的安全关键词匹配实现规范,防止纯子串匹配误判正常响应内容中的技术术语(如 Cloudflare、502、error)

Why use Api Proxy Safety on TypingMind?

Because you install it once and use it with any model. Api Proxy Safety is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Api Proxy Safety in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/doccker/cc-use-exp/tree/main/.claude/skills/api-proxy-safety. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Api Proxy Safety?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Api Proxy Safety?

As many as you like. As long as a model supports skills, you can use Api Proxy Safety with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Api Proxy Safety AI skill free?

It is published on GitHub by doccker. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇