mirror of
https://github.com/HeyPuter/puter.git
synced 2026-11-23 14:17:06 +00:00
fix(fs): treat path-less entries found by uid or id as missing (#4611)
A uid or id lookup can return a legacy row with no path when its parent chain is broken. resolveNode now reports it as not found, so readdir, stat and the other uid-addressed routes answer 404 instead of crashing in the ACL check.
This commit is contained in:
1 parent
a6e75b46cb
commit
61b5aa4900
3 files changed
+39
-2
No files matched your search
@@ -154,6 +154,26 @@ describe('GET /fs/readdir over HTTP', () => {
|
||||
).toEqual(['a', 'a/b']);
|
||||
});
|
||||
|
||||
it('answers 404 for a directory whose parent chain is broken', async () => {
|
||||
const { username, token } = env.users.user;
|
||||
const path = `/${username}/Documents/http-orphan-${Date.now()}`;
|
||||
const created = await fetch(new URL('/fs/mkdir', env.apiOrigin), {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ path, auth_token: token }),
|
||||
});
|
||||
expect(created.status).toBe(200);
|
||||
const { uid } = (await created.json()) as { uid: string };
|
||||
await env.server.clients.db.write(
|
||||
'UPDATE fsentries SET path = NULL, parent_uid = ? WHERE uuid = ?',
|
||||
['does-not-exist', uid],
|
||||
);
|
||||
await env.server.stores.fsEntry.invalidateEntryCacheByUuid(uid);
|
||||
|
||||
const response = await fetch(readdirUrl({ uid, auth_token: token }));
|
||||
expect(response.status).toBe(404);
|
||||
});
|
||||
|
||||
it('mkdir does not return internal ids, storage columns or tokens', async () => {
|
||||
const { username, token } = env.users.user;
|
||||
const response = await fetch(new URL('/fs/mkdir', env.apiOrigin), {
|
||||
|
||||
@@ -124,6 +124,21 @@ describe('resolveNode', () => {
|
||||
expect(error.message).toContain('uuid=ghost');
|
||||
});
|
||||
|
||||
it('treats a path-less row found by uid or id as missing', async () => {
|
||||
const orphan = makeEntry({ path: null as unknown as string });
|
||||
const store = makeStore({
|
||||
getEntryByUuid: vi.fn(async () => orphan),
|
||||
getEntryById: vi.fn(async () => orphan),
|
||||
});
|
||||
|
||||
await expect(resolveNode(store, { uid: 'uuid-7' })).resolves.toBeNull();
|
||||
await expectHttpError(
|
||||
() => resolveNode(store, { id: 7 }, { required: true }),
|
||||
404,
|
||||
'subject_does_not_exist',
|
||||
);
|
||||
});
|
||||
|
||||
it('falls back to id lookup when uid is blank', async () => {
|
||||
const entry = makeEntry();
|
||||
const store = makeStore({ getEntryById: vi.fn(async () => entry) });
|
||||
|
||||
@@ -62,10 +62,12 @@ export async function resolveNode(
|
||||
): Promise<FSEntry | null> {
|
||||
if (ref.entry) return ref.entry;
|
||||
|
||||
// A uid/id lookup can return a legacy row with no path when its parent
|
||||
// chain is broken. Nothing can authorize or address it, so it's a miss.
|
||||
const uuid = ref.uid ?? ref.uuid;
|
||||
if (isNonEmptyString(uuid)) {
|
||||
const entry = await fsEntryStore.getEntryByUuid(uuid);
|
||||
if (entry) return entry;
|
||||
if (entry?.path) return entry;
|
||||
return notFoundOrNull(
|
||||
options.required,
|
||||
`Entry not found: uuid=${uuid}`,
|
||||
@@ -80,7 +82,7 @@ export async function resolveNode(
|
||||
});
|
||||
}
|
||||
const entry = await fsEntryStore.getEntryById(numericId);
|
||||
if (entry) return entry;
|
||||
if (entry?.path) return entry;
|
||||
return notFoundOrNull(
|
||||
options.required,
|
||||
`Entry not found: id=${numericId}`,
|
||||
|
||||
Reference in new issue
Block a user