Skip to content

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

fix: improve url validation ## Context

Maidul Islam45f7db858f1e
diff --git a/backend/src/ee/services/oidc/oidc-config-service.ts b/backend/src/ee/services/oidc/oidc-config-service.ts
index b3ac192177..f7b537d4c6 100644
--- a/backend/src/ee/services/oidc/oidc-config-service.ts
+++ b/backend/src/ee/services/oidc/oidc-config-service.ts
@@ -18,7 +18,7 @@ import { crypto } from "@app/lib/crypto";
import { BadRequestError, ForbiddenRequestError, NotFoundError, OidcAuthError } from "@app/lib/errors";
import { AuthAttemptAuthMethod, AuthAttemptAuthResult, authAttemptCounter } from "@app/lib/telemetry/metrics";
import { OrgServiceActor } from "@app/lib/types";
-import { matchesAllowedEmailDomain } from "@app/lib/validator";
+import { blockLocalAndPrivateIpAddresses, matchesAllowedEmailDomain } from "@app/lib/validator";
import { ActorType, AuthMethod, AuthTokenType } from "@app/services/auth/auth-type";
import { TAuthTokenServiceFactory } from "@app/services/auth-token/auth-token-service";
import { TokenType } from "@app/services/auth-token/auth-token-types";
@@ -575,6 +575,13 @@ export const oidcConfigServiceFactory = ({
}
}
+ if (discoveryURL) {
+ await blockLocalAndPrivateIpAddresses(discoveryURL);
+ }
+ if (jwksUri) {
+ await blockLocalAndPrivateIpAddresses(jwksUri);
+ }
+
const updateQuery: TOidcConfigsUpdate = {
allowedEmailDomains,
configurationType,
@@ -654,6 +661,13 @@ export const oidcConfigServiceFactory = ({
});
}
+ if (discoveryURL) {
+ await blockLocalAndPrivateIpAddresses(discoveryURL);
+ }
+ if (jwksUri) {
+ await blockLocalAndPrivateIpAddresses(jwksUri);
+ }
+
const { encryptor } = await kmsService.createCipherPairWithDataKey({
type: KmsDataKey.Organization,
orgId: org.id
@@ -710,6 +724,7 @@ export const oidcConfigServiceFactory = ({
message: "OIDC not configured correctly"
});
}
+ await blockLocalAndPrivateIpAddresses(oidcCfg.discoveryURL);
issuer = await Issuer.discover(oidcCfg.discoveryURL);
} else {
if (
@@ -723,6 +738,7 @@ export const oidcConfigServiceFactory = ({
message: "OIDC not configured correctly"
});
}
+ await blockLocalAndPrivateIpAddresses(oidcCfg.jwksUri);
issuer = new OpenIdIssuer({
issuer: oidcCfg.issuer,
authorization_endpoint: oidcCfg.authorizationEndpoint,
diff --git a/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts b/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts
index 9d1ca61a45..8e3361d775 100644
--- a/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts
+++ b/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts
@@ -30,6 +30,7 @@ import {
} from "@app/lib/errors";
import { extractIPDetails, isValidIpOrCidr } from "@app/lib/ip";
import { AuthAttemptAuthMethod, AuthAttemptAuthResult, authAttemptCounter } from "@app/lib/telemetry/metrics";
+import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
import { getValueByDot } from "@app/lib/template/dot-access";
import { ActorType, AuthTokenType } from "../auth/auth-type";
@@ -116,6 +117,8 @@ export const identityJwtAuthServiceFactory = ({
let tokenData: Record<string, string | boolean | number> = {};
if (identityJwtAuth.configurationType === JwtConfigurationType.JWKS) {
+ await blockLocalAndPrivateIpAddresses(identityJwtAuth.jwksUrl);
+
let client: JwksClient;
if (identityJwtAuth.jwksUrl.includes("https:")) {
const decryptedJwksCaCert = orgDataKeyDecryptor({
@@ -478,6 +481,10 @@ export const identityJwtAuthServiceFactory = ({
return extractIPDetails(accessTokenTrustedIp.ipAddress);
});
+ if (configurationType === JwtConfigurationType.JWKS && jwksUrl) {
+ await blockLocalAndPrivateIpAddresses(jwksUrl);
+ }
+
const { encryptor: orgDataKeyEncryptor } = await kmsService.createCipherPairWithDataKey({
type: KmsDataKey.Organization,
orgId: actorOrgId
@@ -606,6 +613,10 @@ export const identityJwtAuthServiceFactory = ({
return extractIPDetails(accessTokenTrustedIp.ipAddress);
});
+ if (jwksUrl) {
+ await blockLocalAndPrivateIpAddresses(jwksUrl);
+ }
+
const updateQuery: TIdentityJwtAuthsUpdate = {
boundIssuer,
configurationType,
diff --git a/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts b/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts
index a6f5daeaf0..266e561040 100644
--- a/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts
+++ b/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts
@@ -32,6 +32,7 @@ import {
import { extractIPDetails, isValidIpOrCidr } from "@app/lib/ip";
import { logger } from "@app/lib/logger";
import { AuthAttemptAuthMethod, AuthAttemptAuthResult, authAttemptCounter } from "@app/lib/telemetry/metrics";
+import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
import { getValueByDot } from "@app/lib/template/dot-access";
import { ActorType, AuthTokenType } from "../auth/auth-type";
@@ -110,6 +111,8 @@ export const identityOidcAuthServiceFactory = ({
let discoveryDoc: { jwks_uri: string };
try {
+ await blockLocalAndPrivateIpAddresses(identityOidcAuth.oidcDiscoveryUrl);
+
const response = await axios.get<{ jwks_uri: string }>(
`${identityOidcAuth.oidcDiscoveryUrl}/.well-known/openid-configuration`,
{
@@ -142,6 +145,8 @@ export const identityOidcAuthServiceFactory = ({
});
}
+ await blockLocalAndPrivateIpAddresses(jwksUri);
+
const decodedToken = crypto.jwt().decode(oidcJwt, { complete: true });
if (!decodedToken) {
throw new UnauthorizedError({
@@ -592,6 +597,8 @@ export const identityOidcAuthServiceFactory = ({
return extractIPDetails(accessTokenTrustedIp.ipAddress);
});
+ await blockLocalAndPrivateIpAddresses(oidcDiscoveryUrl);
+
const { encryptor } = await kmsService.createCipherPairWithDataKey({
type: KmsDataKey.Organization,
orgId: identityMembershipOrg.scopeOrgId
@@ -710,6 +717,10 @@ export const identityOidcAuthServiceFactory = ({
return extractIPDetails(accessTokenTrustedIp.ipAddress);
});
+ if (oidcDiscoveryUrl) {
+ await blockLocalAndPrivateIpAddresses(oidcDiscoveryUrl);
+ }
+
const updateQuery: TIdentityOidcAuthsUpdate = {
oidcDiscoveryUrl,
boundIssuer,