Files
HomeDash/deploy/verify-scroll.js
HomeDash Bot b99319b38b chore(sanitize): 备案号与域名一律可配置,仓库不再预置真实域名/备案号/内网地址
用户要求:备案号与域名都应当可配置,仓库内容要脱敏。

功能(不只是替换字面量):
- 被代理页面注入的备案号改为读后台「站点信息」的 icp/gongan,**未配置就不注入**;
  原先写死具体备案号,等于每个部署者都会把别人的备案信息印到自己页面上
- 注入内容做 nginx 安全处理(去引号/反斜杠/换行/美元符),并有测试覆盖
- auth.go:PORTAL_COOKIE_DOMAIN / PORTAL_HOME_URL 不再预置域名,
  cookie 默认 host-only、首页默认相对路径 "/"
- gateway.go:默认 loginUrl 不再预置域名(受保护路由缺配置会明确报错,不静默生成跳不出去的登录页)
- 首装脚本在给了 NAVI_DOMAIN 时自动注入 PORTAL_COOKIE_DOMAIN/PORTAL_HOME_URL,
  避免"去掉写死默认值"导致跨子域单点登录失效

脱敏:内网 IP(10.0.0.10)与真实备案号清零;真实域名仅剩门户页内容 8 处(待定);
测试夹具/示例/错误页/脚本/后台占位提示全部通用化。

README:新增「跨子域单点登录需要的两个环境变量」;环境变量表改为 NAVI_HOST 必填。
测试:新增备案号注入三条(用配置、未配置不注入、危险字符清理)。
2026-09-12 10:10:52 +08:00

36 lines
2.1 KiB
JavaScript

// 目标环境通过环境变量指定,仓库不预置任何真实域名/主机。
const BASE = process.env.PORTAL_BASE || 'https://dashy.example.com';
const DOM = process.env.PORTAL_COOKIE_DOMAIN || '.example.com';
const { chromium }=require('playwright-core');
const C=process.env.PORTAL_COOKIE;
(async()=>{
const b=await chromium.connectOverCDP('http://127.0.0.1:9222');
for(const [w,h] of [[1280,720],[1280,600],[1024,600],[900,520],[768,600],[390,780]]){
const ctx=await b.newContext({ignoreHTTPSErrors:true,viewport:{width:w,height:h}});
await ctx.addCookies([{name:'portal_session',value:C,domain:DOM,path:'/',httpOnly:true,secure:true,sameSite:'Lax'}]);
const p=await ctx.newPage();
await p.emulateMedia({colorScheme:'dark'}); await p.addInitScript(()=>localStorage.removeItem('navi-theme'));
await p.goto(BASE+'/minimal',{waitUntil:'networkidle',timeout:90000}); await p.waitForTimeout(1800);
const r=await p.evaluate(()=>{
const de=document.documentElement;
const foot=document.querySelector('.navi-footer');
const fr=foot?foot.getBoundingClientRect():null;
// 谁在撑高页面
let worst=null;
for(const e of document.querySelectorAll('body *')){
const b=e.getBoundingClientRect();
if(b.height<4) continue;
if(de.scrollHeight>innerHeight+2 && b.bottom>innerHeight+2){
if(!worst||b.bottom>worst.bottom) worst={cls:e.className.toString().slice(0,60),bottom:Math.round(b.bottom),h:Math.round(b.height)};
}
}
return {scrollH:de.scrollHeight,viewH:innerHeight,overflow:de.scrollHeight-innerHeight,scrollable:de.scrollHeight>innerHeight+2,
bodyH:document.body.scrollHeight,footerBottom:fr?Math.round(fr.bottom):null,worst};
});
console.log(`${String(w).padStart(4)}x${String(h).padEnd(4)} docH=${String(r.scrollH).padEnd(5)} viewH=${String(r.viewH).padEnd(5)} 溢出=${String(r.overflow).padEnd(4)} 可滚=${r.scrollable?'YES':'no '} footer底=${r.footerBottom} 元凶=${r.worst?JSON.stringify(r.worst):'无'}`);
await p.screenshot({path:`/tmp/mini-${w}x${h}.png`});
await ctx.close();
}
await b.close();
})().catch(e=>{console.error(e);process.exit(1)});