You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature] Can bili context encrypt the data files it outputs? #708
[bot] 🏷 Triage done — this is a real problem, and I'd recommend implementing it with a scoped design. Here's what I verified and what I propose; I'll start coding once you confirm the scope.
What bili actually writes to disk today (per host):
The session files are where the real exposure is: each one holds the block summaries, blockContents (the originals of every compressed block — kept so decompress/bili export --full can restore them), and a snapshot of the newest ~16k tokens of the folded conversation. That is effectively the full conversation content — code, pasted secrets, everything — sitting in plaintext JSON on whatever host runs the proxy. On an untrusted remote node, yes, this needs encryption at rest.
Recommended design (v1):
Scope: session files only. They're the only disk output containing actual conversation content. Logs are already operator-controllable (ACP_LOG_FILE=off), the CA key is regenerable, and the config must stay human-editable. Logs could be a follow-up if you want them covered too.
Mechanism: AES-256-GCM at the persist boundary. File format: 8-byte magic (BILIENC1) + version byte + fresh 12-byte nonce per write + ciphertext + GCM tag. No key material ever touches disk.
Key source: env var BILI_ENCRYPTION_KEY (hex or base64, exactly 32 bytes decoded). Opt-in — unset means today's behavior, zero change. Deliberately no key-file option: a key file next to the data on the same untrusted filesystem defeats the threat model; systemd Environment= / container secret injection is the right delivery path.
Migration: files without the magic keep loading as plaintext (existing trees don't break); when encryption is enabled, boot rewrites every loaded session once so no plaintext lingers (otherwise already-persisted sessions stay readable until their next dirty write).
Failure semantics: GCM auth failure (wrong key / corruption) → treated like today's corrupt-file path (log + skip), plus one prominent boot warning naming how many sessions failed to decrypt. Never silent, never mixed up.
Cross-repo dependency (heads-up): the fs I/O itself lives in acp-kernel's StateStore (this repo's src/persist.ts is policy only). So step one is a small kernel change — an optional codec { encode, decode } hook on StateStoreOptions, applied before the temp/spill writes and before JSON.parse — released from acp-kernel first, verified on npm, then bumped here per our cross-repo release rule. The billion-context side is one new module (src/encrypt.ts) + wiring into SessionStore + tests + docs.
Stopgap that already exists: for a fully ephemeral run on a hostile node, BILI_PERSIST=0 + ACP_LOG_FILE=off writes nothing but the regenerable CA/config. That works but throws away restart durability — persistence exists precisely so long sessions survive a restart — which is why encrypt-in-place is the right fix rather than "just disable it."
Question to confirm before I build: OK to proceed with (a) sessions-only scope, (b) env-var key only, (c) off by default? If you want the log file encrypted in v1 as well, say so — it's a modest addition but touches the logger contract.
we should process Session state file. also we can use zstd compress or avro file to make file size little.
i think sessions-only scope is good, what do u think?
[bot] 🏷 Sessions-only it is — agreed on my side too. On your two ideas:
zstd: yes. Conveniently, fzstd is already a build-time dependency of billion-context — it's bundled into dist today and used in the hot path to decode zstd request bodies from Codex Desktop (src/content-encoding.ts). So we get real zstd at zero new-dependency risk, on Node ≥20 including Windows. Order matters: JSON → zstd → AES-256-GCM (encrypting first destroys compressibility). Session JSON is very repetitive (long message texts, repeated structure), so expect roughly 5–10× shrinkage on top of the encryption envelope.
Avro: no — here's why. The persist layer's contract is JSON documents with organic schema evolution: the store stamps an envelope version, and old shapes are adopted through a legacy hook that operates on the parsed JSON — that's exactly how the v1→v3 file migration works. Avro needs fixed, managed schemas per version and would break the kernel's mechanism/policy split (StateStore owns JSON.parse/stringify). And the size win you're after comes from entropy reduction, which zstd already delivers on repetitive text without any schema machinery. Avro would add maintenance cost for ~0 additional shrinkage.
So the final format when enabled: BILIENC1 magic + version byte + 12-byte nonce + AES-256-GCM(zstd(JSON)). Everything else as proposed: key via BILI_ENCRYPTION_KEY env only (hex or base64, exactly 32 bytes decoded), off by default, legacy plaintext files keep loading and are re-encrypted once at boot, GCM auth failure = corrupt-file handling + one prominent boot warning.
One process note: the file I/O itself lives in acp-kernel's StateStore, so step 1 is a small kernel PR adding an optional codec { encode, decode } hook (applied around the temp/spill writes and the read path), released first per our cross-repo rule; then the billion-context side lands on top. Starting now — I'll link both PRs here as they open.
We need to support gracefully taking over existing unencoded data files after a new version is released. Ideally, if we have encryption enabled in the configuration, we should process the old data files once, generate new encrypted files, and then delete the old data files.
[bot] 🏷 Agreed — eager one-shot takeover at boot, no lazy re-encryption. Design:
When BILI_ENCRYPTION_KEY is set, SessionStore.boot() runs a migration pass before loading:
Walk the sessions tree (incl. .fb.json spills), peek the first 8 bytes of each .json — O(1) per file, no marker file needed.
Files with the BILIENC1 magic: skip (already migrated).
Files without (legacy plaintext): parse the envelope, re-serialize it byte-for-byte (version/savedAt/id/payload untouched), encode with AES-256-GCM(zstd(...)), and write it back to the same path via temp-file + rename.
The atomic rename makes "delete the old file" inherent: the plaintext is replaced in place, so there is never a moment where both copies exist (or neither does). A crash mid-migration leaves each file either old or new — the next boot simply finishes the remaining files. Files that fail to parse are left as-is with a warning (same tolerance as today's corrupt-file handling). Boot logs how many files were migrated.
Status: the mechanism half is ready for review — ranxianglei/acp-kernel#249 adds an optional codec hook to the kernel StateStore (encode around every write, decode around every read; decode failure = corrupt-file skip; default off = zero behavior change). It needs your merge so CI can publish 0.0.64; the billion-context side (key handling, BILIENC1 format, eager migration, docs, tests) lands as a follow-up PR pinned to 0.0.64 — I'm building it now and will link it here.
[bot] 🏷 Implementation is done on both sides — both PRs are open:
Mechanism (kernel): ranxianglei/acp-kernel#249 — optional codec hook on StateStore (encode around every write incl. spills, decode around every read; decode failure = corrupt-file skip; default off = zero behavior change). Needs your merge so CI publishes acp-kernel 0.0.64.
BILIENC1 format: AES-256-GCM over zstd-compressed JSON (compress-then-encrypt, per your size point — expect ~5–10× smaller files; zstd via built-in node:zlib on Node ≥ 22.15, raw mode byte on older runtimes). Avru… avro was not needed: zstd alone covers the size goal without breaking the JSON envelope-versioning contract.
Your migration requirement as specified: when encryption is enabled, boot processes every existing unencoded file once, writes the encrypted version, and the old plaintext is gone — done as an atomic in-place rename per file (crash mid-migration self-heals on next boot; unreadable files are left alone with a warning; .fb.json spills covered).
Wrong key at boot → GCM auth failure → affected sessions skip as corrupt (logged, no crash).
9 new tests (roundtrip, tamper/wrong-key rejection, legacy passthrough, eager migration + idempotency, spill coverage, fail-fast key validation, no-key zero-change); full suite 1376/1376 green locally; docs in CONFIGURATION.md + zh-CN.
One sequencing note: PR #711 currently pins acp-kernel 0.0.63 and will show red CI until 0.0.64 exists on npm — the moment #249 merges and CI publishes it, I add the pin+lockfile commit, re-run the full pre-flight, and #711 goes green. No other open items.
威胁模型决定算法。[Feature] Can bili context encrypt the data files it outputs? #708 防的是「数据文件的离线访问」:被拷走的磁盘镜像、泄露的备份、被同步到云盘的状态目录、回收后转手的节点——即攻击者能读文件但没有密钥。这个模型里加密方和解密方是同一个进程(bili 每次请求都要读写这些文件),非对称加密只在「不能看到明文的一方 ≠ 加密方」时才有价值(比如把密文交给持私钥的第三方),此处两个角色重合,用非对称只会增加复杂度而不增加任何保护。所有成熟的静态文件加密方案(LUKS/dm-crypt、age、sops、KMS 信封加密)都是同一形态:对称数据密钥 + 密钥从文件系统之外注入。
(English: Yes — symmetric AES-256-GCM, deliberately. The threat model is offline file access (stolen volumes/backups/synced dirs): the attacker can read the file but not the key, which is injected only via the BILI_ENCRYPTION_KEY env var and never written to disk/logs/config — key-file support was explicitly rejected because a key beside the data is exactly the "key leaks too" failure. Asymmetric crypto adds nothing here because the same process both encrypts and decrypts. It does NOT protect against a live full-root attacker on the running node — that attacker reads the key from the process environment and the conversation from process memory alike; for that threat use a TEE or BILI_PERSIST=0.)
(Follow-up: the "defends offline file access, not live full-root" boundary from the answer above is now documented in PR #711's CONFIGURATION docs (EN + ZH). The branch also picked up a small hardening — orphaned .tmp-enc-* temps from a crashed migration are now swept at next boot. Full pre-flight re-run green.)
(English recap: Agreed with the two-scenario split — it matches the shipped design exactly. Scenario 1 (routine/offline-mechanical theft: provider disk swaps, post-drift offline snapshots, stolen volumes/backups/synced dirs): PR #711 implements precisely this tier; key mechanism stays as-is per your decision (env-injected only, no ephemeral/KMS-wrap variants). Scenario 2 (targeted 1-on-1): confirmed out of scope for the proxy layer — trust root moves out via KMS/TEE/confidential VMs + hardened permissions; this framing is now written into the PR docs verbatim (commit e90e589, EN + ZH). No further code changes planned. Remaining delivery chain: human merge of acp-kernel#249 → CI publishes 0.0.64 → exact-pin + lockfile commit on #711 → CI green → normal release flow.)
(English recap: Evaluated the double-encryption proposal seriously — recommended AGAINST it for scenario 1. Core argument: security is determined by which artifact the attacker lacks, not by encryption layers. In every scenario-1 sub-case the attacker lacks exactly one thing — your off-disk secret — whether it's called the data key or the wrapping key; the missing set is unchanged. K2-in-env gives zero gain (attacker takes both at once; once the real key is in hand, decryption is instant under ANY scheme); key-splitting is strictly equivalent to status quo; machine-binding actively breaks the snapshot-migration use case; passphrase breaks headless operation; KDF stretching has no target against a 256-bit random key. Envelope encryption's value is never the second layer — it's the second key living in a different trust domain (HSM/KMS/TEE); remove that separation and the layer is pure ceremony. Recommendation: keep single AES-256-GCM key in v1; offered to add a one-line "why not double-encryption" note to the PR docs pending his OK.)
(Done as approved: the "why not double-encryption" rationale is now in both config docs (commit 1653250, EN + ZH). Branch head is fully ready; the only remaining chain is the human merge of acp-kernel#249 → 0.0.64 publish → pin+lockfile commit → #711 CI green → normal release flow.)
(Yes — built and verified. PR #249 merged; npm latest turned out to be 0.0.66 (three releases since 0.0.63). Verified the published 0.0.66 tarball contains the StateStoreCodec contract. The bili branch had already been merged with master (which pinned 0.0.66 in 33bbae5), so my pending pin commit was redundant — discarded, reset to remote head 5dd8c7d, and re-ran full pre-flight fresh: npm ci ✓, typecheck ✓, tests 1439/1439 pass (2 e2e-skipped), build ✓. PR #711 is dependency-ready and should go green on CI; no further commits needed from me. Remaining: human review → merge → normal release flow.)
按流程剩下的都是人工操作:合并 PR #738 → CI 自动发布到 npm(打 tag v0.1.108 + GitHub Release),我不会手动 publish。合并后可以 npm view billion-context version 确认,或按 README 的 auto-update 测试流程验证旧版自升级。
(Confirmed #711 is merged to master (1952fc9). Release PR prepared: #738 — branch cut from master, single commit bumping only the version fields, local pre-flight green (typecheck / 1439 tests / build). It ships the session-file encryption feature plus promptPack, preflight recovery (#726), orphan-temp sweep, fake-upstream E2E, paper docs, and the acp-kernel 0.0.66 pin. Remaining steps are human-only per the release flow: merge PR #738 → CI publishes to npm automatically (tag + GitHub Release); no manual publish by me.)
Activity
ranxianglei commentedon Sep 11, 2026
[bot] 🏷 Triage done — this is a real problem, and I'd recommend implementing it with a scoped design. Here's what I verified and what I propose; I'll start coding once you confirm the scope.
What bili actually writes to disk today (per host):
~/.local/share/billion-context/sessions/**/*.json~/.local/state/billion-context/bili.log(+.old)~/.local/share/billion-context/ca/~/.config/billion-context/billion-context.jsonThe session files are where the real exposure is: each one holds the block summaries,
blockContents(the originals of every compressed block — kept sodecompress/bili export --fullcan restore them), and a snapshot of the newest ~16k tokens of the folded conversation. That is effectively the full conversation content — code, pasted secrets, everything — sitting in plaintext JSON on whatever host runs the proxy. On an untrusted remote node, yes, this needs encryption at rest.Recommended design (v1):
ACP_LOG_FILE=off), the CA key is regenerable, and the config must stay human-editable. Logs could be a follow-up if you want them covered too.BILIENC1) + version byte + fresh 12-byte nonce per write + ciphertext + GCM tag. No key material ever touches disk.BILI_ENCRYPTION_KEY(hex or base64, exactly 32 bytes decoded). Opt-in — unset means today's behavior, zero change. Deliberately no key-file option: a key file next to the data on the same untrusted filesystem defeats the threat model; systemdEnvironment=/ container secret injection is the right delivery path.StateStore(this repo'ssrc/persist.tsis policy only). So step one is a small kernel change — an optionalcodec { encode, decode }hook onStateStoreOptions, applied before the temp/spill writes and beforeJSON.parse— released from acp-kernel first, verified on npm, then bumped here per our cross-repo release rule. The billion-context side is one new module (src/encrypt.ts) + wiring intoSessionStore+ tests + docs.Stopgap that already exists: for a fully ephemeral run on a hostile node,
BILI_PERSIST=0+ACP_LOG_FILE=offwrites nothing but the regenerable CA/config. That works but throws away restart durability — persistence exists precisely so long sessions survive a restart — which is why encrypt-in-place is the right fix rather than "just disable it."Question to confirm before I build: OK to proceed with (a) sessions-only scope, (b) env-var key only, (c) off by default? If you want the log file encrypted in v1 as well, say so — it's a modest addition but touches the logger contract.
BsoBird commentedon Sep 11, 2026
we should process Session state file. also we can use zstd compress or avro file to make file size little.
i think sessions-only scope is good, what do u think?
ranxianglei commentedon Sep 11, 2026
[bot] 🏷 Sessions-only it is — agreed on my side too. On your two ideas:
zstd: yes. Conveniently,
fzstdis already a build-time dependency of billion-context — it's bundled intodisttoday and used in the hot path to decode zstd request bodies from Codex Desktop (src/content-encoding.ts). So we get real zstd at zero new-dependency risk, on Node ≥20 including Windows. Order matters: JSON → zstd → AES-256-GCM (encrypting first destroys compressibility). Session JSON is very repetitive (long message texts, repeated structure), so expect roughly 5–10× shrinkage on top of the encryption envelope.Avro: no — here's why. The persist layer's contract is JSON documents with organic schema evolution: the store stamps an envelope version, and old shapes are adopted through a
legacyhook that operates on the parsed JSON — that's exactly how the v1→v3 file migration works. Avro needs fixed, managed schemas per version and would break the kernel's mechanism/policy split (StateStoreownsJSON.parse/stringify). And the size win you're after comes from entropy reduction, which zstd already delivers on repetitive text without any schema machinery. Avro would add maintenance cost for ~0 additional shrinkage.So the final format when enabled:
BILIENC1magic + version byte + 12-byte nonce + AES-256-GCM(zstd(JSON)). Everything else as proposed: key viaBILI_ENCRYPTION_KEYenv only (hex or base64, exactly 32 bytes decoded), off by default, legacy plaintext files keep loading and are re-encrypted once at boot, GCM auth failure = corrupt-file handling + one prominent boot warning.One process note: the file I/O itself lives in acp-kernel's
StateStore, so step 1 is a small kernel PR adding an optionalcodec { encode, decode }hook (applied around the temp/spill writes and the read path), released first per our cross-repo rule; then the billion-context side lands on top. Starting now — I'll link both PRs here as they open.BsoBird commentedon Sep 11, 2026
We need to support gracefully taking over existing unencoded data files after a new version is released. Ideally, if we have encryption enabled in the configuration, we should process the old data files once, generate new encrypted files, and then delete the old data files.
ranxianglei commentedon Sep 11, 2026
[bot] 🏷 Agreed — eager one-shot takeover at boot, no lazy re-encryption. Design:
When
BILI_ENCRYPTION_KEYis set,SessionStore.boot()runs a migration pass before loading:.fb.jsonspills), peek the first 8 bytes of each.json— O(1) per file, no marker file needed.BILIENC1magic: skip (already migrated).version/savedAt/id/payloaduntouched), encode with AES-256-GCM(zstd(...)), and write it back to the same path via temp-file + rename.The atomic rename makes "delete the old file" inherent: the plaintext is replaced in place, so there is never a moment where both copies exist (or neither does). A crash mid-migration leaves each file either old or new — the next boot simply finishes the remaining files. Files that fail to parse are left as-is with a warning (same tolerance as today's corrupt-file handling). Boot logs how many files were migrated.
Status: the mechanism half is ready for review — ranxianglei/acp-kernel#249 adds an optional
codechook to the kernelStateStore(encode around every write, decode around every read; decode failure = corrupt-file skip; default off = zero behavior change). It needs your merge so CI can publish 0.0.64; the billion-context side (key handling,BILIENC1format, eager migration, docs, tests) lands as a follow-up PR pinned to 0.0.64 — I'm building it now and will link it here.中文摘要:按你的要求采用启动时一次性迁移——加密开启时扫描旧明文会话文件,逐个原子替换为加密文件(同名 temp+rename,旧文件天然被覆盖删除,崩溃可自愈),内核侧 codec 钩子 PR 已提交待合并。
docs: changelog entry for session-file encryption (#708, PR #711)
ranxianglei commentedon Sep 11, 2026
[bot] 🏷 Implementation is done on both sides — both PRs are open:
codechook onStateStore(encode around every write incl. spills, decode around every read; decode failure = corrupt-file skip; default off = zero behavior change). Needs your merge so CI publishes acp-kernel 0.0.64.BILI_ENCRYPTION_KEY(env-only, hex/base64, exactly 32 bytes; invalid value aborts startup); unset = today's plaintext behavior.BILIENC1format: AES-256-GCM over zstd-compressed JSON (compress-then-encrypt, per your size point — expect ~5–10× smaller files; zstd via built-in node:zlib on Node ≥ 22.15, raw mode byte on older runtimes). Avru… avro was not needed: zstd alone covers the size goal without breaking the JSON envelope-versioning contract..fb.jsonspills covered).One sequencing note: PR #711 currently pins acp-kernel 0.0.63 and will show red CI until 0.0.64 exists on npm — the moment #249 merges and CI publishes it, I add the pin+lockfile commit, re-run the full pre-flight, and #711 goes green. No other open items.
中文摘要:两侧 PR 均已提交——内核 codec 钩子(acp-kernel#249,待你合并发布 0.0.64)与本仓库加密功能(#711:BILI_ENCRYPTION_KEY、BILIENC1 = AES-256-GCM(zstd(JSON))、启动时一次性原子迁移旧明文文件、9 个新测试全绿);待 0.0.64 发布后补 pin 提交即可转绿。
fix: sweep orphaned .tmp-enc-* temps left by a crashed encryption mig…
ranxianglei commentedon Sep 11, 2026
这里有一个问题,现在加密是对称加密还是非对称加密.如果是对称加密,是不是密码本会被泄露?使得加密徒劳?
ranxianglei commentedon Sep 11, 2026
[bot] 🏷 好问题,直接回答:
是的,对称加密(AES-256-GCM,一个 32 字节密钥同时用于加解密)。这是刻意选择,不是疏忽:
威胁模型决定算法。 [Feature] Can bili context encrypt the data files it outputs? #708 防的是「数据文件的离线访问」:被拷走的磁盘镜像、泄露的备份、被同步到云盘的状态目录、回收后转手的节点——即攻击者能读文件但没有密钥。这个模型里加密方和解密方是同一个进程(bili 每次请求都要读写这些文件),非对称加密只在「不能看到明文的一方 ≠ 加密方」时才有价值(比如把密文交给持私钥的第三方),此处两个角色重合,用非对称只会增加复杂度而不增加任何保护。所有成熟的静态文件加密方案(LUKS/dm-crypt、age、sops、KMS 信封加密)都是同一形态:对称数据密钥 + 密钥从文件系统之外注入。
密钥在哪、会不会泄露? 密钥只经
BILI_ENCRYPTION_KEY环境变量注入,设计上不落盘、不进日志、不进配置文件——这也是我们明确不支持「密钥文件」的原因:把密钥放在数据旁边,正是你担心的「密码本一起泄露、加密徒劳」的场景,我们在设计层面直接封死了这条路。密钥的暴露面(进程环境/内存)严格小于数据的暴露面(长期驻留磁盘的文件)。诚实的边界——它防不了什么: 如果攻击者已经拿到运行中节点的 root,他可以从进程环境或内存里直接读到密钥。但注意:那个场景下他同样能直接从 bili 进程内存里读出全部会话内容(进程本来就在内存里持有完整上下文),文件加密在那里也救不了。要防「活的实时全权攻击」,答案是 TEE/机密虚拟机,或者干脆不持久化(
BILI_PERSIST=0),而不是非对称加密。一句话:对称 + 外部注入密钥是「不可信存储上的文件」的行业标准答案;它防的是文件离开你的控制,不是坐在进程里面的攻击者。
(English: Yes — symmetric AES-256-GCM, deliberately. The threat model is offline file access (stolen volumes/backups/synced dirs): the attacker can read the file but not the key, which is injected only via the
BILI_ENCRYPTION_KEYenv var and never written to disk/logs/config — key-file support was explicitly rejected because a key beside the data is exactly the "key leaks too" failure. Asymmetric crypto adds nothing here because the same process both encrypts and decrypts. It does NOT protect against a live full-root attacker on the running node — that attacker reads the key from the process environment and the conversation from process memory alike; for that threat use a TEE orBILI_PERSIST=0.)docs: clarify encryption threat model (offline file access, not live …
ranxianglei commentedon Sep 11, 2026
[bot] 🏷 跟进:上面「防离线、不防活的 root」的边界说明已写进 PR #711 的 CONFIGURATION.md(含中文版),避免后续部署的人产生同样疑问。分支上另有一处小加固已合入:迁移中途崩溃遗留的
.tmp-enc-*临时文件现在会在下次启动时被清扫(此前会永久残留)。全量 pre-flight 重新跑过:typecheck ✓ / 1377 tests ✓ / build ✓。唯一待办不变:等 acp-kernel#249 合并发布 0.0.64,我补 pin+lockfile 提交后 #711 即转绿。
(Follow-up: the "defends offline file access, not live full-root" boundary from the answer above is now documented in PR #711's CONFIGURATION docs (EN + ZH). The branch also picked up a small hardening — orphaned
.tmp-enc-*temps from a crashed migration are now swept at next boot. Full pre-flight re-run green.)ranxianglei commentedon Sep 11, 2026
[bot] 🏷 更正上一条的链接笔误:PR 地址是 #711 (上一条里
github.com后漏了斜杠)。其余内容不变。ranxianglei commentedon Sep 11, 2026
所以我在想 如果攻击者能拿到bili的内存,加密意义何在?
如果是对称的加密,明文密钥岂不是直接传输?最后防止偷窥的目标是否能达到
9 remaining items
ranxianglei commentedon Sep 12, 2026
[bot] 🏷 完全同意这个划分,而且它和已提交方案是精确对齐的——确认如下:
场景 1(常规,≥90%):PR #711 实现的就是这一档。保护对象明确为离线/机械性的文件获取:云厂商换盘、节点镜像漂移后的离线磁盘快照、磁盘镜像失窃、备份泄露、被云同步的状态目录——离线第三方拿不到密钥就无法读取内容(AES-256-GCM,密钥只经环境变量注入,不落盘)。按你的决定,密钥机制保持不变(env 注入,本地或远端密钥管理服务提供均可),不引入临时密钥/KMS 包裹等变体。duckdb 式的先例一致。
场景 2(定向一对一):确认不在 proxy 层处理。刚把这段威胁模型表述原样写进了 PR #711 的文档(CONFIGURATION.md + zh-CN,commit
e90e589):该档威胁应把明文边界/信任根移出不可信 proxy——KMS / TEE / 机密虚拟机 + 强化权限体系,大范围处理;到了那个程度 proxy 自身密钥不是该守的边界。BILI_PERSIST=0作为彻底关闭持久化的选项也一并写明。当前状态:不再有计划内的代码改动。剩最后一步交付链路——acp-kernel#249(codec 钩子)等人工合并 → CI 发布 0.0.64 → 我在 billion-context#711 上补 exact-pin + lockfile commit → CI 转绿 → 走正常 release 流程发布。合并后我会在这里贴最终状态。
(English recap: Agreed with the two-scenario split — it matches the shipped design exactly. Scenario 1 (routine/offline-mechanical theft: provider disk swaps, post-drift offline snapshots, stolen volumes/backups/synced dirs): PR #711 implements precisely this tier; key mechanism stays as-is per your decision (env-injected only, no ephemeral/KMS-wrap variants). Scenario 2 (targeted 1-on-1): confirmed out of scope for the proxy layer — trust root moves out via KMS/TEE/confidential VMs + hardened permissions; this framing is now written into the PR docs verbatim (commit e90e589, EN + ZH). No further code changes planned. Remaining delivery chain: human merge of acp-kernel#249 → CI publishes 0.0.64 → exact-pin + lockfile commit on #711 → CI green → normal release flow.)
BsoBird commentedon Sep 12, 2026
对于场景1,可能可以耍一个小花招,假设用户没有条件部署密钥云服务,是否可以使用二次加密的密钥进行文件加解密.{例如base64的密钥+截取长度}
这样我就是给你暴露密钥你也无法第一时间解出明文.
ranxianglei commentedon Sep 12, 2026
[bot] 🏷 这个想法值得认真过一遍——结论先说:在场景 1 的约束下(无密钥云服务),二次加密不提供任何额外安全,我建议不做。推理如下:
核心论点:决定安全性的是「攻击者手里缺哪个工件」,不是加密套了几层。
场景 1 的所有子场景里(离线磁盘快照、换盘、备份泄露、镜像漂移转手),攻击者缺的永远是同一类东西:你的非落盘秘密。当前设计里这个秘密叫「数据密钥」(env 注入);改成二次加密后它叫「包裹密钥」——名字换了,缺失集合完全没变:
一句话:用同一个信任域里的另一把钥匙去包钥匙,等于给门上的锁多刷了一层漆——锁的强度没变,KMS 信封加密的价值从来不在「第二层」,而在第二把钥匙住在不同的信任域(HSM/云)。去掉这个隔离,第二层就是纯仪式:更多代码、更多失败模式(双密钥轮换、双重迁移)、相同的安全性。
我的建议:v1 保持单 AES-256-GCM 密钥不变。如果目标是「密钥暴露≠立刻可读明文」,唯一真正有效的形态是把包裹密钥放进不同信任域(KMS/TPM/TEE)——这正是你已裁定属于场景 2、不由 proxy 承担的路径。如果你同意这个结论,我可以在 PR #711 的文档里补一句「为何不做二次加密」的说明(防止未来重复讨论),你点头我就加。
(English recap: Evaluated the double-encryption proposal seriously — recommended AGAINST it for scenario 1. Core argument: security is determined by which artifact the attacker lacks, not by encryption layers. In every scenario-1 sub-case the attacker lacks exactly one thing — your off-disk secret — whether it's called the data key or the wrapping key; the missing set is unchanged. K2-in-env gives zero gain (attacker takes both at once; once the real key is in hand, decryption is instant under ANY scheme); key-splitting is strictly equivalent to status quo; machine-binding actively breaks the snapshot-migration use case; passphrase breaks headless operation; KDF stretching has no target against a 256-bit random key. Envelope encryption's value is never the second layer — it's the second key living in a different trust domain (HSM/KMS/TEE); remove that separation and the layer is pure ceremony. Recommendation: keep single AES-256-GCM key in v1; offered to add a one-line "why not double-encryption" note to the PR docs pending his OK.)
BsoBird commentedon Sep 12, 2026
okay
go ahead
docs: note why same-trust-domain double-encryption adds nothing (#708)
ranxianglei commentedon Sep 12, 2026
[bot] 🏷 已加。PR #711 的 CONFIGURATION.md + zh-CN 里
BILI_ENCRYPTION_KEY条目末尾补了一句结论(commit1653250):用同一进程/环境中的第二把密钥做二次加密不增加任何安全性——所有离线失窃场景里攻击者缺的始终只有一个工件(你的非落盘秘密),无论它叫数据密钥还是包裹密钥;只有包裹密钥住在不同信任域(KMS/TPM/TEE)才能提高门槛,那属于场景 2。当前分支状态:
1653250(全部功能代码 + 测试 + 文档已就位)。剩余交付链路不变:acp-kernel#249 等人工合并 → CI 发布 0.0.64 → 我补 exact-pin + lockfile commit → billion-context#711 CI 转绿 → 走正常 release 流程。合并后我会在这里贴最终状态。(Done as approved: the "why not double-encryption" rationale is now in both config docs (commit 1653250, EN + ZH). Branch head is fully ready; the only remaining chain is the human merge of acp-kernel#249 → 0.0.64 publish → pin+lockfile commit → #711 CI green → normal release flow.)
BsoBird commentedon Sep 13, 2026
ranxianglei/acp-kernel#249 merged,can we try build?
ranxianglei commentedon Sep 13, 2026
[bot] 🏷 可以,已经试过了,全绿。过程与结果:
npm install acp-kernel@0.0.66后检查了实际 tarball——StateStoreCodec接口和codec?选项都在acp-kernel/persist导出里,语义与我们实现的一致(每次写入 canonical+spill 前 encode、读取时 decode,默认无 codec 零行为变化)。2026-09-11_persist-encryption分支已经被合入过 master(含 v0.1.106/v0.1.107 发布和一批新 PR),其中 commit33bbae5已经把 acp-kernel pin 到 0.0.66——我本地准备的那个 pin commit 因此变冗余,直接丢弃、对齐到远端分支头5dd8c7d。npm ci✓npm run typecheck✓(零错误)npm test✓ 1439 pass / 0 fail / 2 skipped(e2e 门控跳过;总数从 1379 涨到 1441 是合入的新测试)npm run build✓(dist/index.js 2.76MB)所以 billion-context#711 现在是依赖就绪、CI 应该转绿的状态,加密功能代码 + 测试 + 文档全部在分支里,无需我再补任何提交。剩下的就是人工 review → 合并 → 走正常 release 流程(release PR 会带上这个功能)。
(Yes — built and verified. PR #249 merged; npm latest turned out to be 0.0.66 (three releases since 0.0.63). Verified the published 0.0.66 tarball contains the StateStoreCodec contract. The bili branch had already been merged with master (which pinned 0.0.66 in 33bbae5), so my pending pin commit was redundant — discarded, reset to remote head 5dd8c7d, and re-ran full pre-flight fresh: npm ci ✓, typecheck ✓, tests 1439/1439 pass (2 e2e-skipped), build ✓. PR #711 is dependency-ready and should go green on CI; no further commits needed from me. Remaining: human review → merge → normal release flow.)
Merge pull request #711 from ranxianglei/2026-09-11_persist-encryption
ranxianglei commentedon Sep 13, 2026
合并了发一个新版本。
ranxianglei commentedon Sep 13, 2026
[bot] 🏷 已确认 #711 合并进 master(merge commit
1952fc9),新版本发布 PR 已备好:**https://github.com/ranxianglei/billion-context/pull/738**(release v0.1.108)。2026-09-13_release-v0.1.108,从 master 切出,唯一提交b7ba22c=release v0.1.108(只改 package.json + lockfile 的版本字段,无其他内容)按流程剩下的都是人工操作:合并 PR #738 → CI 自动发布到 npm(打 tag v0.1.108 + GitHub Release),我不会手动 publish。合并后可以
npm view billion-context version确认,或按 README 的 auto-update 测试流程验证旧版自升级。(Confirmed #711 is merged to master (1952fc9). Release PR prepared: #738 — branch cut from master, single commit bumping only the version fields, local pre-flight green (typecheck / 1439 tests / build). It ships the session-file encryption feature plus promptPack, preflight recovery (#726), orphan-temp sweep, fake-upstream E2E, paper docs, and the acp-kernel 0.0.66 pin. Remaining steps are human-only per the release flow: merge PR #738 → CI publishes to npm automatically (tag + GitHub Release); no manual publish by me.)
feat: encrypt session files at rest behind BILI_ENCRYPTION_KEY (ranxi…