mirror of
https://github.com/HeyPuter/puter.git
synced 2026-11-26 07:37:54 +00:00
apps: refuse new names that have the form of an app uid
This commit is contained in:
1 parent
5cc33ffc4a
commit
d7f2acc953
4 files changed
+83
-3
No files matched your search
@@ -79,6 +79,10 @@ const APP_WRITE_LIMIT = {
|
||||
};
|
||||
|
||||
const APP_NAME_REGEX = /^[a-zA-Z0-9_-]+$/;
|
||||
// The app an origin's first sign-in creates is named after its `app-<uuid>`
|
||||
// uid, so new names of that shape are refused.
|
||||
const RESERVED_APP_NAME_REGEX =
|
||||
/^app-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||
const APP_NAME_MAX_LEN = 100;
|
||||
const APP_TITLE_MAX_LEN = 100;
|
||||
const APP_DESCRIPTION_MAX_LEN = 7000;
|
||||
@@ -598,6 +602,7 @@ export class AppDriver extends PuterDriver {
|
||||
maxLen: APP_NAME_MAX_LEN,
|
||||
regex: APP_NAME_REGEX,
|
||||
});
|
||||
if (RESERVED_APP_NAME_REGEX.test(name)) return false;
|
||||
return !(await this.appStore.existsByName(name));
|
||||
}
|
||||
|
||||
@@ -613,6 +618,16 @@ export class AppDriver extends PuterDriver {
|
||||
regex: APP_NAME_REGEX,
|
||||
required: isCreate,
|
||||
});
|
||||
if (
|
||||
out.name !== existing?.name &&
|
||||
RESERVED_APP_NAME_REGEX.test(out.name ?? '')
|
||||
) {
|
||||
throw new HttpError(
|
||||
400,
|
||||
'`name` cannot have the form of an app uid',
|
||||
{ legacyCode: 'bad_request' },
|
||||
);
|
||||
}
|
||||
}
|
||||
if (isCreate || object.title !== undefined) {
|
||||
out.title = validateString(object.title, {
|
||||
|
||||
@@ -134,6 +134,32 @@ describe('AppDriver.create', () => {
|
||||
).rejects.toMatchObject({ statusCode: 400 });
|
||||
});
|
||||
|
||||
it("refuses an origin's derived uid as a name, so that origin's app can still be created", async () => {
|
||||
const { actor } = await makeUser();
|
||||
const origin = new URL(uniqueIndexUrl()).origin;
|
||||
const uid = await server.services.auth.appUidFromOrigin(origin);
|
||||
|
||||
for (const name of [uid, uid.toUpperCase(), `app-${uuidv4()}`]) {
|
||||
await expect(
|
||||
withActor(actor, () =>
|
||||
driver.create({
|
||||
object: {
|
||||
name,
|
||||
title: 't',
|
||||
index_url: uniqueIndexUrl(),
|
||||
},
|
||||
}),
|
||||
),
|
||||
).rejects.toMatchObject({
|
||||
statusCode: 400,
|
||||
legacyCode: 'bad_request',
|
||||
});
|
||||
}
|
||||
|
||||
const app = await server.services.app.ensureOriginApp(uid, origin);
|
||||
expect(app).toMatchObject({ uid, name: uid });
|
||||
});
|
||||
|
||||
it('rejects a missing index_url with 400', async () => {
|
||||
const { actor } = await makeUser();
|
||||
await expect(
|
||||
@@ -837,6 +863,41 @@ describe('AppDriver.update', () => {
|
||||
expect(updated.description).toBe('now with desc');
|
||||
});
|
||||
|
||||
it('refuses a rename to an app-uid-shaped name', async () => {
|
||||
const { actor } = await makeUser();
|
||||
const created = await withActor(actor, () =>
|
||||
driver.create({
|
||||
object: {
|
||||
name: uniqueName('rename'),
|
||||
title: 't',
|
||||
index_url: uniqueIndexUrl(),
|
||||
},
|
||||
}),
|
||||
);
|
||||
await expect(
|
||||
withActor(actor, () =>
|
||||
driver.update({
|
||||
uid: created.uid,
|
||||
object: { name: `app-${uuidv4()}` },
|
||||
}),
|
||||
),
|
||||
).rejects.toMatchObject({ statusCode: 400, legacyCode: 'bad_request' });
|
||||
});
|
||||
|
||||
it('keeps updating an app whose existing name has the form of an app uid', async () => {
|
||||
const { actor, userId } = await makeUser();
|
||||
const origin = new URL(uniqueIndexUrl()).origin;
|
||||
const uid = await server.services.auth.appUidFromOrigin(origin);
|
||||
await server.stores.app.createFromOrigin(uid, origin, {
|
||||
ownerUserId: userId,
|
||||
});
|
||||
|
||||
const updated = await withActor(actor, () =>
|
||||
driver.update({ uid, object: { name: uid, title: 'Renamed' } }),
|
||||
);
|
||||
expect(updated).toMatchObject({ uid, name: uid, title: 'Renamed' });
|
||||
});
|
||||
|
||||
it("rejects updating another user's app with 403", async () => {
|
||||
const a = await makeUser();
|
||||
const b = await makeUser();
|
||||
@@ -1000,6 +1061,10 @@ describe('AppDriver.isNameAvailable', () => {
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('reports an app-uid-shaped name as unavailable', async () => {
|
||||
expect(await driver.isNameAvailable(`app-${uuidv4()}`)).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects an invalid name format with 400', async () => {
|
||||
await expect(driver.isNameAvailable('has spaces')).rejects.toMatchObject(
|
||||
{ statusCode: 400 },
|
||||
|
||||
@@ -20,7 +20,7 @@ puter.apps.create(options)
|
||||
|
||||
#### `name` (required)
|
||||
|
||||
The name of the app to create. App names are unique across all Puter accounts. If any app already has this name, the promise will be rejected.
|
||||
The name of the app to create. App names are unique across all Puter accounts. If any app already has this name, the promise will be rejected. Names in the form of an app UID (`app-` followed by a UUID) are reserved and rejected.
|
||||
|
||||
#### `indexURL` (required)
|
||||
|
||||
@@ -43,7 +43,7 @@ An object containing the options for the app to create. The object can contain t
|
||||
|
||||
| Option | Type | Description |
|
||||
|--------|------|-------------|
|
||||
| `name` | `String` | Required. The name of the app to create. App names are unique across all Puter accounts. If any app already has this name, the promise will be rejected. |
|
||||
| `name` | `String` | Required. The name of the app to create. App names are unique across all Puter accounts. If any app already has this name, the promise will be rejected. Names in the form of an app UID (`app-` followed by a UUID) are reserved and rejected. |
|
||||
| `indexURL` | `String` | Required. The URL of the app's index page. This URL must be accessible to the user. If it's missing, the promise will be rejected. |
|
||||
| `title` | `String` | The human-readable title of the app. If it's missing, the app will be created with `name` as its title. |
|
||||
| `description` | `String` | The description of the app aimed at the end user. |
|
||||
|
||||
@@ -24,7 +24,7 @@ An object containing the attributes to update. The object can contain the follow
|
||||
| `indexURL` | `String` | The new URL of the app's index page. This URL must be accessible to the user. |
|
||||
| `description` | `String` | The new description of the app aimed at the end user. |
|
||||
| `icon` | `String` | The new icon of the app. |
|
||||
| `name` | `String` | The new name of the app. App names are unique across all Puter accounts. If any app already has this name, the promise will be rejected. |
|
||||
| `name` | `String` | The new name of the app. App names are unique across all Puter accounts. If any app already has this name, the promise will be rejected. Names in the form of an app UID (`app-` followed by a UUID) are reserved and rejected. |
|
||||
| `filetypeAssociations` | `Array<String>` | An array of strings representing the filetypes that the app can open. Defaults to `[]`. File extensions and MIME types are supported. For example, `[".txt", ".md", "application/pdf"]` would allow the app to open `.txt`, `.md`, and PDF files. At most 200 entries, each at most 60 characters. |
|
||||
| `maximizeOnStart` | `Boolean` | Whether the app should be maximized when it is started. Defaults to `false`. |
|
||||
| `background` | `Boolean` | Whether the app should run in the background. Defaults to `false`. |
|
||||
|
||||
Reference in new issue
Block a user