mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
fix(gateway): handle malformed URL's
This commit is contained in:
@@ -274,9 +274,27 @@ export const identityKubernetesAuthServiceFactory = ({
|
|||||||
|
|
||||||
if (identityKubernetesAuth.tokenReviewMode === IdentityKubernetesAuthTokenReviewMode.Gateway) {
|
if (identityKubernetesAuth.tokenReviewMode === IdentityKubernetesAuthTokenReviewMode.Gateway) {
|
||||||
const { kubernetesHost } = identityKubernetesAuth;
|
const { kubernetesHost } = identityKubernetesAuth;
|
||||||
const lastColonIndex = kubernetesHost.lastIndexOf(":");
|
|
||||||
const k8sHost = kubernetesHost.substring(0, lastColonIndex);
|
let urlString = kubernetesHost;
|
||||||
const k8sPort = kubernetesHost.substring(lastColonIndex + 1);
|
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) {
|
if (!identityKubernetesAuth.gatewayId) {
|
||||||
throw new BadRequestError({
|
throw new BadRequestError({
|
||||||
@@ -287,7 +305,7 @@ export const identityKubernetesAuthServiceFactory = ({
|
|||||||
data = await $gatewayProxyWrapper(
|
data = await $gatewayProxyWrapper(
|
||||||
{
|
{
|
||||||
gatewayId: identityKubernetesAuth.gatewayId,
|
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,
|
targetPort: k8sPort ? Number(k8sPort) : 443,
|
||||||
caCert,
|
caCert,
|
||||||
reviewTokenThroughGateway: true
|
reviewTokenThroughGateway: true
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -106,6 +107,11 @@ func handleStream(stream quic.Stream, quicConn quic.Connection) {
|
|||||||
|
|
||||||
targetURL := string(argParts[0])
|
targetURL := string(argParts[0])
|
||||||
|
|
||||||
|
if !isValidURL(targetURL) {
|
||||||
|
log.Error().Msgf("Invalid target URL: %s", targetURL)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Parse optional parameters
|
// Parse optional parameters
|
||||||
var caCertB64, verifyParam string
|
var caCertB64, verifyParam string
|
||||||
for _, part := range argParts[1:] {
|
for _, part := range argParts[1:] {
|
||||||
@@ -255,6 +261,11 @@ type CloseWrite interface {
|
|||||||
CloseWrite() error
|
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) {
|
func CopyDataFromQuicToTcp(quicStream quic.Stream, tcpConn net.Conn) {
|
||||||
// Create a WaitGroup to wait for both copy operations
|
// Create a WaitGroup to wait for both copy operations
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|||||||
@@ -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)
|
## 0.0.2 (June 6, 2025)
|
||||||
|
|
||||||
* Bumped default CLI image version from 0.41.1 -> 0.41.8.
|
* Bumped default CLI image version from 0.41.1 -> 0.41.8.
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ type: application
|
|||||||
# This is the chart version. This version number should be incremented each time you make changes
|
# 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.
|
# to the chart and its templates, including the app version.
|
||||||
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
# 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
|
# 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
|
# 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.
|
# follow Semantic Versioning. They should reflect the version the application is using.
|
||||||
# It is recommended to use it with quotes.
|
# It is recommended to use it with quotes.
|
||||||
appVersion: "0.0.2"
|
appVersion: "0.0.3"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
image:
|
image:
|
||||||
pullPolicy: IfNotPresent
|
pullPolicy: IfNotPresent
|
||||||
tag: "0.41.8"
|
tag: "0.41.81"
|
||||||
|
|
||||||
secret:
|
secret:
|
||||||
# The secret that contains the environment variables to be used by the gateway, such as INFISICAL_API_URL and TOKEN
|
# The secret that contains the environment variables to be used by the gateway, such as INFISICAL_API_URL and TOKEN
|
||||||
|
|||||||
Reference in New Issue
Block a user