安全审计与加固:爱发电回调防投毒、回调日志封顶、令牌定长比较、转义补全;nginx 安全头 / 挡备份与原始内容文件(片段 + 文档)
- 没验证过的爱发电回调不再写进账本 pay_orders,只进 50 条封顶的待核对清单;回调日志只记关键头 + 正文 4KB、5MB 轮转(测试 +2) - 福利券领取令牌定长比较;ys_admin.py 转义补上引号;星门格子提示转义;首页价格改读公开接口 - nginx 片段:安全头(HSTS/nosniff/XFO/Referrer/Permissions/CSP)、挡备份 / 预览稿 / 隐藏文件 / 原始内容 json、回调单独限流、server_tokens off - 交接文档 2.9 安全加固 + 维护页挂法更新 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -132,3 +132,36 @@ location /order/ {
|
|||||||
防护全在后端自己的限流 + 两把令牌 + 来源 IP 门上。
|
防护全在后端自己的限流 + 两把令牌 + 来源 IP 门上。
|
||||||
- **没做多机/负载均衡**:单机单进程,够用。
|
- **没做多机/负载均衡**:单机单进程,够用。
|
||||||
- **HTTPS 用自动签发的证书**,续期自动化,没有额外动作。
|
- **HTTPS 用自动签发的证书**,续期自动化,没有额外动作。
|
||||||
|
|
||||||
|
|
||||||
|
## ⑤ 安全加固(2026-10-06,线上已加)
|
||||||
|
|
||||||
|
```nginx
|
||||||
|
# 文件:/etc/nginx/snippets/jz-sec-base.conf
|
||||||
|
add_header Strict-Transport-Security "max-age=31536000" always;
|
||||||
|
add_header X-Content-Type-Options "nosniff" always;
|
||||||
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||||
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||||
|
add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=(), usb=()" always;
|
||||||
|
|
||||||
|
# 文件:/etc/nginx/snippets/jz-sec-csp.conf(只给本站页面)
|
||||||
|
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: https:; media-src 'self' blob:; font-src 'self' data:; connect-src 'self'; frame-src https://player.bilibili.com; worker-src 'self' blob:; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'" always;
|
||||||
|
|
||||||
|
# server 块里:
|
||||||
|
include snippets/jz-sec-base.conf;
|
||||||
|
include snippets/jz-sec-csp.conf;
|
||||||
|
location ~* (\.bak[^/]*|\.maint[^/]*|\.old[^/]*|\.orig|\.swp|~|\.v[0-9]+-(live|new)[^/]*)$ { return 404; }
|
||||||
|
location ~* ^/(order/)?preview-[^/]*\.html$ { return 404; }
|
||||||
|
location ~ /\.(?!well-known/) { return 404; }
|
||||||
|
location = /content/site.json { return 404; }
|
||||||
|
location = /order/content/order.json { return 404; }
|
||||||
|
# 回调单独限流(http 级:limit_req_zone $binary_remote_addr zone=jzhook:1m rate=20r/m;)
|
||||||
|
location ~ ^/order/api/(payplatform|afdian)-hook$ {
|
||||||
|
limit_req zone=jzhook burst=10 nodelay; limit_req_status 429; client_max_body_size 64k;
|
||||||
|
rewrite ^/order/api/(.*)$ /api/$1 break; proxy_pass http://localhost:<PORT>;
|
||||||
|
proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
add_header Cache-Control "no-store" always; include snippets/jz-sec-base.conf;
|
||||||
|
}
|
||||||
|
# ⚠️ 每个自己写了 add_header 的 location 里都要再 include 上面两个文件(nginx 不继承 server 级的 add_header)
|
||||||
|
# nginx.conf 的 http 块:server_tokens off;
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user