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

fix: refuse ChatGPT ZIP members named after Windows devices (#5652)

Adam Eivy125d74c6651e
diff --git a/server/services/chatgptZipImport.js b/server/services/chatgptZipImport.js
index b81d00ec4f..c941e268d7 100644
--- a/server/services/chatgptZipImport.js
+++ b/server/services/chatgptZipImport.js
@@ -111,6 +111,13 @@ const IS_ASSET_NAME_MAP = (path) => /(?:^|\/)conversation_asset_file_names\.json
// `${assetDir}/${id}` would then escape the asset dir (Zip Slip).
const datAssetId = (path) => path.split(/[\\/]/).pop().replace(/\.dat$/i, '');
+// Windows resolves these basenames to devices whatever the extension, so a
+// member named `CON.dat` would open the console instead of `CON.part` and the
+// later rename would fail — aborting the whole import. Real exports only ever
+// use `file-…` ids, so they are refused on every platform for one consistent
+// outcome rather than a Windows-only failure.
+const WINDOWS_RESERVED_NAME = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])$/i;
+
// A `.dat` member is extractable only when BOTH its ZIP-spec name and the asset
// id it reduces to are plain filenames.
//
@@ -127,8 +134,12 @@ const datAssetId = (path) => path.split(/[\\/]/).pop().replace(/\.dat$/i, '');
// 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
// cannot silently reintroduce the escape.
-const isSafeDatMember = (path) =>
- isTopLevelEntryName(path.replace(/^.*\//, '')) && isTopLevelEntryName(datAssetId(path));
+const isSafeDatMember = (path) => {
+ const assetId = datAssetId(path);
+ return isTopLevelEntryName(path.replace(/^.*\//, ''))
+ && isTopLevelEntryName(assetId)
+ && !WINDOWS_RESERVED_NAME.test(assetId);
+};
// Single-sourced so both guards below log identically. Deliberately carries NO
// member path — the name is untrusted third-party text.
diff --git a/server/services/chatgptZipImport.test.js b/server/services/chatgptZipImport.test.js
index 6178df94fe..c81ad95d34 100644
--- a/server/services/chatgptZipImport.test.js
+++ b/server/services/chatgptZipImport.test.js
@@ -93,6 +93,10 @@ describe('chatgptZipImport service', () => {
expect(isSafeDatMember('bad\u0000name.dat')).toBe(false);
expect(isSafeDatMember('.dat')).toBe(false); // id becomes ''
expect(isSafeDatMember('..dat')).toBe(false); // id becomes '.'
+ // Windows device names resolve to a device, not a file, whatever the ext.
+ expect(isSafeDatMember('CON.dat')).toBe(false);
+ expect(isSafeDatMember('files/lpt1.dat')).toBe(false);
+ expect(isSafeDatMember('com10.dat')).toBe(true); // only COM1-9 are reserved
// Forward-slash components ARE directories: the basename is what's used,
// so traversal components reduce away harmlessly.
expect(isSafeDatMember('../../evil.dat')).toBe(true);
@@ -240,6 +244,19 @@ describe('chatgptZipImport service', () => {
expect(await readdir(assetDir)).toEqual(['file-OK.jpg']);
});
+ it('skips a .dat member named after a Windows device instead of failing the import', async () => {
+ const assetDir = join(TMP, 'assets');
+ const zipPath = await writeZip([
+ ['conversations-000.json', JSON.stringify([{ id: 'c1', title: 'A', mapping: {} }])],
+ ['CON.dat', PNG],
+ ['file-OK.dat', JPEG],
+ ]);
+ const { conversationFiles, stats } = await extractChatgptZip(zipPath, { assetDir });
+ expect(conversationFiles.length).toBe(1);
+ expect(stats.assetCount).toBe(1);
+ expect(await readdir(assetDir)).toEqual(['file-OK.jpg']);
+ });
+
it('skips .dat members whose id degenerates to "" or "." rather than writing a dotfile', async () => {
const assetDir = join(TMP, 'assets');
const zipPath = await writeZip([