Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion recipes/openai-bridge/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Current App streamfix addresses contain only an opaque HMAC route ID; their orig

Runtime execution requires the fixed component source, manifest hash and private file to agree. The published r11 stale-file mode also allows non-executing retirement and interrupted in-place upgrades when each private file still matches its recorded hash or the current fixed source; this mode never executes the old private file. As the manifest is not a signature trust root, this is not proof that the old bytes were an authentic historical release. Upgrades replace stale runtime files with current verified source before any later execution, while retirement may safely remove Hooks/registration without executing the private content. The stop protocol is implemented in the fixed installer and never sources or executes a private `bridge-common.sh`, even for its explicit manual cleanup path. Lock opens use directory descriptors, `O_NOFOLLOW` and no truncation, reject hard links/special files, and recheck identity under the shared registration lock. Before TERM/KILL, the installer checks the expected Node/watchdog command, runtime path, PID start time and registration again; settings writes similarly recheck the snapshot rather than overwrite a concurrent edit. These checks do not make the private manifest a signature trust root or authorize deleting unverified data. Successor-registration retention assumes writers use the shared registration flock. It is not an atomic compare-and-unlink guarantee against arbitrary noncooperating same-UID code rewriting the pathname between the final check and unlink; directory descriptors prevent parent redirection, not that same-UID mutation.

The sole path alias normalization is `fs.realpathSync(os.homedir())` at the trusted HOME root, before deriving default targets and forwarding HOME to child processes; explicit target paths and links below that root remain subject to strict identity/no-follow checks. The watchdog treats explicit disabled as an immediate stop without creating a new fault. Only a missing fixed component entry receives one bounded ten-second confirmation, with unchanged manifest hash/inode and a canonical regular entry required to continue. No patch/stop/spawn occurs while it waits, and the service lock is released instead of blocking other operations. The old transaction is abandoned; the main loop reacquires nonblocking, revalidates manifest and PID/starttime identity, rereads the durable attempt count and gives a concurrently started replacement only a bounded readiness grace. Unobserved confirmation time is not credited as stable health. A persistent absence still locks recovery and exits. Existing locks are never cleared by an update or save. This addresses the confirmed update-transient failure, not the still-unknown earlier first midnight health failure.
Path normalization is confined to caller-trusted HOME/component roots and the verified Android app-root spellings `/data/data/<package>` and `/data/user/0/<package>`. The app-root directories must have matching device/inode identities; their canonical `/data/data` spelling is preferred when available, including bind-mount layouts whose realpaths retain both spellings. Only that prefix is projected, never the complete input path: symlinks below HOME, inside an instance, in state/registration directories or below the component root remain subject to the existing strict realpath, lstat and no-follow checks. The installer, fixed entry, registration and shell lifecycle code share this policy. Equivalent recorded target/settings/component/home paths and explicit `--dir` aliases no longer require rewriting the manifest or registration. Hook merge/removal recognizes only exact generated Hook objects for the verified aliases, not arbitrary shell commands. Identity, source/hash and recovery gates are unchanged. The watchdog treats explicit disabled as an immediate stop without creating a new fault. Only a missing fixed component entry receives one bounded ten-second confirmation, with unchanged manifest hash/inode and a canonical regular entry required to continue. No patch/stop/spawn occurs while it waits, and the service lock is released instead of blocking other operations. The old transaction is abandoned; the main loop reacquires nonblocking, revalidates manifest and PID/starttime identity, rereads the durable attempt count and gives a concurrently started replacement only a bounded readiness grace. Unobserved confirmation time is not credited as stable health. A persistent absence still locks recovery and exits. Existing locks are never cleared by an update or save. This addresses the confirmed update-transient failure, not the still-unknown earlier first midnight health failure.

Release presence follows the official App/component release records, not a permanent "unpublished" label in this contract. Publish an App supporting the new schema while retaining the old one first, then the component; migration remains explicit. Unknown future schemas fail closed for startup but must not prevent fixed-path/owned-file uninstall cleanup. These source changes do not by themselves prove a signed release or native-App acceptance. The installed App, installed signed component and current daily bridge are not modified by this source revision. Genuine package-update recovery, final signature installation and all eight native UI delivery gates remain separate verification requirements.

Expand Down
12 changes: 6 additions & 6 deletions recipes/openai-bridge/component.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function run(file,argv){
process.exitCode=result.status??1;
}
try{
// 仅 HOME 信任根允许 realpath(应用 HOME 可是 Android 路径别名);显式 --dir 不规范化。
// 只归并可信根的别名;--dir 以下的链接仍由当前安装器逐项拒绝。
const home=api.trustedHome();process.env.HOME=home;
if(command==='--selftest'){
if(args.length)throw new Error('selftest 不接受额外参数。');
Expand All @@ -32,19 +32,19 @@ try{
if(command==='configure'){
run(path.join(__dirname,'installer.cjs'),['install',...args,'--bundled-runtime',__dirname]);
}else if(command==='ensure'||(command==='uninstall'&&scoped)){
const target=options.dir===undefined?path.join(home,'.local/share/ccr-bridge-kit'):path.resolve(options.dir);
const target=options.dir===undefined?path.join(home,'.local/share/ccr-bridge-kit'):api.normalizedPath(path.resolve(options.dir));
// 固定入口必须保留实例核对,不能将新参数交给可能不认识它们的旧 manage.cjs。
// 当前安装器验证既有 manifest/注册/运行文件后管理它;绝不覆盖私有运行副本。
const forwarded=options.dir===undefined?[...args,'--dir',target]:args;
const forwarded=options.dir===undefined?[...args,'--dir',target]:args.map((value,i)=>args[i-1]==='--dir'?target:value);
run(path.join(__dirname,'installer.cjs'),[command,...forwarded]);
}else{
const target=options.dir===undefined?path.join(home,'.local/share/ccr-bridge-kit'):path.resolve(options.dir);
const target=options.dir===undefined?path.join(home,'.local/share/ccr-bridge-kit'):api.normalizedPath(path.resolve(options.dir));
const marker=path.join(target,'.ccr-bridge-kit.json');
if(!fs.existsSync(marker))throw new Error('尚未配置此安装。请用户在终端运行 openai-bridge configure。');
const manifest=JSON.parse(fs.readFileSync(marker,'utf8'));
if(manifest.id!=='ccr-bridge-kit'||!api.sameDir(path.resolve(manifest.target),target))throw new Error('不是受管理的桥安装。');
if(manifest.id!=='ccr-bridge-kit'||api.normalizedPath(manifest.target)!==target)throw new Error('不是受管理的桥安装。');
// 手动清理不要求新实例协议;保留旧运行副本自带管理器,不擅自覆盖它。
const forwarded=options.dir===undefined?[...args,'--dir',target]:args;
const forwarded=options.dir===undefined?[...args,'--dir',target]:args.map((value,i)=>args[i-1]==='--dir'?target:value);
run(path.join(target,'manage.cjs'),[command,...forwarded]);
}
}else throw new Error('未知操作;运行 openai-bridge --help 查看用法。');
Expand Down
Loading
Loading