Skip to content

Commit

Permalink
fix(core): disable bring your ui feature for admin tenant (#6300)
Browse files Browse the repository at this point in the history
  • Loading branch information
charIeszhao committed Jul 23, 2024
1 parent 3cb3e5f commit 27e0d36
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFile } from 'node:fs/promises';

import { uploadFileGuard, maxUploadFileSize } from '@logto/schemas';
import { uploadFileGuard, maxUploadFileSize, adminTenantId } from '@logto/schemas';
import { generateStandardId } from '@logto/shared';
import pRetry, { AbortError } from 'p-retry';
import { object, z } from 'zod';
Expand Down Expand Up @@ -53,6 +53,10 @@ export default function customUiAssetsRoutes<T extends ManagementApiRouter>(
assertThat(file.size <= maxUploadFileSize, 'guard.file_size_exceeded');
assertThat(file.mimetype === 'application/zip', 'guard.mime_type_not_allowed');

const [tenantId] = await getTenantId(ctx.URL);
assertThat(tenantId, 'guard.can_not_get_tenant_id');
assertThat(tenantId !== adminTenantId, 'guard.not_allowed_for_admin_tenant');

const { experienceZipsProviderConfig } = SystemContext.shared;
assertThat(
experienceZipsProviderConfig?.provider === 'AzureStorage',
Expand All @@ -65,9 +69,6 @@ export default function customUiAssetsRoutes<T extends ManagementApiRouter>(
container
);

const [tenantId] = await getTenantId(ctx.URL);
assertThat(tenantId, 'guard.can_not_get_tenant_id');

const customUiAssetId = generateStandardId(8);
const objectKey = `${tenantId}/${customUiAssetId}/assets.zip`;
const errorLogObjectKey = `${tenantId}/${customUiAssetId}/error.log`;
Expand Down
1 change: 1 addition & 0 deletions packages/phrases/src/locales/en/errors/guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const guard = {
can_not_get_tenant_id: 'Unable to get tenant id from request.',
file_size_exceeded: 'File size exceeded.',
mime_type_not_allowed: 'MIME type is not allowed.',
not_allowed_for_admin_tenant: 'Not allowed for admin tenant.',
};

export default Object.freeze(guard);

0 comments on commit 27e0d36

Please sign in to comment.