Files
wrong-notebook/packaging/desktop/runtime-policy.js
margrop 25e41ae2b1 fix: 桌面壳绕过系统代理直连本机并补充崩溃恢复
app 就绪前配置 proxy-bypass-list 让 127.0.0.1/localhost 直连;
监听渲染进程崩溃与主帧加载失败(排除 ERR_ABORTED),提示并可一键重载;
second-instance 在 app 未就绪时直接返回,避免冷启动连续双击抛异常。

Refs: https://github.com/margrop/wrong-notebook/issues/154
2026-12-04 19:46:49 +08:00

48 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 桌面壳运行时隔离策略:内置服务端环境变量清理与渲染进程权限白名单。
* 纯函数,便于单元测试;main.js 复用同一套判定。
*/
const { isSameOrigin } = require('./url-policy');
/** 宿主机全局设置后可能干扰内置服务端启动或污染会话密钥的变量 */
const SERVER_ENV_DENYLIST = [
'NODE_OPTIONS',
'NEXTAUTH_SECRET',
'NEXTAUTH_SECRET_FILE',
'DATABASE_URL',
'CONFIG_DIR',
'WRONG_NOTEBOOK_HOME',
'PORT',
'HOSTNAME',
];
/** 渲染进程可申请的权限;通知、地理位置等其余权限一律拒绝 */
const ALLOWED_PERMISSIONS = ['clipboard-read', 'clipboard-sanitized-write', 'media'];
/** 复制宿主机环境变量时剔除冲突项,避免 NODE_OPTIONS 注入或宿主密钥覆盖应用数据目录密钥 */
function cleanServerEnv(env) {
const result = {};
for (const key of Object.keys(env || {})) {
if (!SERVER_ENV_DENYLIST.includes(key)) result[key] = env[key];
}
return result;
}
/** 仅同源页面可申请白名单内的权限 */
function isAllowedPermission(url, baseUrl, permission) {
return ALLOWED_PERMISSIONS.includes(permission) && isSameOrigin(url, baseUrl);
}
/** ERR_ABORTED 表示主动取消/替换的导航,不应弹出加载失败提示 */
function isIgnorableLoadFailure(errorCode) {
return errorCode === -3;
}
module.exports = {
SERVER_ENV_DENYLIST,
ALLOWED_PERMISSIONS,
cleanServerEnv,
isAllowedPermission,
isIgnorableLoadFailure,
};