Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

docs: state the ChatGPT ZIP guard's layering precisely and pin its end-to-end outcome (#5652)

Adam Eivy71cf27f0c8ad
diff --git a/server/services/chatgptZipImport.js b/server/services/chatgptZipImport.js
index c941e268d7..75e3f134cc 100644
--- a/server/services/chatgptZipImport.js
+++ b/server/services/chatgptZipImport.js
@@ -128,11 +128,13 @@ const WINDOWS_RESERVED_NAME = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])$/i;
// degenerate once `.dat` is dropped (`.dat` -> ``, `..dat` -> `.`), which would
// otherwise write a `.png` / `..png` dotfile into the served dir.
//
-// `zipStream.js` also sanitizes separators and `.`/`..` components as it decodes
-// each header, so a traversal has to defeat two independent layers to land. This
-// one is the layer that matters here: the parser's sanitizing is its own private
-// policy, while the consumer is what actually opens the file, and keeping the
-// check at the write site means a future faithful-reader refactor of the parser
+// Today `zipStream.js` sanitizes separators and `.`/`..` components as it decodes
+// each header, so a `\` never actually reaches this predicate — the flattened
+// basename is what arrives. That makes this guard the SECOND layer, not the
+// first, and it is deliberately kept anyway: the parser's sanitizing is its own
+// private policy (its header comment describes it as a faithful sequential
+// reader), while this is the code that actually opens the file. Validating at
+// the write site means a future refactor that makes the parser truly faithful
// cannot silently reintroduce the escape.
const isSafeDatMember = (path) => {
const assetId = datAssetId(path);
diff --git a/server/services/chatgptZipImport.test.js b/server/services/chatgptZipImport.test.js
index c81ad95d34..8ff5559cd1 100644
--- a/server/services/chatgptZipImport.test.js
+++ b/server/services/chatgptZipImport.test.js
@@ -202,12 +202,14 @@ describe('chatgptZipImport service', () => {
});
it('writes nothing outside the asset dir for a member whose name carries backslashes', async () => {
- // `a\..\..\evil.dat` is the classic Zip Slip shape. Two independent
- // layers stop it: `zipStream.js` sanitizes separators/traversal on the way
- // out of the parser, and `isSafeDatMember` refuses anything that still
- // isn't a plain filename before the temp file is opened. This pins the
- // end-to-end outcome — no write lands outside `assetDir` on any platform,
- // and the rest of the import still succeeds.
+ // `a\..\..\evil.dat` is the classic Zip Slip shape. Two layers stand
+ // between it and an escape: `zipStream.js` flattens separators and
+ // `.`/`..` components as it decodes the header (so the consumer sees
+ // `a/evil.dat` and extracts a harmless `evil.png` INSIDE the asset dir),
+ // and `isSafeDatMember` refuses anything that still isn't a plain filename
+ // before the temp file is opened. This pins the end-to-end outcome that
+ // matters: whichever layer acts, no write lands outside `assetDir` on any
+ // platform, and the rest of the import still succeeds.
const assetDir = join(TMP, 'nest', 'assets');
const zipPath = await writeZip([
['conversations-000.json', JSON.stringify([{ id: 'c1', title: 'A', mapping: {} }])],
@@ -218,14 +220,11 @@ describe('chatgptZipImport service', () => {
expect(conversationFiles.length).toBe(1);
expect(assets.get('file-OK').file).toBe('file-OK.jpg');
- // Nothing escaped into a sibling or parent directory.
+ // The hostile member was flattened to a basename and landed inside the
+ // asset dir — never at `${TMP}/evil.png` or above it.
+ expect((await readdir(assetDir)).sort()).toEqual(['evil.png', 'file-OK.jpg']);
expect((await readdir(join(TMP, 'nest'))).sort()).toEqual(['assets']);
expect((await readdir(TMP)).sort()).toEqual(['export.zip', 'nest']);
- // Every extracted file sits directly inside the asset dir.
- for (const name of await readdir(assetDir)) {
- expect(name.includes('/')).toBe(false);
- expect(name.includes('\\')).toBe(false);
- }
});
it('skips a .dat member whose name contains a NUL instead of failing the whole import', async () => {