From 311753689ae0769e55e13dedcfec5b90549aba57 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 25 Aug 2026 15:01:21 +0800 Subject: [PATCH] =?UTF-8?q?security:=20fetch=5Fforex=5Frates.dspy=20?= =?UTF-8?q?=E5=8A=A0=20localhost=20=E6=A0=A1=E9=AA=8C(=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=85=A5=E5=8F=A3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 该端点授权给 any 且无任何鉴权,会发起外网抓取(BOC 页面)并写 exchange_rate 表, 匿名可反复触发 → 外部请求放大 + 脏数据写入 + DoS。改为仅本机可调(client_ip)。 build.sh 的 crontab 本就是 curl localhost:9090,不影响定时任务。 --- wwwroot/api/fetch_forex_rates.dspy | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/wwwroot/api/fetch_forex_rates.dspy b/wwwroot/api/fetch_forex_rates.dspy index bebeb9a..41ea5b0 100644 --- a/wwwroot/api/fetch_forex_rates.dspy +++ b/wwwroot/api/fetch_forex_rates.dspy @@ -1,5 +1,15 @@ # 获取中国银行外汇牌价并插入 exchange_rate 表 # GET /accounting/api/fetch_forex_rates.dspy +# +# 安全:本端点是定时任务入口(会发起外网抓取 + 写库),只允许本机调用。 +# 之前无任何鉴权且授权给 any 角色,匿名可反复触发 → 外部抓取放大 + 脏数据写入 + DoS。 +# 判定依据 client_ip:nginx 用 $proxy_add_x_forwarded_for 追加模式、中间件取链尾值, +# 外部伪造 X-Forwarded-For 会被追加真实 IP 到链尾,伪造不成立;且应用端口不对外开放。 +_ip = request.get('client_ip') or '' +if _ip not in ('127.0.0.1', '::1', 'localhost'): + return json.dumps({'success': False, 'message': '仅允许本机调用(定时任务入口)'}, + ensure_ascii=False) + import re import urllib.request from datetime import date