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
refactor and change interface to have tooltip
adilson39ea2a16f3da
diff --git a/backend/src/server/routes/v1/secret-sharing-router.ts b/backend/src/server/routes/v1/secret-sharing-router.tsindex 6358528180..45c8850e99 100644--- a/backend/src/server/routes/v1/secret-sharing-router.ts+++ b/backend/src/server/routes/v1/secret-sharing-router.ts@@ -97,9 +97,16 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>}),response: {200: SanitizedSecretSharingSchema.extend({- isPasswordProtected: z.boolean().describe("Whether the shared secret is protected by a password.")+ isPasswordProtected: z.boolean().describe("Whether the shared secret is protected by a password."),+ isAuthorizedUser: z+ .boolean()+ .describe(+ "Whether the current user is an authorized org member. If false, the user must provide a password."+ )}).omit({- authorizedEmails: true+ authorizedEmails: true,+ externalEmails: true,+ allowExternalEmails: true})}},diff --git a/backend/src/services/secret-sharing/secret-sharing-service.ts b/backend/src/services/secret-sharing/secret-sharing-service.tsindex e1846eb68f..9425c5216d 100644--- a/backend/src/services/secret-sharing/secret-sharing-service.ts+++ b/backend/src/services/secret-sharing/secret-sharing-service.ts@@ -560,36 +560,23 @@ export const secretSharingServiceFactory = ({};};- // Validates that an authenticated org member is authorized to view a secret shared to specific emails.- const $validateAuthorizedEmailAccess = async (sharedSecret: TSecretSharing, actorId?: string) => {+ // Checks if the authenticated user is in the authorizedEmails list (org members).+ // Returns true if no email restriction exists or user is authorized; false otherwise.+ const $isAuthorizedEmailUser = async (sharedSecret: TSecretSharing, actorId?: string): Promise<boolean> => {const hasAuthorizedEmails = sharedSecret.authorizedEmails && (sharedSecret.authorizedEmails as string[]).length > 0;- if (!hasAuthorizedEmails) return;-- if (!actorId) {- throw new UnauthorizedError({ message: "Authentication required to view this secret" });- }+ if (!hasAuthorizedEmails || !actorId) return false;const user = await userDAL.findById(actorId);- if (!user || !user.email) {- throw new UnauthorizedError({ message: "Authentication required to view this secret" });- }+ if (!user || !user.email) return false;- if (!(sharedSecret.authorizedEmails as string[]).includes(user.email)) {- throw new ForbiddenRequestError({ message: "You are not authorized to view this secret" });- }+ return (sharedSecret.authorizedEmails as string[]).includes(user.email);};- // Validates that a secret is properly configured for external (non-org) email access.- // External users authenticate via password — actual password verification is handled by the caller.- const $validateExternalEmailAccess = (sharedSecret: TSecretSharing) => {+ // Checks whether external (non-org) email access is available for this secret.+ const $hasExternalEmailAccess = (sharedSecret: TSecretSharing): boolean => {const hasExternalEmails = sharedSecret.externalEmails && (sharedSecret.externalEmails as string[]).length > 0;-- if (!hasExternalEmails || !sharedSecret.allowExternalEmails) return;-- if (!sharedSecret.password) {- throw new BadRequestError({ message: "A password is required for secrets shared with external emails" });- }+ return Boolean(hasExternalEmails && sharedSecret.allowExternalEmails);};const getSharedSecretById = async (sharedSecretId: string, orgId?: string, actorId?: string) => {@@ -626,12 +613,19 @@ export const secretSharingServiceFactory = ({throw new NotFoundError({ message: "The shared secret has reached its view limit" });}- await $validateAuthorizedEmailAccess(sharedSecret, actorId);- $validateExternalEmailAccess(sharedSecret);+ const isAuthorizedUser = await $isAuthorizedEmailUser(sharedSecret, actorId);++ if (!isAuthorizedUser && !$hasExternalEmailAccess(sharedSecret)) {+ if (!actorId) {+ throw new UnauthorizedError({ message: "Authentication required to view this secret" });+ }+ throw new ForbiddenRequestError({ message: "You are not authorized to view this secret" });+ }return {...mapIdentifierToId(sharedSecret),- isPasswordProtected: Boolean(sharedSecret.password)+ isPasswordProtected: Boolean(sharedSecret.password),+ isAuthorizedUser};};@@ -674,8 +668,14 @@ export const secretSharingServiceFactory = ({throw new ForbiddenRequestError();}- await $validateAuthorizedEmailAccess(sharedSecret, actorId);- $validateExternalEmailAccess(sharedSecret);+ const isAuthorizedUser = await $isAuthorizedEmailUser(sharedSecret, actorId);++ if (!isAuthorizedUser && !$hasExternalEmailAccess(sharedSecret)) {+ if (!actorId) {+ throw new UnauthorizedError();+ }+ throw new ForbiddenRequestError();+ }// all secrets pass through here, meaning we check if its expired first and then check if it needs verification// or can be safely sent to the client.diff --git a/frontend/src/hooks/api/secretSharing/types.ts b/frontend/src/hooks/api/secretSharing/types.tsindex cabd426f2d..d0cfb2302a 100644--- a/frontend/src/hooks/api/secretSharing/types.ts+++ b/frontend/src/hooks/api/secretSharing/types.ts@@ -74,6 +74,7 @@ export type TSanitizedSharedSecret = {export type TSharedSecretPublicDetails = TSanitizedSharedSecret & {isPasswordProtected: boolean;+ isAuthorizedUser: boolean;};export type TAccessSharedSecretResponse = {diff --git a/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx b/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsxindex 94b14f8791..1510cfa091 100644--- a/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx+++ b/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx@@ -1,6 +1,6 @@import { useState } from "react";import { Controller, useForm } from "react-hook-form";-import { faCheck, faCopy, faRedo } from "@fortawesome/free-solid-svg-icons";+import { faCheck, faCopy, faInfoCircle, faRedo } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { zodResolver } from "@hookform/resolvers/zod";import { useSearch } from "@tanstack/react-router";@@ -18,7 +18,8 @@ import {Input,Select,SelectItem,- Switch+ Switch,+ Tooltip} from "@app/components/v2";import { useTimedReset } from "@app/hooks";import { useCreatePublicSharedSecret, useCreateSharedSecret } from "@app/hooks/api";@@ -402,11 +403,11 @@ export const ShareSecretForm = ({name="emails"render={({ field, fieldState: { error } }) => (<FormControl- label="Authorized Emails"+ label="Emails"isOptionalhelperText={isAllowingExternalEmails- ? "External recipients will receive a link and need the password to access the secret."+ ? "All recipients will receive a link and need the password to access the secret. They don't need an Infisical account.": "Recipients must have an Infisical account to verify identity"}tooltipText={@@ -441,17 +442,7 @@ export const ShareSecretForm = ({field: { onChange, value: isChecked, ...field },fieldState: { error }}) => (- <FormControl- errorText={error?.message}- isError={Boolean(error)}- tooltipText={- <p>- When enabled, emails not registered in Infisical will receive the secret- link via email but will need the password to access the secret.- </p>- }- tooltipClassName="max-w-sm"- >+ <FormControl errorText={error?.message} isError={Boolean(error)}><SwitchclassName={`mr-2 ml-0 bg-mineshaft-400/50 shadow-inner data-[state=checked]:bg-primary ${isOrgAccess ? "opacity-50" : ""}`}thumbClassName="bg-mineshaft-800"@@ -462,7 +453,16 @@ export const ShareSecretForm = ({id="allow-external-emails"{...field}>- Allow external recipients+ <span className="flex items-center">+ Allow external recipients+ <Tooltip content="When enabled, the defined emails will receive the secret link via email but will need the password to access the secret.">+ <FontAwesomeIcon+ icon={faInfoCircle}+ size="xs"+ className="ml-1 text-mineshaft-400"+ />+ </Tooltip>+ </span></Switch></FormControl>)}diff --git a/frontend/src/pages/public/ViewSharedSecretByIDPage/ViewSharedSecretByIDPage.tsx b/frontend/src/pages/public/ViewSharedSecretByIDPage/ViewSharedSecretByIDPage.tsxindex 1fb0d7200a..a3546017a9 100644--- a/frontend/src/pages/public/ViewSharedSecretByIDPage/ViewSharedSecretByIDPage.tsx+++ b/frontend/src/pages/public/ViewSharedSecretByIDPage/ViewSharedSecretByIDPage.tsx@@ -80,9 +80,14 @@ export const ViewSharedSecretByIDPage = () => {sharedSecretId: id});- // Auto-access when the secret is not password protected+ // Auto-access when the user is authorized and no password is neededuseEffect(() => {- if (secretDetails && !secretDetails.isPasswordProtected && !hasTriggeredAccess.current) {+ if (+ secretDetails &&+ secretDetails.isAuthorizedUser &&+ !secretDetails.isPasswordProtected &&+ !hasTriggeredAccess.current+ ) {hasTriggeredAccess.current = true;accessMutation.mutate({ sharedSecretId: id });}@@ -125,10 +130,11 @@ export const ViewSharedSecretByIDPage = () => {const secret = accessMutation.data;const isPasswordProtected = secretDetails?.isPasswordProtected ?? false;+ const needsPassword = isPasswordProtected;// only show password prompt if no critical error (403/404) occurred after submissionconst hasCriticalError = accessMutation.isError && (isForbidden || isNotFound);- const showPasswordPrompt = isPasswordProtected && !secret && !hasCriticalError;- const isLoading = isLoadingDetails || (!isPasswordProtected && accessMutation.isPending);+ const showPasswordPrompt = needsPassword && !secret && !hasCriticalError;+ const isLoading = isLoadingDetails || (!needsPassword && accessMutation.isPending);const hasCustomBranding = !!brandingConfig;