1
文件
Hubert Chen 10fa599481 update rules
waf:
    use challenge instead of block
cache:
    update new URL and URI path
2025-12-06 20:54:12 +08:00
..
2025-12-06 20:54:12 +08:00
2025-12-06 20:54:12 +08:00

Cloudflare 的 WAF 規則,用於防止爬蟲與其他用途

Warning

套用規則前請替換對應的域名,並將採取措施設爲 托管质询 / Managed Challenge 規則中也不允許註釋,記得刪掉

使用方法:前往 Cloudflare Dashboard > 域名 > 安全性 > 安全规则 > 创建规则 > 编辑表达式

default.clj ⬅️ 點擊鏈接查看完整規則

配置前部分指定哪些域名的哪些路徑或其他規則不允許被訪問,後部分設定觸發規則的請求參數

(
  ( # Gitea
    http.host eq "gitea.trle5.xyz" and (
      (
        http.request.uri.path contains "/archive/" or # 代码归档
        http.request.uri.path contains "/commit/"  or # 单个 commit 的信息
        http.request.uri.path contains "/commits/" or # commit 页面
        http.request.uri.path contains "/compare/" or # 拉取请求预览
        http.request.uri.path contains "/graph"    or # 提交图页面
        http.request.uri.path contains "/pulls/"      # 合并请求信息
      ) or (
        # 搜索和过滤方式
        http.request.uri.query contains "q=" and not (
          # 这里防止自己登进首页看不到仓库信息
          http.request.uri.path eq "/repo/search"
        )
      )
    )
  ) or
  ( # AList
    http.host eq "alist.trle5.xyz" and not (
      http.request.uri.path contains "/api/"    or
      http.request.uri.path contains "/assets/" or
      http.request.uri.path contains "/d/"      or # 防止直接下载文件时触发质询
      http.request.uri.path contains "/static/"
    )
  )
)
# 移除了其他规则限制

對於 Gitea 規則大致是:

  • 查看单个 commit 修改內容时需要验证
  • 以某个 commit 作为时间节点查看全部文件需要验证(最新文件和任意分支不受影响)
    • 爬虫通过一次验证后能不能继续爬有待观察
  • 查看合并请求预览页面需要验证
  • 下载归档需要验证(分支和任意 commit)
    • 有待观察?
  • 筛选或搜索时需要验证