diff --git a/frontend/nginx.conf b/frontend/nginx.conf index 9e1ccd1..80dcbb3 100644 --- a/frontend/nginx.conf +++ b/frontend/nginx.conf @@ -30,7 +30,10 @@ server { application/xml application/rss+xml image/svg+xml font/ttf font/otf; # 安全头配置 - add_header X-Frame-Options "SAMEORIGIN" always; + # 防嵌入(T303 K2,2026-11-25):X-Frame-Options SAMEORIGIN 换成 CSP frame-ancestors 白名单—— + # 允许本站自嵌('self')、统一工作台(本机联调口 + well-trust.com 子域正式口)把主站装进画框; + # 其余站点照旧拒绝。host 不带端口即匹配任意端口;/embed/ 挂件的按渠道策略不受影响(见下)。 + add_header Content-Security-Policy "frame-ancestors 'self' http://127.0.0.1:* http://localhost:* https://*.well-trust.com http://*.well-trust.com" always; add_header X-Content-Type-Options "nosniff" always; add_header X-XSS-Protection "1; mode=block" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; @@ -92,8 +95,8 @@ server { # index.html 及 SPA fallback 不可缓存,否则前端升级后用户看不到新版本 add_header Cache-Control "no-cache, must-revalidate" always; - # nginx add_header 不从上层继承,需要在 location 内重复声明安全头 - add_header X-Frame-Options "SAMEORIGIN" always; + # nginx add_header 不从上层继承,需要在 location 内重复声明安全头(T303 K2:与 server 级同款白名单) + add_header Content-Security-Policy "frame-ancestors 'self' http://127.0.0.1:* http://localhost:* https://*.well-trust.com http://*.well-trust.com" always; add_header X-Content-Type-Options "nosniff" always; add_header X-XSS-Protection "1; mode=block" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; diff --git a/frontend/src/views/auth/Login.vue b/frontend/src/views/auth/Login.vue index 4fc9be1..18ff666 100644 --- a/frontend/src/views/auth/Login.vue +++ b/frontend/src/views/auth/Login.vue @@ -631,6 +631,23 @@ const loadOIDCConfig = async () => { if (!oidcPasswordEnabled.value) { loginMode.value = 'local' } + // 统一登录自动发起(T303 K5,2026-11-25 用户拍板:OIDC 跳转为登录主路径,工号密码直登留兜底): + // 后端报告 OIDC 启用、未登录、非邀请链接场景时,自动跳一次身份源;已有 IdP 会话即静默通过 + // (这就是「登录一次」)。一次浏览器会话只自动一次,标记在「已登录进入应用」处清除(见 + // onMounted),登出后可再次自动发起;手动点 OIDC 按钮不受标记限制。 + // 2026-11-29 收窄(hxops 8c91c6e8 同款拍板):自动发起仅限画框场景(统一工作台嵌入, + // 判据=window.self !== window.top)——顶层直接访问 kbt 的用户不被强拽去身份源,停在本页自选。 + if ( + oidcEnabled.value && + !authStore.isLoggedIn && + !inviteToken.value && + window.self !== window.top && + !new URLSearchParams(window.location.search).has('local') && + !sessionStorage.getItem('academy_sso_auto_tried') + ) { + sessionStorage.setItem('academy_sso_auto_tried', '1') + void handleOIDCLogin() + } } // 切换工号/邮箱模式:清空两套字段与校验痕迹,防止串台。 @@ -670,7 +687,13 @@ const handleOIDCLogin = async () => { if (inviteToken.value) { sessionStorage.setItem('academy_pending_invite_token', inviteToken.value) } - window.location.href = authorizationURL + // 画框内追加 Casdoor 静默签发参数(2026-11-29,hxops silentSignin 同款):已有 IdP 会话 + // 即一闪直过不发登录页;顶层手动 OIDC 不带(跳转可见属预期)。 Casdoor 老构建不认 + // prompt=none,自家 silentSignin 参数是当前构建可用的静默通道。 + const isEmbedded = window.self !== window.top + window.location.href = isEmbedded + ? `${authorizationURL}${authorizationURL.includes('?') ? '&' : '?'}silentSignin=1` + : authorizationURL } catch (error: any) { console.error('OIDC 登录跳转失败:', error) MessagePlugin.error(error.message || t('auth.oidcLoginFailed')) @@ -852,6 +875,8 @@ onMounted(async () => { } if (authStore.isLoggedIn) { + // 已登录进入应用:清掉「统一登录自动发起」的一次性标记(T303 K5),登出后可再次自动发起。 + sessionStorage.removeItem('academy_sso_auto_tried') router.replace('/platform/creatChat') return }