🏰

Sub-Bridge Fortress

多用户订阅转换、高防扫路径与边缘 Cache API 智能缓存要塞

net.xzgg.us.kg要塞防线版
用户通道:

终极要塞安全风控与订阅转换设置

/

💡 终极安全:对外发放的订阅链接将直接采用此防扫字串(如 `/7gkA29`),使攻击者绝对无法扫出您的后台或猜测他人订阅!

1

🛡️ 要塞防线安全访问限制 (Fortress Pro)

快捷设置有效期:

🚀 专属分发订阅链接

🎯 所见即所得匹配预览

实时
原始: 🟢 极速 香港 HK-01 (IEPL)✅ 保留
原始: 🟢 极速 香港 HK-02 (IEPL)✅ 保留
原始: 🟢 极速 香港 HK-03 (IEPL)✅ 保留
原始: 🔵 优质 日本 JP-01 (BGP)✅ 保留
原始: 🔵 优质 日本 JP-02 (BGP)✅ 保留
原始: 🔴 稳定 美国 US-01 (Anycast)✅ 保留
原始: 🔴 稳定 美国 US-02 (Anycast)✅ 保留
原始: 🟡 畅游 新加坡 SG-01 (BGP)✅ 保留
原始: 🟣 GPT 专线 - 香港 HK-OpenAI✅ 保留
原始: 🟣 GPT 专线 - 日本 JP-OpenAI✅ 保留
原始: 🟠 Claude 专线 - 美国 US-Claude✅ 保留
原始: 🟠 Claude 专线 - 新加坡 SG-Claude✅ 保留
原始: 🎨 TikTok 专线 - 美国 TikTok✅ 保留
🏰

Cloudflare Workers 边缘中转 Cache API 缓存代码生成器

要塞防线版

终极要塞安全策略:**敏感 URL 完全不公开写死**,中转键名完全采用**随机 Path Key 彻底防扫**,并在边缘集成了 **Cache API 10分钟智能缓存**(高频拉取 0ms 延迟秒开,免除回源 Vercel 开销,极力防止机场抖动影响)!

/**
 * Sub-Bridge Ultimate Fortress - 要塞防线版中转代码 (Cloudflare Workers)
 * 功能特性:
 * 1. 🛡️ 【极致安全】原始 URL 完全以 Secrets 形式加密分离存储,代码库无任何敏感链接
 * 2. 🧩 【随机防扫】中转路由映射键完全采用高强度随机 Path Key,隔绝常规后台扫描
 * 3. ⚡ 【0ms秒开】集成 Cache API 边缘 10分钟智能缓存,防机场网络抖动,减少 Vercel 回源开销
 * 4. 📊 【状态传递】智能传递流量状态进度条 (subscription-userinfo) 与自动更新头
 */

export default {
  async fetch(request, env, ctx) {
    const url = new URL(request.url);
    const userAgent = request.headers.get("user-agent") || "";
    const userPath = url.pathname.replace("/", "").trim().toLowerCase();

    // 1. 无状态随机 Path Key 属性配置表 (由 Vercel Dashboard 自动生成)
    const USERS = {

    };

    // 2. 匹配防扫随机路径
    if (!userPath || !USERS[userPath]) {
      return new Response("ERROR: Sub-Bridge 要塞防线提示:通道不存在或路径无效。", { status: 404 });
    }

    const item = USERS[userPath];

    // 3. 边缘风控第一层:管理员状态关停
    if (item.status === "banned") {
      return new Response("BANNED: This subscription channel is banned by administrator.", { status: 403 });
    }

    // 4. 边缘风控第二层:密码验证
    const clientPassword = url.searchParams.get("pwd") || url.searchParams.get("password") || "";
    if (item.password && clientPassword !== item.password) {
      return new Response("FORBIDDEN: Incorrect access credential (?pwd=xxx).", { status: 403 });
    }

    // 5. 边缘风控第三层:到期判断
    if (item.expire) {
      const now = new Date();
      const expireDate = new Date(item.expire + "T23:59:59+08:00"); // 北京东八区时间
      if (now > expireDate) {
        return new Response("EXPIRED: Your subscription channel has expired.", { status: 403 });
      }
    }

    // 6. 边缘风控第四层:正规代理软件 UA 检测
    const allowUA = ["Clash", "Shadowrocket", "Stash", "sing-box", "Surge", "Quantumult"];
    const allowed = allowUA.some(x => userAgent.toLowerCase().includes(x.toLowerCase()));
    if (!allowed) {
      return new Response("FORBIDDEN: Please fetch subscription via official proxy tools.", { status: 403 });
    }

    // 7. ⚡ 【重磅升级】边缘 Cache API 缓存机制检验 (实现 0ms 高速秒开且零回源占用)
    const cache = caches.default;
    // 以当前请求 URL (含 pwd 及格式参数) 作为缓存唯一键
    const cacheKey = new Request(url.toString(), request);
    let response = await cache.match(cacheKey);

    if (response) {
      // 缓存命中:直接返回边缘节点缓存的数据,免去网络请求回源
      const cachedHeaders = new Headers(response.headers);
      cachedHeaders.set("X-Sub-Bridge-Cache", "HIT-Edge-CDN");
      return new Response(response.body, { headers: cachedHeaders });
    }

    // 8. 缓存未命中:读取 CF Secrets 加密值拉取真实的 Vercel 订阅长链
    if (!item.sub) {
      return new Response("ERROR: Secret subscription source is not configured.", { status: 500 });
    }

    try {
      // 携带客户端原本的查询条件(Clash 格式转换)
      const vercelUrl = new URL(item.sub);
      url.searchParams.forEach((val, k) => {
        vercelUrl.searchParams.set(k, val);
      });

      const res = await fetch(vercelUrl.toString(), {
        headers: {
          "user-agent": userAgent // 穿透真实的客户端 UA,保证 Clash 分流配置智能返回
        }
      });

      if (!res.ok) {
        return new Response("ERROR: Backend subscription processor failed.", { status: 502 });
      }

      const text = await res.text();

      // 9. 组装响应并将头信息设置为在 CDN 边缘强行缓存 10分钟 (600秒)
      const headers = new Headers({
        "content-type": "text/plain;charset=utf-8",
        "subscription-userinfo": res.headers.get("subscription-userinfo") || "",
        "profile-update-interval": "24",
        "access-control-allow-origin": "*",
        "cache-control": "public, s-maxage=600", // 让 Cloudflare CDN 强缓存 10分钟
        "X-Sub-Bridge-Cache": "MISS-Loaded-New"
      });

      const newResponse = new Response(text, { status: 200, headers });

      // 异步存入全球边缘缓存,不阻塞当前的连接返回
      ctx.waitUntil(cache.put(cacheKey, newResponse.clone()));

      return newResponse;

    } catch (err) {
      return new Response("ERROR: Edge bridge connection failed: " + err.message, { status: 500 });
    }
  }
};
🔑

Cloudflare 环境变量 (Variables & Secrets) 一键配置对照表

请前往您的 Cloudflare Worker 控制台 ➔ Settings ➔ Variables ➔ Add Variable,依次将下方左侧的 **加密变量名** 填入 Name,将右侧的 **真实的 Vercel 订阅链接** 填入 Value (并点击 **Encrypt** 加密):

CF 变量名 (Name)真实 Vercel 脱敏分发源 (Value)一键复制