安全加固: - 系统配置 API 增加写入 key 白名单,防止任意配置注入 - ADMIN_TOKEN 最小长度要求 16 字符 - 补充安全响应头(X-Content-Type-Options, X-Frame-Options, Referrer-Policy) - /api/users/[id] 和 /api/limits 增加 token 鉴权 - console.error 敏感信息脱敏(config route) - 敏感值 mask 修复短值完全隐藏 输入校验: - admin 渠道接口校验 rate_multiplier > 0、sort_order >= 0、name 非空 - admin 订阅套餐接口校验 price > 0、validity_days > 0、sort_order >= 0 金额精度: - feeRate 字段精度从 Decimal(5,2) 提升到 Decimal(5,4) - calculatePayAmount 返回 string 避免 Number 中间转换精度丢失 - 支付宝查询订单增加金额有效性校验(isFinite && > 0) UI 统一: - 订阅管理「售卖」列改为 toggle switch 开关(与渠道管理一致) - 表单中 checkbox 改为 toggle switch - 列名统一为「启用售卖」,支持直接点击切换
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { NextResponse } from 'next/server';
|
||
import type { NextRequest } from 'next/server';
|
||
|
||
export function middleware(request: NextRequest) {
|
||
const response = NextResponse.next();
|
||
|
||
// 自动从 SUB2API_BASE_URL 提取 origin,允许 Sub2API 主站 iframe 嵌入
|
||
const sub2apiUrl = process.env.SUB2API_BASE_URL || '';
|
||
const extraOrigins = process.env.IFRAME_ALLOW_ORIGINS || '';
|
||
|
||
const origins = new Set<string>();
|
||
|
||
if (sub2apiUrl) {
|
||
try {
|
||
origins.add(new URL(sub2apiUrl).origin);
|
||
} catch {
|
||
// ignore invalid URL
|
||
}
|
||
}
|
||
|
||
for (const s of extraOrigins.split(',')) {
|
||
const trimmed = s.trim();
|
||
if (trimmed) origins.add(trimmed);
|
||
}
|
||
|
||
if (origins.size > 0) {
|
||
response.headers.set('Content-Security-Policy', `frame-ancestors 'self' ${[...origins].join(' ')}`);
|
||
}
|
||
|
||
response.headers.set('X-Content-Type-Options', 'nosniff');
|
||
response.headers.set('X-Frame-Options', 'SAMEORIGIN');
|
||
response.headers.set('Referrer-Policy', 'strict-origin-when-cross-origin');
|
||
|
||
return response;
|
||
}
|
||
|
||
export const config = {
|
||
matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
|
||
};
|