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

address review (claude): pin new asset-charset rejection, correct guard comment

[._.]/ Adam Eivy5210515f3cda
diff --git a/server/services/chatgptImport.js b/server/services/chatgptImport.js
index af89cfbf0d..934e1453a6 100644
--- a/server/services/chatgptImport.js
+++ b/server/services/chatgptImport.js
@@ -336,12 +336,12 @@ export const extractAssetFileNames = (content) => {
let m;
while ((m = re.exec(content)) !== null) {
const name = m[1].replace(/[).,]+$/, '');
- // Served asset names are `<assetId><ext>` — both restricted to this flat
- // charset (see chatgptZipImport.js: datAssetId + the extension allowlist).
- // Anchoring to it is a strict superset of the path-traversal guard: it
- // rejects `/`, `\`, `..`, null bytes, and stray query-string/punctuation
- // matches that can never name a real on-disk asset, so a crafted link can't
- // produce a name we'd hand to unlink().
+ // Served asset names are `<assetId><ext>` (see chatgptZipImport.js) and are
+ // flat in practice. This regex is the actual safety boundary regardless of
+ // how the producer names files: a strict superset of the path-traversal
+ // guard, it rejects `/`, `\`, `..`, null bytes, and stray
+ // query-string/punctuation tails that can never name a real on-disk asset —
+ // so a crafted link can't produce a name we'd hand to unlink().
if (/^[a-zA-Z0-9._-]+$/.test(name)) {
names.add(name);
}
diff --git a/server/services/chatgptImport.test.js b/server/services/chatgptImport.test.js
index 2e0d1af41a..cdd329150e 100644
--- a/server/services/chatgptImport.test.js
+++ b/server/services/chatgptImport.test.js
@@ -297,6 +297,19 @@ describe('chatgptImport service', () => {
expect([...extractAssetFileNames(content)]).toEqual(['file-ok.png']);
});
+ it('rejects non-asset-charset tails (query strings, url-encoded dots) the basename guard let through', () => {
+ // Both names below contain no bare `/`, `\\`, or literal `..`, so they
+ // passed the looser prior `!includes()` guard — but neither can name a
+ // real on-disk asset. The flat-charset anchor is what rejects them, so
+ // this pins the hardening (it would fail under the prior guard).
+ const content = [
+ '![q](/data/brain-imports/file-q.png?sig=abc)', // query-string tail
+ '![pct](/data/brain-imports/file%2e%2e.png)', // url-encoded dots (not literal `..`)
+ '![ok](/data/brain-imports/file-ok2.png)',
+ ].join('\n');
+ expect([...extractAssetFileNames(content)]).toEqual(['file-ok2.png']);
+ });
+
it('returns an empty set for non-string / asset-free content', () => {
expect(extractAssetFileNames(null).size).toBe(0);
expect(extractAssetFileNames('plain memory text').size).toBe(0);