feat: 更新环境配置并增强 iframe 安全处理机制
修改 .env.example,优化环境切换说明,并新增 API_BASE_URL 配置项,提升配置管理能力。 更新 next.config.ts:使用 API_BASE_URL 代理 API 请求,增强开发与生产环境的灵活性。 重构 iframe-bridge 与 use-token-refresh 组件,采用新的 iframe 来源校验方法,提升安全性检查能力。 优化 csp-config.ts:动态注入允许的父级来源(parent origins)到 CSP 配置中,强化安全策略。 调整 lottery-http:通过 Next.js 代理转发 API 请求,简化 API 调用流程。
This commit is contained in:
@@ -2,6 +2,10 @@ import { useCallback, useEffect, useRef } from "react";
|
||||
|
||||
import { usePlayerSessionStore } from "@/stores/player-session-store";
|
||||
import { useErrorStore } from "@/stores/error-store";
|
||||
import {
|
||||
isIframeOriginAllowed,
|
||||
loadIframeAllowedOrigins,
|
||||
} from "@/lib/iframe-origins";
|
||||
|
||||
/** Token 过期前警告阈值(毫秒) */
|
||||
const TOKEN_WARNING_THRESHOLD = 60 * 1000; // 1 分钟
|
||||
@@ -116,21 +120,15 @@ export function useTokenRefresh(): {
|
||||
useEffect(() => {
|
||||
if (typeof window === "undefined") return;
|
||||
|
||||
const handleMessage = (event: MessageEvent): void => {
|
||||
// 安全检查:验证来源
|
||||
const allowedOrigins = [
|
||||
process.env.NEXT_PUBLIC_MAIN_SITE_URL,
|
||||
// 开发环境允许本地
|
||||
"http://localhost:3800",
|
||||
"http://127.0.0.1:3800",
|
||||
].filter(Boolean);
|
||||
void loadIframeAllowedOrigins();
|
||||
|
||||
if (
|
||||
allowedOrigins.length > 0 &&
|
||||
!allowedOrigins.includes(event.origin)
|
||||
) {
|
||||
console.warn("[TokenRefresh] Ignored message from unknown origin:", event.origin);
|
||||
return;
|
||||
const handleMessage = async (event: MessageEvent): Promise<void> => {
|
||||
if (!isIframeOriginAllowed(event.origin)) {
|
||||
await loadIframeAllowedOrigins();
|
||||
if (!isIframeOriginAllowed(event.origin)) {
|
||||
console.warn("[TokenRefresh] Ignored message from unknown origin:", event.origin);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const { data } = event;
|
||||
|
||||
Reference in New Issue
Block a user