Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat: updated some conditions

=54dd48eaded7
diff --git a/backend/src/ee/services/dynamic-secret/dynamic-secret-fns.ts b/backend/src/ee/services/dynamic-secret/dynamic-secret-fns.ts
index af1f422de2..8a440c1aeb 100644
--- a/backend/src/ee/services/dynamic-secret/dynamic-secret-fns.ts
+++ b/backend/src/ee/services/dynamic-secret/dynamic-secret-fns.ts
@@ -24,6 +24,7 @@ export const verifyHostInputValidity = async ({
const reservedHosts = [appCfg.DB_HOST || getDbConnectionHost(appCfg.DB_CONNECTION_URI)].concat(
(appCfg.DB_READ_REPLICAS || []).map((el) => getDbConnectionHost(el.DB_CONNECTION_URI)),
getDbConnectionHost(appCfg.REDIS_URL),
+ getDbConnectionHost(appCfg.CLICKHOUSE_URL),
getDbConnectionHost(appCfg.AUDIT_LOGS_DB_CONNECTION_URI)
);
@@ -31,26 +32,18 @@ export const verifyHostInputValidity = async ({
const exclusiveIps: string[] = [];
for await (const el of reservedHosts) {
if (el) {
- if (net.isIPv4(el)) {
+ if (net.isIP(el)) {
exclusiveIps.push(el);
} else {
- try {
- const resolvedIps = await dns.resolve4(el);
- exclusiveIps.push(...resolvedIps);
- } catch (error) {
- // only try lookup if not found
- if ((error as { code: string })?.code !== "ENOTFOUND") throw error;
-
- const resolvedIps = (await dns.lookup(el, { all: true, family: 4 })).map(({ address }) => address);
- exclusiveIps.push(...resolvedIps);
- }
+ const resolvedIps = (await dns.lookup(el, { all: true })).map(({ address }) => address);
+ exclusiveIps.push(...resolvedIps);
}
}
}
const normalizedHost = host.split(":")[0].toLowerCase();
const inputHostIps: string[] = [];
- if (net.isIPv4(host)) {
+ if (net.isIP(host)) {
inputHostIps.push(host);
} else {
if (!appCfg.DYNAMIC_SECRET_ALLOW_INTERNAL_IP && !appCfg.ALLOW_INTERNAL_IP_CONNECTIONS) {
@@ -60,16 +53,8 @@ export const verifyHostInputValidity = async ({
});
}
}
- try {
- const resolvedIps = await dns.resolve4(host);
- inputHostIps.push(...resolvedIps);
- } catch (error) {
- // only try lookup if not found
- if ((error as { code: string })?.code !== "ENOTFOUND") throw error;
-
- const resolvedIps = (await dns.lookup(host, { all: true, family: 4 })).map(({ address }) => address);
- inputHostIps.push(...resolvedIps);
- }
+ const resolvedIps = (await dns.lookup(host, { all: true })).map(({ address }) => address);
+ inputHostIps.push(...resolvedIps);
}
if (!(appCfg.DYNAMIC_SECRET_ALLOW_INTERNAL_IP || appCfg.ALLOW_INTERNAL_IP_CONNECTIONS)) {
diff --git a/backend/src/lib/validator/validate-url.ts b/backend/src/lib/validator/validate-url.ts
index b96d1bfe4d..d7127de1d7 100644
--- a/backend/src/lib/validator/validate-url.ts
+++ b/backend/src/lib/validator/validate-url.ts
@@ -1,6 +1,6 @@
import dns from "node:dns/promises";
-import { isIPv4 } from "net";
+import { isIP } from "net";
import RE2 from "re2";
import { verifyHostInputValidity } from "@app/ee/services/dynamic-secret/dynamic-secret-fns";
@@ -22,28 +22,19 @@ export const blockLocalAndPrivateIpAddresses = async (url: string, isGateway = f
}
const inputHostIps: string[] = [];
- if (isIPv4(validUrl.hostname)) {
+ if (isIP(validUrl.hostname)) {
inputHostIps.push(validUrl.hostname);
} else {
if (validUrl.hostname === "localhost" || validUrl.hostname === "host.docker.internal") {
throw new BadRequestError({ message: "Local IPs not allowed as URL" });
}
- try {
- const resolvedIps = await dns.resolve4(validUrl.hostname);
- inputHostIps.push(...resolvedIps);
- } catch (err) {
- if ((err as { code: string })?.code !== "ENOTFOUND") throw err;
+ const entries = await dns.lookup(validUrl.hostname, { all: true });
- const entries = await dns.lookup(validUrl.hostname, { all: true, family: 4 });
-
- if (!entries || entries.length === 0) {
- throw new BadRequestError({ message: "Could not resolve hostname to any IPv4 address" });
- }
-
- const resolvedIps = entries.map(({ address }) => address);
-
- inputHostIps.push(...resolvedIps);
+ if (!entries || entries.length === 0) {
+ throw new BadRequestError({ message: "Could not resolve hostname to any IP address" });
}
+
+ inputHostIps.push(...entries.map(({ address }) => address));
}
const isInternalIp = inputHostIps.some((el) => isPrivateIp(el));
if (isInternalIp && !appCfg.ALLOW_INTERNAL_IP_CONNECTIONS)
diff --git a/backend/src/services/org/org-dal.ts b/backend/src/services/org/org-dal.ts
index 676d0a32c0..66ee9b2d67 100644
--- a/backend/src/services/org/org-dal.ts
+++ b/backend/src/services/org/org-dal.ts
@@ -816,7 +816,13 @@ export const orgDALFactory = (db: TDbClient) => {
tx?: Knex;
}): Promise<TMemberships | null> => {
const list = await findEffectiveOrgMemberships(dto);
- return list[0] ?? null;
+ const directMembership = list.find((membership) =>
+ dto.actorType === ActorType.USER
+ ? membership.actorUserId === dto.actorId
+ : membership.actorIdentityId === dto.actorId
+ );
+
+ return directMembership ?? list[0] ?? null;
};
const findMembershipWithScimFilter = async (
diff --git a/backend/src/services/secret-sharing/secret-sharing-service.ts b/backend/src/services/secret-sharing/secret-sharing-service.ts
index 38ac0b89bf..dc3374c81f 100644
--- a/backend/src/services/secret-sharing/secret-sharing-service.ts
+++ b/backend/src/services/secret-sharing/secret-sharing-service.ts
@@ -100,6 +100,10 @@ export const secretSharingServiceFactory = ({
}
};
+ // Checks whether external (non-org) email access is available for this secret.
+ const $hasExternalEmailAccess = (sharedSecret: TSecretSharing): boolean =>
+ Boolean(sharedSecret.allowExternalEmails && sharedSecret.password);
+
const createSharedSecret = async ({
actor,
actorId,
@@ -611,8 +615,9 @@ export const secretSharingServiceFactory = ({
}
const isAuthorizedUser = await $isAuthorizedEmailUser(sharedSecret, actorId);
+ const hasExternalEmailAccess = $hasExternalEmailAccess(sharedSecret);
- if (!isAuthorizedUser && !sharedSecret.allowExternalEmails) {
+ if (!isAuthorizedUser && !hasExternalEmailAccess) {
if (!actorId) {
throw new UnauthorizedError({ message: "Authentication required to view this secret" });
}
@@ -666,8 +671,9 @@ export const secretSharingServiceFactory = ({
}
const isAuthorizedUser = await $isAuthorizedEmailUser(sharedSecret, actorId);
+ const hasExternalEmailAccess = $hasExternalEmailAccess(sharedSecret);
- if (!isAuthorizedUser && !sharedSecret.allowExternalEmails) {
+ if (!isAuthorizedUser && !hasExternalEmailAccess) {
if (!actorId) {
throw new UnauthorizedError({ message: "Authentication required to view this secret" });
}