Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ define EXPOSE_ENV
fi
endef

.PHONY: all help dev dev-pulse build-ui build build-cli run run-cli install-air install-pulse clean test test-cli install-ui setup-workspace work-init work-clean docs docker-image docker-run cleanup-enterprise mod-tidy test-integrations-py test-integrations-ts install-playwright run-e2e run-e2e-ui run-e2e-headed run-e2e-api format ui install-newman run-provider-harness-test run-cli-harness-test test-semantic-cache test-semantic-cache-complete _test-semantic-cache-complete-inner helm-index
.PHONY: all help dev dev-pulse build-ui build build-cli run run-cli install-air install-pulse clean test test-cli install-ui setup-workspace work-init work-clean docs docker-image docker-run cleanup-enterprise mod-tidy test-integrations-py test-integrations-ts install-playwright run-e2e run-e2e-ui run-e2e-headed run-e2e-api format ui install-newman run-provider-harness-test run-cli-harness-test test-semantic-cache test-semantic-cache-complete _test-semantic-cache-complete-inner helm-index install-microsocks socks5-proxy install-tinyproxy http-proxy

all: help

Expand Down Expand Up @@ -152,6 +152,31 @@ install-junit-viewer: ## Install junit-viewer for HTML report generation (if not
$(ECHO) "$(YELLOW)CI environment detected, skipping junit-viewer installation$(NC)"; \
fi

install-microsocks: ## Install microsocks SOCKS5 proxy for local testing (if not already installed)
@which microsocks > /dev/null || (command -v brew > /dev/null && $(ECHO) "$(YELLOW)Installing microsocks via Homebrew...$(NC)" && brew install microsocks) || ($(ECHO) "$(RED)Error: microsocks not found and Homebrew is unavailable. Install manually: https://github.com/rofl0r/microsocks$(NC)" && exit 1)
@$(ECHO) "$(GREEN)microsocks is ready$(NC)"

socks5-proxy: install-microsocks ## Run a local SOCKS5 proxy for testing provider proxy_config (Usage: make socks5-proxy [PORT=1080] [HOST=127.0.0.1])
@PROXY_PORT=$${PORT:-1080}; \
PROXY_HOST=$${HOST:-127.0.0.1}; \
$(ECHO) "$(GREEN)Starting SOCKS5 proxy on $$PROXY_HOST:$$PROXY_PORT (no auth, logs each connection, Ctrl+C to stop)...$(NC)"; \
$(ECHO) "$(YELLOW)Point a provider's proxy_config at socks5://$$PROXY_HOST:$$PROXY_PORT to test$(NC)"; \
Comment on lines +162 to +163

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- repository status ---'
git status --short --branch

printf '%s\n' '--- concise recent commits ---'
git log --oneline -12

printf '%s\n' '--- stack indicators ---'
rg -n -i 'stack|stacked|depends.?on|parent|base branch|change.?id' \
  .github README.md CONTRIBUTING.md Makefile 2>/dev/null || true

printf '%s\n' '--- Makefile relevant sections ---'
cat -n Makefile | sed -n '135,190p'

printf '%s\n' '--- proxy URL references ---'
rg -n -C 3 'socks5://|http://.*PROXY|PROXY_HOST|PROXY_PORT' Makefile .

Repository: maximhq/bifrost

Length of output: 13974


🏁 Script executed:

#!/bin/bash
set -eu
cat -n Makefile | sed -n '135,190p'
printf '%s\n' '--- proxy URL references ---'
rg -n -C 3 'socks5://|http://.*PROXY|PROXY_HOST|PROXY_PORT' Makefile .
printf '%s\n' '--- concise history and status ---'
git status --short --branch
git log --oneline -12

Repository: maximhq/bifrost

Length of output: 11355


🏁 Script executed:

#!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
p = Path("Makefile")
lines = p.read_text().splitlines()
for start, end in ((145, 180),):
    for i in range(start, min(end, len(lines)) + 1):
        print(f"{i}: {lines[i-1]}")
PY

Repository: maximhq/bifrost

Length of output: 2861


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- HOST export declarations ---'
rg -n '(^|[[:space:]])export[[:space:]]+.*HOST|^HOST[[:space:]]*[:?+]?=' Makefile . \
  -g 'Makefile' -g '*.mk' 2>/dev/null || true

printf '%s\n' '--- standalone GNU make command-line propagation probe ---'
if command -v make >/dev/null 2>&1; then
  env -i PATH="$PATH" make -f - HOST='::1' <<'MAKE'
print:
	`@printf` 'shell HOST=<%s>\n' "$$HOST"
MAKE
else
  printf '%s\n' 'make unavailable'
fi

printf '%s\n' '--- standalone URI authority probe ---'
python3 - <<'PY'
from urllib.parse import urlsplit

for scheme, host, port in (
    ("socks5", "127.0.0.1", "1080"),
    ("http", "proxy.example", "8888"),
    ("socks5", "::1", "1080"),
    ("http", "2001:db8::1", "8888"),
):
    raw = f"{scheme}://{host}:{port}"
    bracketed = f"{scheme}://[{host}]:{port}" if ":" in host else raw
    for label, value in (("raw", raw), ("bracketed", bracketed)):
        try:
            parsed = urlsplit(value)
            print(label, value, "->", parsed.hostname, parsed.port)
        except ValueError as exc:
            print(label, value, "-> ValueError:", exc)
PY

Repository: maximhq/bifrost

Length of output: 857


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- Makefile header and variable definitions ---'
cat -n Makefile | sed -n '1,35p'
rg -n -C 2 '(^|[[:space:]])HOST([[:space:]]|$)|PROXY_HOST|socks5-proxy|http-proxy' Makefile

printf '%s\n' '--- current commit summary ---'
git show --stat --oneline --no-renames HEAD

printf '%s\n' '--- current commit Makefile patch ---'
git show --format= --no-ext-diff --unified=12 HEAD -- Makefile

Repository: maximhq/bifrost

Length of output: 11982


🌐 Web query:

GNU make manual command line variables exported to environment of recipe

💡 Result:

In GNU Make, variables defined on the command line are automatically exported to the environment of recipes executed by Make [1][2]. When Make runs a recipe, it places variables into the environment of the shell used to execute that recipe [1][2]. Variables that originate from the command line, as well as those that were present in the environment when Make was invoked, are automatically included in this environment [1][2]. For other variables defined within the Makefile, they are only exported to the environment of recipes if they are explicitly marked with the export directive [1][2]. It is important to note that this behavior applies specifically to recipe commands [3]. Historically, the $(shell...) function did not receive these exported variables; however, as of GNU Make 4.4, all exported variables are now properly exported to the environment of the $(shell...) function as well [4].

Citations:


🏁 Script executed:

#!/bin/bash
set -eu
cat -n Makefile | sed -n '1,35p'
git show --stat --oneline --no-renames HEAD
git show --format= --no-ext-diff --unified=12 HEAD -- Makefile

Repository: maximhq/bifrost

Length of output: 9483


Bracket IPv6 literals in the proxy messages.

When invoked with HOST=::1, the messages emit invalid URLs such as socks5://::1:1080. Use a display-only host that wraps IPv6 literals in [...] without changing PROXY_HOST passed to the proxy processes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Makefile` around lines 162 - 163, Update the proxy startup messages around
the SOCKS5 host/port output to use a display-only host value that wraps IPv6
literals in brackets, producing valid URLs such as socks5://[::1]:1080. Keep
PROXY_HOST unchanged for the proxy processes and preserve unbracketed output for
non-IPv6 hosts.

Source: MCP tools

microsocks -i $$PROXY_HOST -p $$PROXY_PORT
Comment on lines +159 to +164

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

block="$(sed -n '/^socks5-proxy:/,/^$/p' Makefile)"
if ! grep -Eq 'case .*PROXY_HOST|microsocks .*(-u|-P|-w)' <<<"$block"; then
  echo "No non-loopback protection found for socks5-proxy" >&2
  exit 1
fi

Repository: maximhq/bifrost

Length of output: 203


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- repository state ---'
git status --short
git branch --show-current
git diff --stat

printf '%s\n' '--- Makefile target context ---'
cat -n Makefile | sed -n '125,180p'

printf '%s\n' '--- related proxy targets and configuration ---'
rg -n -C 3 'socks5-proxy|microsocks|proxy_config|Allow|allowlist|SOCKS5' . \
  -g '!node_modules' -g '!dist' -g '!build'

printf '%s\n' '--- stack metadata ---'
find .. -maxdepth 2 -type f \( -iname '*stack*' -o -iname '*pull*request*' \) -print

Repository: maximhq/bifrost

Length of output: 50374


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

log=/tmp/coderabbit-shell-logs/shell-output-xxXwlU

printf '%s\n' '--- state and target output ---'
sed -n '1,140p' "$log"

printf '%s\n' '--- exact target matches ---'
rg -n -C 8 '^socks5-proxy:|microsocks|proxy_config' Makefile README.md docs .github 2>/dev/null || true

printf '%s\n' '--- Makefile size and nearby targets ---'
wc -l Makefile
cat -n Makefile | sed -n '140,175p'

printf '%s\n' '--- changed files and stack indicators ---'
git diff --name-status
git status --short
find .. -maxdepth 2 -type f \( -iname '*stack*' -o -iname '*pull*request*' \) -print

Repository: maximhq/bifrost

Length of output: 50373


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- dry-run command expansion ---'
make -n socks5-proxy HOST=0.0.0.0 PORT=1080 | tail -n 8
make -n socks5-proxy HOST=192.0.2.10 PORT=1234 | tail -n 8

printf '%s\n' '--- microsocks option documentation ---'
curl -fsSL https://raw.githubusercontent.com/rofl0r/microsocks/master/README.md \
  | sed -n '/^Usage/,/^$/p;/^-i /p;/^-p /p;/^-u /p;/^-P /p;/^-w /p'

printf '%s\n' '--- microsocks bind and authentication implementation ---'
curl -fsSL https://raw.githubusercontent.com/rofl0r/microsocks/master/microsocks.c \
  | rg -n -C 3 'listen_ip|bind|username|password|SOCKS5_USER|SOCKS5_PASS|-i|-u|-P|-w'

Repository: maximhq/bifrost

Length of output: 229


🏁 Script executed:

#!/usr/bin/env bash
set -u

printf '%s\n' '--- microsocks option documentation ---'
if curl -fsSL https://raw.githubusercontent.com/rofl0r/microsocks/master/README.md > /tmp/microsocks-readme; then
  sed -n '/^Usage/,/^$/p;/^-i /p;/^-p /p;/^-u /p;/^-P /p;/^-w /p' /tmp/microsocks-readme
else
  echo 'Unable to retrieve microsocks README' >&2
fi

printf '%s\n' '--- microsocks bind and authentication implementation ---'
if curl -fsSL https://raw.githubusercontent.com/rofl0r/microsocks/master/microsocks.c > /tmp/microsocks-c; then
  rg -n -C 4 'listen_ip|bind|username|password|SOCKS5_USER|SOCKS5_PASS|getopt|case .[ipuPw]' /tmp/microsocks-c || true
else
  echo 'Unable to retrieve microsocks source' >&2
fi

printf '%s\n' '--- Makefile recipe expansion by static substitution ---'
python3 - <<'PY'
from pathlib import Path
text = Path("Makefile").read_text()
start = text.index("socks5-proxy:")
end = text.index("\n\n", start)
recipe = text[start:end]
print(recipe)
print("\nFor HOST=0.0.0.0, the final command arguments are:")
print("microsocks -i 0.0.0.0 -p 1080")
PY

Repository: maximhq/bifrost

Length of output: 972


🌐 Web query:

microsocks GitHub README -i listen IP -u username -P password -w whitelist

💡 Result:

Microsocks is a lightweight SOCKS5 server that provides command-line options for configuring its behavior, including listening address, port, authentication, and IP whitelisting [1][2]. All arguments are optional, and by default, it listens on 0.0.0.0 at port 1080 [1][3]. Below are the relevant command-line options based on the official documentation: -i listenip: Specifies the local IP address or hostname the server should listen on [2]. -p port: Sets the TCP port the server listens on [2]. -u username: Specifies the username for authentication [2]. This must be used in conjunction with the -P option [2]. -P password: Specifies the password for authentication [2]. This must be used in conjunction with the -u option [2]. -w whitelist: Allows a comma-separated list of IP addresses to use the proxy without authentication [1][2]. -1 (auth_once mode): Once a client from a specific IP address successfully authenticates with the provided username and password, that IP is added to a temporary whitelist and can subsequently use the proxy without further authentication [1][2]. This option requires both -u and -P to be specified [2]. To restrict access so that only specific whitelisted IPs can connect, users can configure an intentionally difficult or impossible-to-guess username/password combination along with the -w option [2]. For more detailed information, you can refer to the official repository at https://github.com/rofl0r/microsocks [1].

Citations:


Reject non-loopback SOCKS5 binds unless access control is configured.

HOST=0.0.0.0 starts microsocks without authentication or an allowlist, which can expose an open proxy. Validate HOST as loopback, or require authentication and an appropriate allowlist for non-loopback binds.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Makefile` around lines 159 - 164, Update the socks5-proxy target to reject
non-loopback HOST values before starting microsocks, unless the command
configures authentication and an appropriate allowlist. Preserve the existing
loopback defaults and startup behavior, and ensure unsafe values such as 0.0.0.0
cannot launch an unauthenticated open proxy.

Source: MCP tools


install-tinyproxy: ## Install tinyproxy HTTP proxy for local testing (if not already installed)
@which tinyproxy > /dev/null || (command -v brew > /dev/null && $(ECHO) "$(YELLOW)Installing tinyproxy via Homebrew...$(NC)" && brew install tinyproxy) || ($(ECHO) "$(RED)Error: tinyproxy not found and Homebrew is unavailable. Install manually: https://github.com/tinyproxy/tinyproxy$(NC)" && exit 1)
@$(ECHO) "$(GREEN)tinyproxy is ready$(NC)"

http-proxy: install-tinyproxy ## Run a local HTTP proxy for testing provider proxy_config (Usage: make http-proxy [PORT=8888] [HOST=127.0.0.1])
@PROXY_PORT=$${PORT:-8888}; \
PROXY_HOST=$${HOST:-127.0.0.1}; \
CONF=$$(mktemp -t bifrost-tinyproxy); \
trap 'rm -f "$$CONF"' EXIT INT TERM; \
printf 'Port %s\nListen %s\nTimeout 600\nAllow 127.0.0.1\nAllow ::1\nLogLevel Info\n' "$$PROXY_PORT" "$$PROXY_HOST" > "$$CONF"; \
$(ECHO) "$(GREEN)Starting HTTP proxy on $$PROXY_HOST:$$PROXY_PORT (no auth, logs each connection, Ctrl+C to stop)...$(NC)"; \
$(ECHO) "$(YELLOW)Point a provider's proxy_config at http://$$PROXY_HOST:$$PROXY_PORT to test$(NC)"; \
tinyproxy -d -c "$$CONF"
Comment on lines +173 to +178

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

for template in bifrost-tinyproxy bifrost-tinyproxy.XXXXXX; do
  if path="$(mktemp -t "$template" 2>/dev/null)"; then
    printf 'accepted: %s -> %s\n' "$template" "$path"
    rm -f "$path"
  else
    printf 'rejected: %s\n' "$template"
  fi
done

Repository: maximhq/bifrost

Length of output: 249


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- Makefile context ---'
sed -n '145,185p' Makefile

printf '%s\n' '--- stack and working-tree summary ---'
git status --short
git branch --show-current
git log --oneline -8

printf '%s\n' '--- mktemp implementations available ---'
command -v mktemp
mktemp --version 2>/dev/null | head -n 2 || true

Repository: maximhq/bifrost

Length of output: 3377


Use a portable temporary-file template and fail fast.

GNU/Linux rejects mktemp -t bifrost-tinyproxy because the template lacks three X characters. Use mktemp "$${TMPDIR:-/tmp}/bifrost-tinyproxy.XXXXXX" || exit 1, and add || exit 1 to printf before launching tinyproxy.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Makefile` around lines 173 - 178, Update the temporary configuration setup in
the Makefile recipe to use the portable mktemp template
"$${TMPDIR:-/tmp}/bifrost-tinyproxy.XXXXXX" and exit immediately if mktemp
fails. Also make the printf command that writes "$$CONF" fail fast with "|| exit
1" before starting tinyproxy.

Source: MCP tools


dev: install-ui install-air setup-workspace $(if $(DEBUG),install-delve) ## Start complete development environment (UI + API with proxy)
@$(EXPOSE_ENV); \
set +m; \
Expand Down
8 changes: 4 additions & 4 deletions core/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ require (
github.com/andybalholm/brotli v1.2.2
github.com/aws/aws-sdk-go-v2 v1.42.0
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.10
github.com/aws/aws-sdk-go-v2/config v1.32.11
github.com/aws/aws-sdk-go-v2/config v1.32.14
github.com/aws/aws-sdk-go-v2/credentials v1.19.14
github.com/aws/aws-sdk-go-v2/service/s3 v1.97.3
github.com/aws/aws-sdk-go-v2/service/s3 v1.99.0
github.com/aws/aws-sdk-go-v2/service/sts v1.41.10
github.com/aws/smithy-go v1.27.1
github.com/bytedance/sonic v1.15.1
Expand Down Expand Up @@ -39,7 +39,7 @@ require (
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.21 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.29 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.29 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.5 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.6 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.22 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.7 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.13 // indirect
Expand All @@ -49,7 +49,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/sso v1.30.15 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.19 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.2 // indirect
github.com/buger/jsonparser v1.2.0 // indirect
github.com/bytedance/gopkg v0.1.3 // indirect
github.com/bytedance/sonic/loader v0.5.1 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
Expand Down
16 changes: 8 additions & 8 deletions core/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ github.com/aws/aws-sdk-go-v2 v1.42.0 h1:XvXMJTkFQtpBKIWZnmr9ZEOc2InWM2yldjXEJ/by
github.com/aws/aws-sdk-go-v2 v1.42.0/go.mod h1:27+ACypSLljLAEKsCYOmrjKh83vuTRkuAe9Uv/3A4bg=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.10 h1:gx1AwW1Iyk9Z9dD9F4akX5gnN3QZwUB20GGKH/I+Rho=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.10/go.mod h1:qqY157uZoqm5OXq/amuaBJyC9hgBCBQnsaWnPe905GY=
github.com/aws/aws-sdk-go-v2/config v1.32.11 h1:ftxI5sgz8jZkckuUHXfC/wMUc8u3fG1vQS0plr2F2Zs=
github.com/aws/aws-sdk-go-v2/config v1.32.11/go.mod h1:twF11+6ps9aNRKEDimksp923o44w/Thk9+8YIlzWMmo=
github.com/aws/aws-sdk-go-v2/config v1.32.14 h1:opVIRo/ZbbI8OIqSOKmpFaY7IwfFUOCCXBsUpJOwDdI=
github.com/aws/aws-sdk-go-v2/config v1.32.14/go.mod h1:U4/V0uKxh0Tl5sxmCBZ3AecYny4UNlVmObYjKuuaiOo=
github.com/aws/aws-sdk-go-v2/credentials v1.19.14 h1:n+UcGWAIZHkXzYt87uMFBv/l8THYELoX6gVcUvgl6fI=
github.com/aws/aws-sdk-go-v2/credentials v1.19.14/go.mod h1:cJKuyWB59Mqi0jM3nFYQRmnHVQIcgoxjEMAbLkpr62w=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.21 h1:NUS3K4BTDArQqNu2ih7yeDLaS3bmHD0YndtA6UP884g=
Expand All @@ -30,8 +30,8 @@ github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.29 h1:f3vKqSo13fhTYb+JE
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.29/go.mod h1:MzoLFUArKGpGD+ukmPiTPG1X5x4o6M2kq4v2dr1FiEc=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.29 h1:RdwIf/CuUsvJX3RgJagbOyotl/cxoLY4xviKuE7p2GY=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.29/go.mod h1:71wt8W2EgswdZy9Mf9KNnzxZ3TiZlv4caKghPktDOkA=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.5 h1:clHU5fm//kWS1C2HgtgWxfQbFbx4b6rx+5jzhgX9HrI=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.5/go.mod h1:O3h0IK87yXci+kg6flUKzJnWeziQUKciKrLjcatSNcY=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.6 h1:qYQ4pzQ2Oz6WpQ8T3HvGHnZydA72MnLuFK9tJwmrbHw=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.6/go.mod h1:O3h0IK87yXci+kg6flUKzJnWeziQUKciKrLjcatSNcY=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.22 h1:rWyie/PxDRIdhNf4DzRk0lvjVOqFJuNnO8WwaIRVxzQ=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.22/go.mod h1:zd/JsJ4P7oGfUhXn1VyLqaRZwPmZwg44Jf2dS84Dm3Y=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.7 h1:5EniKhLZe4xzL7a+fU3C2tfUN4nWIqlLesfrjkuPFTY=
Expand All @@ -42,8 +42,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.21 h1:c31//R3x
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.21/go.mod h1:r6+pf23ouCB718FUxaqzZdbpYFyDtehyZcmP5KL9FkA=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.21 h1:ZlvrNcHSFFWURB8avufQq9gFsheUgjVD9536obIknfM=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.21/go.mod h1:cv3TNhVrssKR0O/xxLJVRfd2oazSnZnkUeTf6ctUwfQ=
github.com/aws/aws-sdk-go-v2/service/s3 v1.97.3 h1:HwxWTbTrIHm5qY+CAEur0s/figc3qwvLWsNkF4RPToo=
github.com/aws/aws-sdk-go-v2/service/s3 v1.97.3/go.mod h1:uoA43SdFwacedBfSgfFSjjCvYe8aYBS7EnU5GZ/YKMM=
github.com/aws/aws-sdk-go-v2/service/s3 v1.99.0 h1:hlSuz394kV0vhv9drL5lhuEFbEOEP1VyQpy15qWh1Pk=
github.com/aws/aws-sdk-go-v2/service/s3 v1.99.0/go.mod h1:uoA43SdFwacedBfSgfFSjjCvYe8aYBS7EnU5GZ/YKMM=
github.com/aws/aws-sdk-go-v2/service/signin v1.0.9 h1:QKZH0S178gCmFEgst8hN0mCX1KxLgHBKKY/CLqwP8lg=
github.com/aws/aws-sdk-go-v2/service/signin v1.0.9/go.mod h1:7yuQJoT+OoH8aqIxw9vwF+8KpvLZ8AWmvmUWHsGQZvI=
github.com/aws/aws-sdk-go-v2/service/sso v1.30.15 h1:lFd1+ZSEYJZYvv9d6kXzhkZu07si3f+GQ1AaYwa2LUM=
Expand All @@ -56,8 +56,8 @@ github.com/aws/smithy-go v1.27.1 h1:4T340VFndXtADGF52gYa1POyL7s9E4Z1OeZ1hCscIw8=
github.com/aws/smithy-go v1.27.1/go.mod h1:YE2RhdIuDbA5E5bTdciG9KrW3+TiEONeUWCqxX9i1Fc=
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/buger/jsonparser v1.1.2 h1:frqHqw7otoVbk5M8LlE/L7HTnIq2v9RX6EJ48i9AxJk=
github.com/buger/jsonparser v1.1.2/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/buger/jsonparser v1.2.0 h1:4EFcvK1kD4jyj6YqNK6skK6w+y7FHHBR+XBCtxwu/6g=
github.com/buger/jsonparser v1.2.0/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M=
github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM=
github.com/bytedance/sonic v1.15.1 h1:nJD5PmM0vY7J8CT6MxoqbVAAMhkSmV2HgRAUrrpLoOw=
Expand Down
124 changes: 124 additions & 0 deletions core/providers/utils/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"
"testing"

ws "github.com/fasthttp/websocket"
"github.com/maximhq/bifrost/core/schemas"
"github.com/valyala/fasthttp"
)
Expand Down Expand Up @@ -92,3 +93,126 @@ func TestConfigureProxy_HTTPProxy_WithUnsetLiteralURL_KeepsDefaultBehavior(t *te
t.Fatal("expected dialer to remain unset when literal proxy URL is not provided")
}
}

func TestConfigureWebSocketProxy_HTTPProxy_WithLiteralURL_ConfiguresDialer(t *testing.T) {
dialer := &ws.Dialer{}
cfg := &schemas.ProxyConfig{
Type: schemas.HTTPProxy,
URL: schemas.NewSecretVar("http://127.0.0.1:1"),
}

_, err := ConfigureWebSocketProxy(dialer, cfg)
if err != nil {
t.Fatalf("expected no error configuring WebSocket proxy, got: %v", err)
}
if dialer.Proxy == nil {
t.Fatal("expected dialer.Proxy to be configured for literal HTTP proxy URL")
}
proxyURL, err := dialer.Proxy(nil)
if err != nil {
t.Fatalf("expected proxy func to resolve without error, got: %v", err)
}
if proxyURL == nil || proxyURL.Host != "127.0.0.1:1" {
t.Fatalf("expected resolved proxy URL host 127.0.0.1:1, got: %v", proxyURL)
}
}

func TestConfigureWebSocketProxy_HTTPProxy_WithEnvURL_ConfiguresDialer(t *testing.T) {
t.Setenv("BIFROST_TEST_WS_PROXY_URL", "http://127.0.0.1:1")

dialer := &ws.Dialer{}
cfg := &schemas.ProxyConfig{
Type: schemas.HTTPProxy,
URL: schemas.NewSecretVar("env.BIFROST_TEST_WS_PROXY_URL"),
}

_, err := ConfigureWebSocketProxy(dialer, cfg)
if err != nil {
t.Fatalf("expected no error configuring WebSocket proxy, got: %v", err)
}
if dialer.Proxy == nil {
t.Fatal("expected dialer.Proxy to be configured for env-backed HTTP proxy URL")
}
}

func TestConfigureWebSocketProxy_HTTPProxy_WithEmptyEnvValue_FailsFast(t *testing.T) {
t.Setenv("BIFROST_TEST_WS_PROXY_URL_EMPTY", "")

dialer := &ws.Dialer{}
cfg := &schemas.ProxyConfig{
Type: schemas.HTTPProxy,
URL: schemas.NewSecretVar("env.BIFROST_TEST_WS_PROXY_URL_EMPTY"),
}

_, err := ConfigureWebSocketProxy(dialer, cfg)
if err == nil {
t.Fatal("expected fail-fast error when env-backed proxy URL resolves empty")
}
if !strings.Contains(err.Error(), "proxy.url") || !strings.Contains(err.Error(), "env.BIFROST_TEST_WS_PROXY_URL_EMPTY") {
t.Fatalf("expected explicit proxy env configuration error, got: %v", err)
}
}

func TestConfigureWebSocketProxy_HTTPProxy_WithUnsetLiteralURL_KeepsDefaultBehavior(t *testing.T) {
dialer := &ws.Dialer{}
cfg := &schemas.ProxyConfig{
Type: schemas.HTTPProxy,
URL: nil,
}

_, err := ConfigureWebSocketProxy(dialer, cfg)
if err != nil {
t.Fatalf("expected no error when proxy URL is unset, got: %v", err)
}
if dialer.Proxy != nil {
t.Fatal("expected dialer.Proxy to remain unset when literal proxy URL is not provided")
}
}

func TestConfigureWebSocketProxy_Socks5Proxy_ConfiguresDialer(t *testing.T) {
dialer := &ws.Dialer{}
cfg := &schemas.ProxyConfig{
Type: schemas.Socks5Proxy,
URL: schemas.NewSecretVar("socks5://127.0.0.1:1080"),
}

_, err := ConfigureWebSocketProxy(dialer, cfg)
if err != nil {
t.Fatalf("expected no error configuring WebSocket proxy, got: %v", err)
}
if dialer.Proxy == nil {
t.Fatal("expected dialer.Proxy to be configured for SOCKS5 proxy URL")
}
proxyURL, err := dialer.Proxy(nil)
if err != nil {
t.Fatalf("expected proxy func to resolve without error, got: %v", err)
}
if proxyURL == nil || proxyURL.Scheme != "socks5" || proxyURL.Host != "127.0.0.1:1080" {
t.Fatalf("expected resolved socks5://127.0.0.1:1080 proxy URL, got: %v", proxyURL)
}
}

func TestConfigureWebSocketProxy_NoProxy_LeavesDialerUnset(t *testing.T) {
dialer := &ws.Dialer{}
cfg := &schemas.ProxyConfig{Type: schemas.NoProxy}

_, err := ConfigureWebSocketProxy(dialer, cfg)
if err != nil {
t.Fatalf("expected no error for NoProxy type, got: %v", err)
}
if dialer.Proxy != nil {
t.Fatal("expected dialer.Proxy to remain unset for NoProxy type")
}
}

func TestConfigureWebSocketProxy_NilConfig_LeavesDialerUnset(t *testing.T) {
dialer := &ws.Dialer{}

_, err := ConfigureWebSocketProxy(dialer, nil)
if err != nil {
t.Fatalf("expected no error for nil proxy config, got: %v", err)
}
if dialer.Proxy != nil {
t.Fatal("expected dialer.Proxy to remain unset for nil proxy config")
}
}
59 changes: 59 additions & 0 deletions core/providers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/bytedance/sonic"
"github.com/cespare/xxhash/v2"
ws "github.com/fasthttp/websocket"
"github.com/maximhq/bifrost/core/network"
"github.com/maximhq/bifrost/core/schemas"
"github.com/tidwall/gjson"
Expand Down Expand Up @@ -610,6 +611,64 @@ func ConfigureProxy(client *fasthttp.Client, proxyConfig *schemas.ProxyConfig, l
return client
}

// ConfigureWebSocketProxy sets up a proxy for a WebSocket dialer based on the provided configuration.
// It supports HTTP, SOCKS5, and environment-based proxy configurations, mirroring ConfigureProxy above.
// Unlike ConfigureProxy (which fails fast by swapping in an always-erroring fasthttp.DialFunc on a
// client that's built once and reused silently), this returns an error directly: callers resolve proxy
// configuration fresh on every dial, so a returned error surfaces immediately instead of on first use.
//
// ws.Dialer.Proxy dispatches on the resolved proxy URL's scheme internally (HTTP CONNECT tunneling for
// "http", golang.org/x/net/proxy.FromURL — which handles "socks5" — for everything else), so unlike the
// fasthttp path there is no need for separate HTTP vs SOCKS5 dialer constructors.
func ConfigureWebSocketProxy(dialer *ws.Dialer, proxyConfig *schemas.ProxyConfig) (*ws.Dialer, error) {
if proxyConfig == nil {
return dialer, nil
}

switch proxyConfig.Type {
case schemas.NoProxy:
return dialer, nil
case schemas.HTTPProxy, schemas.Socks5Proxy:
if proxyConfig.URL != nil && proxyConfig.URL.IsFromSecret() && proxyConfig.URL.GetValue() == "" {
return nil, fmt.Errorf("invalid proxy configuration: %s references %q but it resolved to an empty value", "proxy.url", proxyConfig.URL.GetRawRef())
}
proxyURLValue := proxyConfig.URL.GetValue()
if proxyURLValue == "" {
getLogger().Warn("Warning: proxy URL is required for setting up WebSocket proxy")
return dialer, nil
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
parsedURL, err := url.Parse(proxyURLValue)
if err != nil {
return nil, fmt.Errorf("invalid proxy configuration: invalid proxy URL: %w", err)
}
proxyUsername := proxyConfig.Username.GetValue()
proxyPassword := proxyConfig.Password.GetValue()
if proxyUsername != "" && proxyPassword != "" {
parsedURL.User = url.UserPassword(proxyUsername, proxyPassword)
}
dialer.Proxy = http.ProxyURL(parsedURL)
case schemas.EnvProxy:
dialer.Proxy = http.ProxyFromEnvironment
default:
return nil, fmt.Errorf("invalid proxy configuration: unsupported proxy type: %s", proxyConfig.Type)
}

if proxyConfig.CACertPEM != nil && proxyConfig.CACertPEM.IsFromSecret() && proxyConfig.CACertPEM.GetValue() == "" {
return nil, fmt.Errorf("invalid proxy configuration: %s references %q but it resolved to an empty value", "proxy.ca_cert_pem", proxyConfig.CACertPEM.GetRawRef())
}
proxyCACertPEM := proxyConfig.CACertPEM.GetValue()
if proxyCACertPEM != "" {
tlsConfig, err := createTLSConfigWithCA(proxyCACertPEM)
if err != nil {
return nil, fmt.Errorf("invalid proxy configuration: invalid proxy CA certificate: %w", err)
} else {
dialer.TLSClientConfig = tlsConfig
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
}

return dialer, nil
}

// createTLSConfigWithCA creates a TLS configuration with a custom CA certificate
// appended to the system root CA pool.
func createTLSConfigWithCA(caCertPEM string) (*tls.Config, error) {
Expand Down
13 changes: 7 additions & 6 deletions framework/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.26.5

require (
cloud.google.com/go/storage v1.62.1
github.com/aws/aws-sdk-go-v2/service/s3 v1.97.3
github.com/aws/aws-sdk-go-v2/service/s3 v1.99.0
github.com/google/uuid v1.6.0
github.com/jackc/pgx/v5 v5.9.2
github.com/maximhq/bifrost/core v1.7.5
Expand All @@ -13,7 +13,7 @@ require (
github.com/redis/go-redis/v9 v9.17.2
github.com/stretchr/testify v1.11.1
github.com/tidwall/gjson v1.18.0
github.com/weaviate/weaviate v1.36.5
github.com/weaviate/weaviate v1.38.0
github.com/weaviate/weaviate-go-client/v5 v5.7.1
golang.org/x/crypto v0.52.0
golang.org/x/sync v0.20.0
Expand Down Expand Up @@ -88,6 +88,7 @@ require (
github.com/segmentio/asm v1.2.0 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/spiffe/go-spiffe/v2 v2.6.0 // indirect
github.com/stretchr/objx v0.5.3 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
Expand All @@ -111,20 +112,20 @@ require (
cloud.google.com/go/compute/metadata v0.9.0 // indirect
github.com/andybalholm/brotli v1.2.2 // indirect
github.com/aws/aws-sdk-go-v2 v1.42.0
github.com/aws/aws-sdk-go-v2/config v1.32.11
github.com/aws/aws-sdk-go-v2/config v1.32.14
github.com/aws/aws-sdk-go-v2/credentials v1.19.14
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.21 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.29 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.29 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.5 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.6 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.7 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.21 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.30.15 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.19 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.41.10
github.com/aws/smithy-go v1.27.1 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.2 // indirect
github.com/buger/jsonparser v1.2.0 // indirect
github.com/bytedance/sonic v1.15.1
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
Expand All @@ -135,7 +136,7 @@ require (
github.com/go-openapi/jsonreference v0.21.4 // indirect
github.com/go-openapi/loads v0.23.2 // indirect
github.com/go-openapi/runtime v0.29.2 // indirect
github.com/go-openapi/spec v0.22.2 // indirect
github.com/go-openapi/spec v0.22.3 // indirect
github.com/go-openapi/strfmt v0.25.0 // indirect
github.com/go-openapi/swag v0.25.4 // indirect
github.com/go-openapi/validate v0.25.1 // indirect
Expand Down
Loading
Loading