Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
use postgres blob storage for logos + small tweaks
x032205a28ac7b3e9a0
diff --git a/backend/src/@types/knex.d.ts b/backend/src/@types/knex.d.tsindex 38fe64712e..15eb2bc889 100644--- a/backend/src/@types/knex.d.ts+++ b/backend/src/@types/knex.d.ts@@ -510,6 +510,9 @@ import {TSecretScanningScans,TSecretScanningScansInsert,TSecretScanningScansUpdate,+ TSecretShareBrandingAssets,+ TSecretShareBrandingAssetsInsert,+ TSecretShareBrandingAssetsUpdate,TSecretSharing,TSecretSharingInsert,TSecretSharingUpdate,@@ -1611,5 +1614,10 @@ declare module "knex/types/tables" {TApprovalRequestsInsert,TApprovalRequestsUpdate>;+ [TableName.SecretShareBrandingAsset]: KnexOriginal.CompositeTableType<+ TSecretShareBrandingAssets,+ TSecretShareBrandingAssetsInsert,+ TSecretShareBrandingAssetsUpdate+ >;}}diff --git a/backend/src/db/migrations/20260109205558_secret-share-brand-config.ts b/backend/src/db/migrations/20260109205558_secret-share-brand-config.tsindex e0570194c7..5542a2413c 100644--- a/backend/src/db/migrations/20260109205558_secret-share-brand-config.ts+++ b/backend/src/db/migrations/20260109205558_secret-share-brand-config.ts@@ -3,17 +3,38 @@ import { Knex } from "knex";import { TableName } from "../schemas";export async function up(knex: Knex): Promise<void> {- const hasColumn = await knex.schema.hasColumn(TableName.Organization, "secretShareBrandConfig");- if (!hasColumn) {+ const hasConfigColumn = await knex.schema.hasColumn(TableName.Organization, "secretShareBrandConfig");+ if (!hasConfigColumn) {await knex.schema.alterTable(TableName.Organization, (t) => {t.jsonb("secretShareBrandConfig").nullable();});}++ // For storing logo/favicon images+ const hasAssetsTable = await knex.schema.hasTable(TableName.SecretShareBrandingAsset);+ if (!hasAssetsTable) {+ await knex.schema.createTable(TableName.SecretShareBrandingAsset, (t) => {+ t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());+ t.uuid("orgId").notNullable();+ t.foreign("orgId").references("id").inTable(TableName.Organization).onDelete("CASCADE");+ t.string("assetType").notNullable(); // 'logo' or 'favicon'+ t.binary("data").notNullable();+ t.string("contentType").notNullable();+ t.integer("size").notNullable();+ t.timestamps(true, true, true);+ t.unique(["orgId", "assetType"]);+ });+ }}export async function down(knex: Knex): Promise<void> {- const hasColumn = await knex.schema.hasColumn(TableName.Organization, "secretShareBrandConfig");- if (hasColumn) {+ const hasAssetsTable = await knex.schema.hasTable(TableName.SecretShareBrandingAsset);+ if (hasAssetsTable) {+ await knex.schema.dropTable(TableName.SecretShareBrandingAsset);+ }++ const hasConfigColumn = await knex.schema.hasColumn(TableName.Organization, "secretShareBrandConfig");+ if (hasConfigColumn) {await knex.schema.alterTable(TableName.Organization, (t) => {t.dropColumn("secretShareBrandConfig");});diff --git a/backend/src/db/schemas/index.ts b/backend/src/db/schemas/index.tsindex 238b40e60b..c3c1f1e063 100644--- a/backend/src/db/schemas/index.ts+++ b/backend/src/db/schemas/index.ts@@ -174,6 +174,7 @@ export * from "./secret-scanning-findings";export * from "./secret-scanning-git-risks";export * from "./secret-scanning-resources";export * from "./secret-scanning-scans";+export * from "./secret-share-branding-assets";export * from "./secret-sharing";export * from "./secret-snapshot-folders";export * from "./secret-snapshot-secrets";diff --git a/backend/src/db/schemas/models.ts b/backend/src/db/schemas/models.tsindex 627d97b403..c366bd2bec 100644--- a/backend/src/db/schemas/models.ts+++ b/backend/src/db/schemas/models.ts@@ -70,6 +70,7 @@ export enum TableName {Secret = "secrets",SecretReference = "secret_references",SecretSharing = "secret_sharing",+ SecretShareBrandingAsset = "secret_share_branding_assets",SecretBlindIndex = "secret_blind_indexes",SecretVersion = "secret_versions",SecretFolder = "secret_folders",diff --git a/backend/src/db/schemas/secret-share-branding-assets.ts b/backend/src/db/schemas/secret-share-branding-assets.tsnew file mode 100644index 0000000000..d0375f1fe8--- /dev/null+++ b/backend/src/db/schemas/secret-share-branding-assets.ts@@ -0,0 +1,27 @@+// Code generated by automation script, DO NOT EDIT.+// Automated by pulling database and generating zod schema+// To update. Just run npm run generate:schema+// Written by akhilmhdh.++import { z } from "zod";++import { zodBuffer } from "@app/lib/zod";++import { TImmutableDBKeys } from "./models";++export const SecretShareBrandingAssetsSchema = z.object({+ id: z.string().uuid(),+ orgId: z.string().uuid(),+ assetType: z.string(),+ data: zodBuffer,+ contentType: z.string(),+ size: z.number(),+ createdAt: z.date(),+ updatedAt: z.date()+});++export type TSecretShareBrandingAssets = z.infer<typeof SecretShareBrandingAssetsSchema>;+export type TSecretShareBrandingAssetsInsert = Omit<z.input<typeof SecretShareBrandingAssetsSchema>, TImmutableDBKeys>;+export type TSecretShareBrandingAssetsUpdate = Partial<+ Omit<z.input<typeof SecretShareBrandingAssetsSchema>, TImmutableDBKeys>+>;diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.tsindex 5c119b5337..d07cc9c1b7 100644--- a/backend/src/server/routes/index.ts+++ b/backend/src/server/routes/index.ts@@ -363,6 +363,7 @@ import { secretFolderVersionDALFactory } from "@app/services/secret-folder/secreimport { secretImportDALFactory } from "@app/services/secret-import/secret-import-dal";import { secretImportServiceFactory } from "@app/services/secret-import/secret-import-service";import { secretReminderRecipientsDALFactory } from "@app/services/secret-reminder-recipients/secret-reminder-recipients-dal";+import { secretShareBrandingAssetDALFactory } from "@app/services/secret-sharing/secret-share-branding-asset-dal";import { secretSharingDALFactory } from "@app/services/secret-sharing/secret-sharing-dal";import { secretSharingServiceFactory } from "@app/services/secret-sharing/secret-sharing-service";import { secretSyncDALFactory } from "@app/services/secret-sync/secret-sync-dal";@@ -552,6 +553,7 @@ export const registerRoutes = async (const userGroupMembershipDAL = userGroupMembershipDALFactory(db);const secretScanningDAL = secretScanningDALFactory(db);const secretSharingDAL = secretSharingDALFactory(db);+ const secretShareBrandingAssetDAL = secretShareBrandingAssetDALFactory(db);const licenseDAL = licenseDALFactory(db);const dynamicSecretDAL = dynamicSecretDALFactory(db);const dynamicSecretLeaseDAL = dynamicSecretLeaseDALFactory(db);@@ -1575,6 +1577,7 @@ export const registerRoutes = async (const secretSharingService = secretSharingServiceFactory({permissionService,secretSharingDAL,+ secretShareBrandingAssetDAL,orgDAL,kmsService,smtpService,diff --git a/backend/src/server/routes/v1/organization-router.ts b/backend/src/server/routes/v1/organization-router.tsindex d36a3ece13..6ade78663b 100644--- a/backend/src/server/routes/v1/organization-router.ts+++ b/backend/src/server/routes/v1/organization-router.ts@@ -323,8 +323,6 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {.describe("Block duplicate secret sync destinations across the organization"),secretShareBrandConfig: z.object({- faviconUrl: z.string().url().optional().or(z.literal("")),- logoUrl: z.string().url().optional().or(z.literal("")),primaryColor: z.string().refine(diff --git a/backend/src/server/routes/v1/secret-sharing-router.ts b/backend/src/server/routes/v1/secret-sharing-router.tsindex f459656807..a3209a2321 100644--- a/backend/src/server/routes/v1/secret-sharing-router.ts+++ b/backend/src/server/routes/v1/secret-sharing-router.ts@@ -1,3 +1,4 @@+import fastifyMultipart from "@fastify/multipart";import { z } from "zod";import { SecretSharingSchema } from "@app/db/schemas";@@ -22,9 +23,16 @@ const ALLOWED_IMAGE_CONTENT_TYPES = ["image/x-icon","image/webp"];-const MAX_IMAGE_SIZE = 5 * 1024 * 1024; // 5MB+const MAX_IMAGE_SIZE = 1 * 1024 * 1024; // 1MBexport const registerSecretSharingRouter = async (server: FastifyZodProvider) => {+ // Allow multipart file uploads+ await server.register(fastifyMultipart, {+ limits: {+ fileSize: MAX_IMAGE_SIZE+ }+ });+server.route({method: "GET",url: "/",@@ -80,8 +88,8 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>isPasswordProtected: z.boolean(),brandingConfig: z.object({- hasLogoUrl: z.boolean(),- hasFaviconUrl: z.boolean(),+ hasLogo: z.boolean(),+ hasFavicon: z.boolean(),primaryColor: z.string().optional(),secondaryColor: z.string().optional()})@@ -119,8 +127,8 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>if (orgBrandConfig) {brandingConfig = {- hasLogoUrl: Boolean(orgBrandConfig.logoUrl),- hasFaviconUrl: Boolean(orgBrandConfig.faviconUrl),+ hasLogo: orgBrandConfig.hasLogo,+ hasFavicon: orgBrandConfig.hasFavicon,primaryColor: orgBrandConfig.primaryColor,secondaryColor: orgBrandConfig.secondaryColor};@@ -277,7 +285,7 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>}});- // Endpoint to proxy external branding images+ // Serve branding images from database - public (using shared secret ID)server.route({method: "GET",url: "/public/:id/branding/:assetType",@@ -299,44 +307,159 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>throw new NotFoundError({ message: "Shared secret not found or has no organization" });}- const orgBrandConfig = await req.server.services.secretSharing.getOrgBrandConfig(orgId);+ const asset = await req.server.services.secretSharing.getBrandingAsset(orgId, assetType);- if (!orgBrandConfig) {- throw new NotFoundError({ message: "No branding configured for this organization" });+ if (!asset) {+ throw new NotFoundError({ message: `No ${assetType} configured for this organization` });}- const imageUrl = assetType === "logo" ? orgBrandConfig.logoUrl : orgBrandConfig.faviconUrl;+ void res.header("Content-Type", asset.contentType);+ void res.header("Cache-Control", "public, max-age=3600"); // Cache for 1 hour- if (!imageUrl) {- throw new NotFoundError({ message: `No ${assetType} configured for this organization` });- }+ return res.send(asset.data);+ }+ });- // Fetch image- const response = await fetch(imageUrl);+ // Upload branding asset+ server.route({+ method: "POST",+ url: "/branding/:assetType",+ config: {+ rateLimit: writeLimit+ },+ schema: {+ params: z.object({+ assetType: z.enum(["logo", "favicon"])+ }),+ response: {+ 200: z.object({+ message: z.string()+ })+ }+ },+ onRequest: verifyAuth([AuthMode.JWT]),+ handler: async (req) => {+ const { assetType } = req.params;+ const file = await req.file();- if (!response.ok) {- throw new BadRequestError({ message: `Failed to fetch ${assetType}` });+ if (!file) {+ throw new BadRequestError({ message: "No file uploaded" });}- const contentType = response.headers.get("content-type") || "application/octet-stream";- const contentLength = response.headers.get("content-length");+ const buffer = await file.toBuffer();++ // Validate size+ if (buffer.length > MAX_IMAGE_SIZE) {+ throw new BadRequestError({ message: `File too large. Maximum size is ${MAX_IMAGE_SIZE / 1024 / 1024}MB` });+ }// Validate content type- if (!ALLOWED_IMAGE_CONTENT_TYPES.some((allowed) => contentType.startsWith(allowed))) {- throw new BadRequestError({ message: "Invalid image type" });+ const contentType = file.mimetype;+ if (!ALLOWED_IMAGE_CONTENT_TYPES.includes(contentType)) {+ throw new BadRequestError({+ message: `Invalid file type. Allowed types: ${ALLOWED_IMAGE_CONTENT_TYPES.join(", ")}`+ });}- // Validate size- if (contentLength && parseInt(contentLength, 10) > MAX_IMAGE_SIZE) {- throw new BadRequestError({ message: "Image too large" });+ await req.server.services.secretSharing.uploadBrandingAsset(+ req.permission.orgId,+ assetType,+ buffer,+ contentType,+ req.permission+ );++ return { message: `Successfully uploaded ${assetType}` };+ }+ });++ // Delete branding asset+ server.route({+ method: "DELETE",+ url: "/branding/:assetType",+ config: {+ rateLimit: writeLimit+ },+ schema: {+ params: z.object({+ assetType: z.enum(["logo", "favicon"])+ }),+ response: {+ 200: z.object({+ message: z.string()+ })}+ },+ onRequest: verifyAuth([AuthMode.JWT]),+ handler: async (req) => {+ const { assetType } = req.params;- const imageBuffer = Buffer.from(await response.arrayBuffer());+ await req.server.services.secretSharing.deleteBrandingAsset(req.permission.orgId, assetType, req.permission);- void res.header("Content-Type", contentType);- void res.header("Cache-Control", "public, max-age=3600"); // Cache for 1 hour+ return { message: `Successfully deleted ${assetType}` };+ }+ });++ // Get branding config for current org+ server.route({+ method: "GET",+ url: "/branding",+ config: {+ rateLimit: readLimit+ },+ schema: {+ response: {+ 200: z.object({+ hasLogo: z.boolean(),+ hasFavicon: z.boolean(),+ primaryColor: z.string().optional(),+ secondaryColor: z.string().optional()+ })+ }+ },+ onRequest: verifyAuth([AuthMode.JWT]),+ handler: async (req) => {+ const config = await req.server.services.secretSharing.getOrgBrandConfig(req.permission.orgId, req.permission);++ return {+ hasLogo: config?.hasLogo ?? false,+ hasFavicon: config?.hasFavicon ?? false,+ primaryColor: config?.primaryColor,+ secondaryColor: config?.secondaryColor+ };+ }+ });++ // Get branding asset for current org - authenticated (for settings page preview)+ server.route({+ method: "GET",+ url: "/branding/:assetType",+ config: {+ rateLimit: readLimit+ },+ schema: {+ params: z.object({+ assetType: z.enum(["logo", "favicon"])+ })+ },+ onRequest: verifyAuth([AuthMode.JWT]),+ handler: async (req, res) => {+ const { assetType } = req.params;++ const asset = await req.server.services.secretSharing.getBrandingAsset(+ req.permission.orgId,+ assetType,+ req.permission+ );++ if (!asset) {+ throw new NotFoundError({ message: `No ${assetType} configured for this organization` });+ }++ void res.header("Content-Type", asset.contentType);+ void res.header("Cache-Control", "private, max-age=300");- return res.send(imageBuffer);+ return res.send(asset.data);}});};diff --git a/backend/src/services/org/org-types.ts b/backend/src/services/org/org-types.tsindex b35b093516..e182e88953 100644--- a/backend/src/services/org/org-types.ts+++ b/backend/src/services/org/org-types.ts@@ -70,8 +70,6 @@ export type TFindAllWorkspacesDTO = {};export type TSecretShareBrandConfig = {- faviconUrl?: string;- logoUrl?: string;primaryColor?: string;secondaryColor?: string;} | null;diff --git a/backend/src/services/secret-sharing/secret-share-branding-asset-dal.ts b/backend/src/services/secret-sharing/secret-share-branding-asset-dal.tsnew file mode 100644index 0000000000..211816a6bd--- /dev/null+++ b/backend/src/services/secret-sharing/secret-share-branding-asset-dal.ts@@ -0,0 +1,38 @@+import { TDbClient } from "@app/db";+import { TableName } from "@app/db/schemas";+import { ormify } from "@app/lib/knex";++export type TSecretShareBrandingAssetDALFactory = ReturnType<typeof secretShareBrandingAssetDALFactory>;++export const secretShareBrandingAssetDALFactory = (db: TDbClient) => {+ const brandingAssetOrm = ormify(db, TableName.SecretShareBrandingAsset);++ const findByOrgIdAndType = async (orgId: string, assetType: string) => {+ const asset = await db.replicaNode()(TableName.SecretShareBrandingAsset).where({ orgId, assetType }).first();+ return asset;+ };++ const upsert = async (orgId: string, assetType: string, data: Buffer, contentType: string, size: number) => {+ const existing = await findByOrgIdAndType(orgId, assetType);+ if (existing) {+ return brandingAssetOrm.updateById(existing.id, { data, contentType, size });+ }+ return brandingAssetOrm.create({ orgId, assetType, data, contentType, size });+ };++ const deleteByOrgIdAndType = async (orgId: string, assetType: string) => {+ await db(TableName.SecretShareBrandingAsset).where({ orgId, assetType }).delete();+ };++ const findAllByOrgId = async (orgId: string) => {+ return db.replicaNode()(TableName.SecretShareBrandingAsset).where({ orgId });+ };++ return {+ ...brandingAssetOrm,+ findByOrgIdAndType,+ upsert,+ deleteByOrgIdAndType,+ findAllByOrgId+ };+};diff --git a/backend/src/services/secret-sharing/secret-sharing-service.ts b/backend/src/services/secret-sharing/secret-sharing-service.tsindex f7ca256e13..dc9bdad6aa 100644--- a/backend/src/services/secret-sharing/secret-sharing-service.ts+++ b/backend/src/services/secret-sharing/secret-sharing-service.ts@@ -4,13 +4,14 @@ import { getConfig } from "@app/lib/config/env";import { crypto } from "@app/lib/crypto/cryptography";import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";import { logger } from "@app/lib/logger";-import { SecretSharingAccessType } from "@app/lib/types";+import { OrgServiceActor, SecretSharingAccessType } from "@app/lib/types";import { isUuidV4 } from "@app/lib/validator";import { TKmsServiceFactory } from "../kms/kms-service";import { TOrgDALFactory } from "../org/org-dal";import { SmtpTemplates, TSmtpService } from "../smtp/smtp-service";import { TUserDALFactory } from "../user/user-dal";+import { TSecretShareBrandingAssetDALFactory } from "./secret-share-branding-asset-dal";import { TSecretSharingDALFactory } from "./secret-sharing-dal";import {SecretSharingType,@@ -24,10 +25,14 @@ import {TRevealSecretRequestValueDTO,TSetSecretRequestValueDTO} from "./secret-sharing-types";+import { ForbiddenError } from "@casl/ability";+import { OrgPermissionSecretShareAction, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";+import { TSecretShareBrandConfig } from "../org/org-types";type TSecretSharingServiceFactoryDep = {permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;secretSharingDAL: TSecretSharingDALFactory;+ secretShareBrandingAssetDAL: TSecretShareBrandingAssetDALFactory;orgDAL: TOrgDALFactory;userDAL: TUserDALFactory;kmsService: TKmsServiceFactory;@@ -39,6 +44,7 @@ export type TSecretSharingServiceFactory = ReturnType<typeof secretSharingServicexport const secretSharingServiceFactory = ({permissionService,secretSharingDAL,+ secretShareBrandingAssetDAL,orgDAL,kmsService,smtpService,@@ -645,16 +651,107 @@ export const secretSharingServiceFactory = ({return sharedSecret?.orgId ?? null;};- const getOrgBrandConfig = async (- orgId: string- ): Promise<{- faviconUrl?: string;- logoUrl?: string;- primaryColor?: string;- secondaryColor?: string;- } | null> => {+ const getOrgBrandConfig = async (orgId: string, actor?: OrgServiceActor) => {+ // When accessed via public endpoint (from shared secret), don't check permission+ if (actor) {+ const { permission } = await permissionService.getOrgPermission({+ actor: actor.type,+ actorId: actor.id,+ orgId,+ actorAuthMethod: actor.authMethod,+ actorOrgId: actor.orgId,+ scope: OrganizationActionScope.ParentOrganization+ });++ ForbiddenError.from(permission).throwUnlessCan(+ OrgPermissionSecretShareAction.ManageSettings,+ OrgPermissionSubjects.SecretShare+ );+ }+const org = await orgDAL.findOrgById(orgId);- return org?.secretShareBrandConfig ?? null;+ const assets = await secretShareBrandingAssetDAL.findAllByOrgId(orgId);++ const hasLogo = assets.some((a) => a.assetType === "logo");+ const hasFavicon = assets.some((a) => a.assetType === "favicon");++ const config = org?.secretShareBrandConfig as TSecretShareBrandConfig;++ if (!config && !hasLogo && !hasFavicon) {+ return null;+ }++ return {+ hasLogo,+ hasFavicon,+ primaryColor: config?.primaryColor,+ secondaryColor: config?.secondaryColor+ };+ };++ const getBrandingAsset = async (orgId: string, assetType: string, actor?: OrgServiceActor) => {+ // When accessed via public endpoint (from shared secret), don't check permission+ if (actor) {+ const { permission } = await permissionService.getOrgPermission({+ actor: actor.type,+ actorId: actor.id,+ orgId,+ actorAuthMethod: actor.authMethod,+ actorOrgId: actor.orgId,+ scope: OrganizationActionScope.ParentOrganization+ });++ ForbiddenError.from(permission).throwUnlessCan(+ OrgPermissionSecretShareAction.ManageSettings,+ OrgPermissionSubjects.SecretShare+ );+ }++ const asset = await secretShareBrandingAssetDAL.findByOrgIdAndType(orgId, assetType);+ return asset;+ };++ const uploadBrandingAsset = async (+ orgId: string,+ assetType: string,+ data: Buffer,+ contentType: string,+ actor: OrgServiceActor+ ) => {+ const { permission } = await permissionService.getOrgPermission({+ actor: actor.type,+ actorId: actor.id,+ orgId,+ actorAuthMethod: actor.authMethod,+ actorOrgId: actor.orgId,+ scope: OrganizationActionScope.ParentOrganization+ });++ ForbiddenError.from(permission).throwUnlessCan(+ OrgPermissionSecretShareAction.ManageSettings,+ OrgPermissionSubjects.SecretShare+ );++ const size = data.length;+ return secretShareBrandingAssetDAL.upsert(orgId, assetType, data, contentType, size);+ };++ const deleteBrandingAsset = async (orgId: string, assetType: string, actor: OrgServiceActor) => {+ const { permission } = await permissionService.getOrgPermission({+ actor: actor.type,+ actorId: actor.id,+ orgId,+ actorAuthMethod: actor.authMethod,+ actorOrgId: actor.orgId,+ scope: OrganizationActionScope.ParentOrganization+ });++ ForbiddenError.from(permission).throwUnlessCan(+ OrgPermissionSecretShareAction.ManageSettings,+ OrgPermissionSubjects.SecretShare+ );++ await secretShareBrandingAssetDAL.deleteByOrgIdAndType(orgId, assetType);};return {@@ -665,6 +762,9 @@ export const secretSharingServiceFactory = ({getSharedSecretById,getSharedSecretOrgId,getOrgBrandConfig,+ getBrandingAsset,+ uploadBrandingAsset,+ deleteBrandingAsset,createSecretRequest,getSecretRequestById,diff --git a/frontend/src/hooks/api/organization/types.ts b/frontend/src/hooks/api/organization/types.tsindex 331f3761e0..b76e37923c 100644--- a/frontend/src/hooks/api/organization/types.ts+++ b/frontend/src/hooks/api/organization/types.ts@@ -4,8 +4,6 @@ import { IdentityMembershipOrg } from "@app/hooks/api/identities/types";import { MfaMethod } from "../auth/types";export type TSecretShareBrandConfig = {- faviconUrl?: string;- logoUrl?: string;primaryColor?: string;secondaryColor?: string;} | null;diff --git a/frontend/src/hooks/api/secretSharing/mutations.ts b/frontend/src/hooks/api/secretSharing/mutations.tsindex 89390d5320..db952577d9 100644--- a/frontend/src/hooks/api/secretSharing/mutations.ts+++ b/frontend/src/hooks/api/secretSharing/mutations.ts@@ -112,3 +112,45 @@ export const useDeleteSecretRequest = () => {}});};++export const useUploadBrandingAsset = () => {+ const queryClient = useQueryClient();+ return useMutation<+ { message: string },+ { message: string },+ { assetType: "logo" | "favicon"; file: File }+ >({+ mutationFn: async ({ assetType, file }) => {+ const formData = new FormData();+ formData.append("file", file);+ const { data } = await apiRequest.post<{ message: string }>(+ `/api/v1/secret-sharing/shared/branding/${assetType}`,+ formData,+ {+ headers: {+ "Content-Type": "multipart/form-data"+ }+ }+ );+ return data;+ },+ onSuccess: () => {+ queryClient.invalidateQueries({ queryKey: secretSharingKeys.brandingAssets() });+ }+ });+};++export const useDeleteBrandingAsset = () => {+ const queryClient = useQueryClient();+ return useMutation<{ message: string }, { message: string }, { assetType: "logo" | "favicon" }>({+ mutationFn: async ({ assetType }) => {+ const { data } = await apiRequest.delete<{ message: string }>(+ `/api/v1/secret-sharing/shared/branding/${assetType}`+ );+ return data;+ },+ onSuccess: () => {+ queryClient.invalidateQueries({ queryKey: secretSharingKeys.brandingAssets() });+ }+ });+};diff --git a/frontend/src/hooks/api/secretSharing/queries.ts b/frontend/src/hooks/api/secretSharing/queries.tsindex 13867aa05c..cdd1edf2a2 100644--- a/frontend/src/hooks/api/secretSharing/queries.ts+++ b/frontend/src/hooks/api/secretSharing/queries.ts@@ -2,7 +2,12 @@ import { useQuery } from "@tanstack/react-query";import { apiRequest } from "@app/config/request";-import { TGetSecretRequestByIdResponse, TSharedSecret, TViewSharedSecretResponse } from "./types";+import {+ TBrandingConfig,+ TGetSecretRequestByIdResponse,+ TSharedSecret,+ TViewSharedSecretResponse+} from "./types";export const secretSharingKeys = {allSharedSecrets: () => ["sharedSecrets"] as const,@@ -15,7 +20,8 @@ export const secretSharingKeys = {"shared-secret",arg],- getSecretRequestById: (arg: { id: string }) => ["secret-request", arg] as const+ getSecretRequestById: (arg: { id: string }) => ["secret-request", arg] as const,+ brandingAssets: () => ["brandingAssets"] as const};export const useGetSharedSecrets = ({@@ -109,3 +115,15 @@ export const useGetSecretRequestById = ({ secretRequestId }: { secretRequestId:}});};++export const useGetBrandingConfig = () => {+ return useQuery({+ queryKey: secretSharingKeys.brandingAssets(),+ queryFn: async () => {+ const { data } = await apiRequest.get<TBrandingConfig>(+ "/api/v1/secret-sharing/shared/branding"+ );+ return data;+ }+ });+};diff --git a/frontend/src/hooks/api/secretSharing/types.ts b/frontend/src/hooks/api/secretSharing/types.tsindex 8567222816..497a0c22c3 100644--- a/frontend/src/hooks/api/secretSharing/types.ts+++ b/frontend/src/hooks/api/secretSharing/types.ts@@ -61,14 +61,16 @@ export type TSharedSecretResponse = {expiresAfterViews?: number | null;};+export type TBrandingConfig = {+ hasLogo: boolean;+ hasFavicon: boolean;+ primaryColor?: string;+ secondaryColor?: string;+};+export type TViewSharedSecretResponse = {isPasswordProtected: boolean;- brandingConfig?: {- hasLogoUrl: boolean;- hasFaviconUrl: boolean;- primaryColor?: string;- secondaryColor?: string;- };+ brandingConfig?: TBrandingConfig;secret?: TSharedSecretResponse;error?: string;};diff --git a/frontend/src/pages/organization/SecretSharingPage/components/SecretSharingSettings/SecretSharingAllowShareToAnyone.tsx b/frontend/src/pages/organization/SecretSharingPage/components/SecretSharingSettings/SecretSharingAllowShareToAnyone.tsxindex 31b2221ce0..4a42d89a23 100644--- a/frontend/src/pages/organization/SecretSharingPage/components/SecretSharingSettings/SecretSharingAllowShareToAnyone.tsx+++ b/frontend/src/pages/organization/SecretSharingPage/components/SecretSharingSettings/SecretSharingAllowShareToAnyone.tsx@@ -23,28 +23,26 @@ export const SecretSharingAllowShareToAnyone = () => {};return (- <div className="mb-4 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-6">- <div className="py-4">- <div className="mb-2 flex justify-between">- <h3 className="text-md text-mineshaft-100">- Allow sharing secrets to members outside of this organization- </h3>- <OrgPermissionCan I={OrgPermissionActions.Edit} a={OrgPermissionSubjects.Settings}>- {(isAllowed) => (- <Switch- id="enable-secret-sharing-outside-org"- onCheckedChange={(value) => handleSecretSharingToggle(value)}- isChecked={currentOrg?.allowSecretSharingOutsideOrganization ?? false}- isDisabled={!isAllowed}- />- )}- </OrgPermissionCan>- </div>- <p className="text-sm text-mineshaft-300">- If enabled, team members will be able to share secrets to members outside of this- organization- </p>+ <div className="mb-4 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4">+ <div className="mb-2 flex justify-between">+ <h3 className="text-md text-mineshaft-100">+ Allow sharing secrets to members outside of this organization+ </h3>+ <OrgPermissionCan I={OrgPermissionActions.Edit} a={OrgPermissionSubjects.Settings}>+ {(isAllowed) => (+ <Switch+ id="enable-secret-sharing-outside-org"+ onCheckedChange={(value) => handleSecretSharingToggle(value)}+ isChecked={currentOrg?.allowSecretSharingOutsideOrganization ?? false}+ isDisabled={!isAllowed}+ />+ )}+ </OrgPermissionCan></div>+ <p className="text-sm text-mineshaft-300">+ If enabled, team members will be able to share secrets to members outside of this+ organization+ </p></div>);};diff --git a/frontend/src/pages/organization/SecretSharingPage/components/SecretSharingSettings/SecretSharingBrandingSection.tsx b/frontend/src/pages/organization/SecretSharingPage/components/SecretSharingSettings/SecretSharingBrandingSection.tsxindex 9a014eb8e6..ec70efa0b4 100644--- a/frontend/src/pages/organization/SecretSharingPage/components/SecretSharingSettings/SecretSharingBrandingSection.tsx+++ b/frontend/src/pages/organization/SecretSharingPage/components/SecretSharingSettings/SecretSharingBrandingSection.tsx@@ -1,13 +1,14 @@-import { useEffect } from "react";+import { useEffect, useRef, useState } from "react";import { Controller, useForm } from "react-hook-form";import { zodResolver } from "@hookform/resolvers/zod";-import { LockIcon } from "lucide-react";+import { LockIcon, TrashIcon, UploadIcon } from "lucide-react";import { z } from "zod";import { createNotification } from "@app/components/notifications";import { OrgPermissionCan } from "@app/components/permissions";import { Button, FormControl, Input } from "@app/components/v2";-import { Badge } from "@app/components/v3";+import { Badge, UnstableButton } from "@app/components/v3";+import { apiRequest } from "@app/config/request";import {OrgPermissionActions,OrgPermissionSubjects,@@ -15,12 +16,24 @@ import {useSubscription} from "@app/context";import { useUpdateOrg } from "@app/hooks/api";+import {+ useDeleteBrandingAsset,+ useGetBrandingConfig,+ useUploadBrandingAsset+} from "@app/hooks/api/secretSharing";const hexColorRegex = /^#[0-9A-Fa-f]{6}$/;+const MAX_FILE_SIZE = 1 * 1024 * 1024; // 1MB+const ALLOWED_FILE_TYPES = [+ "image/png",+ "image/jpeg",+ "image/gif",+ "image/svg+xml",+ "image/x-icon",+ "image/webp"+];const formSchema = z.object({- logoUrl: z.string().url("Must be a valid URL").or(z.literal("")).optional(),- faviconUrl: z.string().url("Must be a valid URL").or(z.literal("")).optional(),primaryColor: z.string().regex(hexColorRegex, "Must be a valid hex color (e.g., #FF5733)")@@ -35,12 +48,159 @@ const formSchema = z.object({type TForm = z.infer<typeof formSchema>;+const validateFile = (file: File): string | null => {+ if (file.size > MAX_FILE_SIZE) {+ return `File too large. Maximum size is ${MAX_FILE_SIZE / 1024 / 1024}MB`;+ }+ if (!ALLOWED_FILE_TYPES.includes(file.type)) {+ return "Invalid file type. Please upload a PNG, JPEG, GIF, SVG, ICO, or WebP image.";+ }+ return null;+};++// Fetch image as base64 data URL using authenticated request+const fetchAssetAsDataUrl = async (assetType: "logo" | "favicon"): Promise<string | null> => {+ try {+ const response = await apiRequest.get(`/api/v1/secret-sharing/shared/branding/${assetType}`, {+ responseType: "blob"+ });+ const blob = response.data as Blob;+ return await new Promise((resolve) => {+ const reader = new FileReader();+ reader.onloadend = () => resolve(reader.result as string);+ reader.onerror = () => resolve(null);+ reader.readAsDataURL(blob);+ });+ } catch {+ return null;+ }+};++type AssetUploadCardProps = {+ assetType: "logo" | "favicon";+ title: string;+ description: string;+ hasAsset: boolean;+ isAllowed: boolean;+ isPending: boolean;+ onUpload: (assetType: "logo" | "favicon", file: File) => Promise<void>;+ onDelete: (assetType: "logo" | "favicon") => Promise<void>;+};++const AssetUploadCard = ({+ assetType,+ title,+ description,+ hasAsset,+ isAllowed,+ isPending,+ onUpload,+ onDelete+}: AssetUploadCardProps) => {+ const inputRef = useRef<HTMLInputElement>(null);+ const [previewUrl, setPreviewUrl] = useState<string | null>(null);+ const [isLoading, setIsLoading] = useState(false);++ // Fetch existing asset on mount if it exists+ useEffect(() => {+ if (hasAsset) {+ setIsLoading(true);+ fetchAssetAsDataUrl(assetType)+ .then((dataUrl) => {+ setPreviewUrl(dataUrl);+ })+ .finally(() => {+ setIsLoading(false);+ });+ } else {+ setPreviewUrl(null);+ }+ }, [hasAsset, assetType]);++ const handleFileChange = async (event: React.ChangeEvent<HTMLInputElement>) => {+ const file = event.target.files?.[0];+ if (file) {+ const error = validateFile(file);+ if (error) {+ createNotification({ text: error, type: "error" });+ return;+ }++ await onUpload(assetType, file);++ // Update preview with the uploaded file+ const reader = new FileReader();+ reader.onloadend = () => {+ setPreviewUrl(reader.result as string);+ };+ reader.readAsDataURL(file);+ }+ };++ const handleDelete = async () => {+ await onDelete(assetType);+ setPreviewUrl(null);+ };++ return (+ <div className="rounded-md border border-mineshaft-600 bg-mineshaft-800 p-3">+ <p className="mb-1 text-sm font-medium">{title}</p>+ <p className="mb-2 text-xs text-mineshaft-400">{description}</p>+ <input+ ref={inputRef}+ type="file"+ accept={ALLOWED_FILE_TYPES.join(",")}+ onChange={handleFileChange}+ className="hidden"+ disabled={!isAllowed || isPending}+ />+ <div className="flex gap-2">+ {isLoading ? (+ <div className="size-10 animate-pulse rounded border border-mineshaft-500 bg-mineshaft-600" />+ ) : (+ previewUrl && (+ <img+ src={previewUrl}+ alt={`${title} preview`}+ className="size-10 rounded border border-mineshaft-500 object-contain p-1"+ />+ )+ )}+ <UnstableButton+ variant="neutral"+ size="xs"+ onClick={() => inputRef.current?.click()}+ isDisabled={!isAllowed || isPending}+ >+ <UploadIcon />+ Upload {title}+ </UnstableButton>+ {previewUrl && (+ <UnstableButton+ variant="danger"+ size="xs"+ onClick={handleDelete}+ isDisabled={!isAllowed || isPending}+ >+ <TrashIcon />+ Delete+ </UnstableButton>+ )}+ </div>+ </div>+ );+};+export const SecretSharingBrandingSection = () => {const { currentOrg } = useOrganization();const { subscription } = useSubscription();- const { mutateAsync, isPending } = useUpdateOrg();+ const { mutateAsync: updateOrg, isPending: isUpdatingOrg } = useUpdateOrg();+ const { mutateAsync: uploadAsset, isPending: isUploadingAsset } = useUploadBrandingAsset();+ const { mutateAsync: deleteAsset, isPending: isDeletingAsset } = useDeleteBrandingAsset();+ const { data: brandingConfig } = useGetBrandingConfig();const isFeatureEnabled = subscription?.secretShareExternalBranding;+ const isPending = isUpdatingOrg || isUploadingAsset || isDeletingAsset;const {control,@@ -50,45 +210,45 @@ export const SecretSharingBrandingSection = () => {} = useForm<TForm>({resolver: zodResolver(formSchema),defaultValues: {- logoUrl: currentOrg?.secretShareBrandConfig?.logoUrl || "",- faviconUrl: currentOrg?.secretShareBrandConfig?.faviconUrl || "",primaryColor: currentOrg?.secretShareBrandConfig?.primaryColor || "",secondaryColor: currentOrg?.secretShareBrandConfig?.secondaryColor || ""}});- useEffect(() => {- if (currentOrg?.secretShareBrandConfig) {- reset({- logoUrl: currentOrg.secretShareBrandConfig.logoUrl || "",- faviconUrl: currentOrg.secretShareBrandConfig.faviconUrl || "",- primaryColor: currentOrg.secretShareBrandConfig.primaryColor || "",- secondaryColor: currentOrg.secretShareBrandConfig.secondaryColor || ""- });- }- }, [currentOrg?.secretShareBrandConfig, reset]);-const handleFormSubmit = async (data: TForm) => {if (!currentOrg?.id) return;- const hasAnyValue = data.logoUrl || data.faviconUrl || data.primaryColor || data.secondaryColor;-- await mutateAsync({+ await updateOrg({orgId: currentOrg.id,- secretShareBrandConfig: hasAnyValue- ? {- logoUrl: data.logoUrl || undefined,- faviconUrl: data.faviconUrl || undefined,- primaryColor: data.primaryColor || undefined,- secondaryColor: data.secondaryColor || undefined- }- : null+ secretShareBrandConfig:+ data.primaryColor || data.secondaryColor+ ? {+ primaryColor: data.primaryColor || undefined,+ secondaryColor: data.secondaryColor || undefined+ }+ : null});reset(data);createNotification({- text: "Successfully updated secret sharing branding",+ text: "Successfully updated branding colors",+ type: "success"+ });+ };++ const handleFileUpload = async (assetType: "logo" | "favicon", file: File) => {+ await uploadAsset({ assetType, file });+ createNotification({+ text: `Successfully uploaded ${assetType}`,+ type: "success"+ });+ };++ const handleFileDelete = async (assetType: "logo" | "favicon") => {+ await deleteAsset({ assetType });+ createNotification({+ text: `Successfully deleted ${assetType}`,type: "success"});};@@ -119,109 +279,98 @@ export const SecretSharingBrandingSection = () => {) : (<OrgPermissionCan I={OrgPermissionActions.Edit} a={OrgPermissionSubjects.Settings}>{(isAllowed) => (- <form onSubmit={handleSubmit(handleFormSubmit)} autoComplete="off">+ <div className="space-y-4"><div className="grid grid-cols-1 gap-4 md:grid-cols-2">- <Controller- control={control}- name="logoUrl"- render={({ field, fieldState: { error } }) => (- <FormControl- isError={Boolean(error)}- errorText={error?.message}- label="Logo URL"- tooltipText="URL to your company logo (displayed on shared secret pages)"- >- <Input- {...field}- placeholder="https://example.com/logo.png"- isDisabled={!isAllowed}- />- </FormControl>- )}+ <AssetUploadCard+ assetType="logo"+ title="Logo"+ description="Displayed on shared secret pages (max 1MB)"+ hasAsset={brandingConfig?.hasLogo ?? false}+ isAllowed={isAllowed}+ isPending={isPending}+ onUpload={handleFileUpload}+ onDelete={handleFileDelete}/>- <Controller- control={control}- name="faviconUrl"- render={({ field, fieldState: { error } }) => (- <FormControl- isError={Boolean(error)}- errorText={error?.message}- label="Favicon URL"- tooltipText="URL to your favicon (displayed in browser tab)"- >- <Input- {...field}- placeholder="https://example.com/favicon.ico"- isDisabled={!isAllowed}- />- </FormControl>- )}+ <AssetUploadCard+ assetType="favicon"+ title="Favicon"+ description="Displayed in browser tab (max 1MB)"+ hasAsset={brandingConfig?.hasFavicon ?? false}+ isAllowed={isAllowed}+ isPending={isPending}+ onUpload={handleFileUpload}+ onDelete={handleFileDelete}/>- <Controller- control={control}- name="primaryColor"- render={({ field, fieldState: { error } }) => (- <FormControl- isError={Boolean(error)}- errorText={error?.message}- label="Primary Color"- tooltipText="Background color for the page (hex format, e.g., #82cec0)"- >- <div className="flex items-center gap-2">- <Input- {...field}- placeholder="#82cec0"- isDisabled={!isAllowed}- className="flex-1"- />- {field.value && hexColorRegex.test(field.value) && (- <div- className="h-9 w-9 rounded border border-mineshaft-500"- style={{ backgroundColor: field.value }}+ </div>++ <form onSubmit={handleSubmit(handleFormSubmit)} autoComplete="off">+ <div className="grid grid-cols-1 gap-4 md:grid-cols-2">+ <Controller+ control={control}+ name="primaryColor"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ isError={Boolean(error)}+ errorText={error?.message}+ label="Primary Color"+ tooltipText="Background color for the page (hex format, e.g., #82cec0)"+ >+ <div className="flex items-center gap-2">+ <Input+ {...field}+ placeholder="#82cec0"+ isDisabled={!isAllowed}+ className="flex-1"/>- )}- </div>- </FormControl>- )}- />- <Controller- control={control}- name="secondaryColor"- render={({ field, fieldState: { error } }) => (- <FormControl- isError={Boolean(error)}- errorText={error?.message}- label="Secondary Color"- tooltipText="Panel and component colors (hex format, e.g., #14211e)"- >- <div className="flex items-center gap-2">- <Input- {...field}- placeholder="#14211e"- isDisabled={!isAllowed}- className="flex-1"- />- {field.value && hexColorRegex.test(field.value) && (- <div- className="h-9 w-9 rounded border border-mineshaft-500"- style={{ backgroundColor: field.value }}+ {field.value && hexColorRegex.test(field.value) && (+ <div+ className="size-9 shrink-0 rounded border border-mineshaft-500"+ style={{ backgroundColor: field.value }}+ />+ )}+ </div>+ </FormControl>+ )}+ />+ <Controller+ control={control}+ name="secondaryColor"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ isError={Boolean(error)}+ errorText={error?.message}+ label="Secondary Color"+ tooltipText="Panel and component background color (hex format, e.g., #14211e)"+ >+ <div className="flex items-center gap-2">+ <Input+ {...field}+ placeholder="#14211e"+ isDisabled={!isAllowed}+ className="flex-1"/>- )}- </div>- </FormControl>- )}- />- </div>- <Button- colorSchema="secondary"- type="submit"- isLoading={isPending}- isDisabled={!isDirty || !isAllowed}- className="mt-4"- >- Save- </Button>- </form>+ {field.value && hexColorRegex.test(field.value) && (+ <div+ className="size-9 shrink-0 rounded border border-mineshaft-500"+ style={{ backgroundColor: field.value }}+ />+ )}+ </div>+ </FormControl>+ )}+ />+ </div>+ <Button+ colorSchema="secondary"+ type="submit"+ isLoading={isUpdatingOrg}+ isDisabled={!isDirty || !isAllowed}+ className="mt-4"+ >+ Save Colors+ </Button>+ </form>+ </div>)}</OrgPermissionCan>)}diff --git a/frontend/src/pages/public/ViewSharedSecretByIDPage/ViewSharedSecretByIDPage.tsx b/frontend/src/pages/public/ViewSharedSecretByIDPage/ViewSharedSecretByIDPage.tsxindex cf2763de2e..179c6c8eb5 100644--- a/frontend/src/pages/public/ViewSharedSecretByIDPage/ViewSharedSecretByIDPage.tsx+++ b/frontend/src/pages/public/ViewSharedSecretByIDPage/ViewSharedSecretByIDPage.tsx@@ -143,10 +143,10 @@ export const ViewSharedSecretByIDPage = () => {const hasCustomBranding = !!brandingConfig;// Use proxy URLs for branding assets to avoid cross origin issues- const logoUrl = brandingConfig?.hasLogoUrl+ const logoUrl = brandingConfig?.hasLogo? `/api/v1/secret-sharing/shared/public/${id}/branding/logo`: DEFAULT_LOGO_URL;- const faviconUrl = brandingConfig?.hasFaviconUrl+ const faviconUrl = brandingConfig?.hasFavicon? `/api/v1/secret-sharing/shared/public/${id}/branding/favicon`: DEFAULT_FAVICON_URL;