Skip to content

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

fix(gateway): handle malformed URL's

Daniel Hougaard022ecf75e1ff
diff --git a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts
index df72b428ec..b15a2ed4f0 100644
--- a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts
+++ b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts
@@ -274,9 +274,27 @@ export const identityKubernetesAuthServiceFactory = ({
if (identityKubernetesAuth.tokenReviewMode === IdentityKubernetesAuthTokenReviewMode.Gateway) {
const { kubernetesHost } = identityKubernetesAuth;
- const lastColonIndex = kubernetesHost.lastIndexOf(":");
- const k8sHost = kubernetesHost.substring(0, lastColonIndex);
- const k8sPort = kubernetesHost.substring(lastColonIndex + 1);
+
+ let urlString = kubernetesHost;
+ if (!kubernetesHost.startsWith("http://") && !kubernetesHost.startsWith("https://")) {
+ urlString = `https://${kubernetesHost}`;
+ }
+
+ const url = new URL(urlString);
+ let { port: k8sPort } = url;
+ const { protocol, hostname: k8sHost } = url;
+
+ const cleanedProtocol = new RE2(/[^a-zA-Z0-9]/g).replace(protocol, "").toLowerCase();
+
+ if (!["https", "http"].includes(cleanedProtocol)) {
+ throw new BadRequestError({
+ message: "Invalid Kubernetes host URL, must start with http:// or https://"
+ });
+ }
+
+ if (!k8sPort) {
+ k8sPort = cleanedProtocol === "https" ? "443" : "80";
+ }
if (!identityKubernetesAuth.gatewayId) {
throw new BadRequestError({
@@ -287,7 +305,7 @@ export const identityKubernetesAuthServiceFactory = ({
data = await $gatewayProxyWrapper(
{
gatewayId: identityKubernetesAuth.gatewayId,
- targetHost: k8sHost, // note(daniel): must include the protocol (https|http)
+ targetHost: `${cleanedProtocol}://${k8sHost}`, // note(daniel): must include the protocol (https|http)
targetPort: k8sPort ? Number(k8sPort) : 443,
caCert,
reviewTokenThroughGateway: true
diff --git a/cli/packages/gateway/connection.go b/cli/packages/gateway/connection.go
index 9274086a1a..46d194c962 100644
--- a/cli/packages/gateway/connection.go
+++ b/cli/packages/gateway/connection.go
@@ -12,6 +12,7 @@ import (
"io"
"net"
"net/http"
+ "net/url"
"os"
"strings"
"sync"
@@ -106,6 +107,11 @@ func handleStream(stream quic.Stream, quicConn quic.Connection) {
targetURL := string(argParts[0])
+ if !isValidURL(targetURL) {
+ log.Error().Msgf("Invalid target URL: %s", targetURL)
+ return
+ }
+
// Parse optional parameters
var caCertB64, verifyParam string
for _, part := range argParts[1:] {
@@ -255,6 +261,11 @@ type CloseWrite interface {
CloseWrite() error
}
+func isValidURL(str string) bool {
+ u, err := url.Parse(str)
+ return err == nil && u.Scheme != "" && u.Host != ""
+}
+
func CopyDataFromQuicToTcp(quicStream quic.Stream, tcpConn net.Conn) {
// Create a WaitGroup to wait for both copy operations
var wg sync.WaitGroup
diff --git a/helm-charts/infisical-gateway/CHANGELOG.md b/helm-charts/infisical-gateway/CHANGELOG.md
index 57bb3b0313..06ff25bf7a 100644
--- a/helm-charts/infisical-gateway/CHANGELOG.md
+++ b/helm-charts/infisical-gateway/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.0.3 (June 6, 2025)
+
+* Minor fix for handling malformed URL's for HTTP forwarding
+
## 0.0.2 (June 6, 2025)
* Bumped default CLI image version from 0.41.1 -> 0.41.8.
diff --git a/helm-charts/infisical-gateway/Chart.yaml b/helm-charts/infisical-gateway/Chart.yaml
index a53258f68b..8d9d4dac3c 100644
--- a/helm-charts/infisical-gateway/Chart.yaml
+++ b/helm-charts/infisical-gateway/Chart.yaml
@@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
-version: 0.0.2
+version: 0.0.3
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
-appVersion: "0.0.2"
+appVersion: "0.0.3"
diff --git a/helm-charts/infisical-gateway/values.yaml b/helm-charts/infisical-gateway/values.yaml
index fef55daa75..9e897f4613 100644
--- a/helm-charts/infisical-gateway/values.yaml
+++ b/helm-charts/infisical-gateway/values.yaml
@@ -1,6 +1,6 @@
image:
pullPolicy: IfNotPresent
- tag: "0.41.8"
+ tag: "0.41.81"
secret:
# The secret that contains the environment variables to be used by the gateway, such as INFISICAL_API_URL and TOKEN