Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 0b69c61

Browse files
committed
Improve SSL security of target connections
Previously we were not checking the hostname and verifying a cert as required. We also set up a basic ssl context in this PR Note this is connection to a host, it does not require our server key or set.
1 parent 7071591 commit 0b69c61

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/codegate/pipeline/secrets/signatures.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,10 @@ def _load_signatures(cls) -> None:
175175
yaml_data = cls._load_yaml(cls._yaml_path)
176176

177177
# Add custom GitHub token patterns
178-
github_patterns = {"Access Token": r"ghp_[0-9a-zA-Z]{32}",
179-
"Personal Token": r"github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59}"}
178+
github_patterns = {
179+
"Access Token": r"ghp_[0-9a-zA-Z]{32}",
180+
"Personal Token": r"github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59}",
181+
}
180182
cls._add_signature_group("GitHub", github_patterns)
181183

182184
# Process patterns from YAML

src/codegate/providers/copilot/provider.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,20 @@ async def connect_to_target(self):
350350
# Create SSL context for target connection
351351
logger.debug("Creating SSL context for target connection")
352352
target_ssl_context = ssl.create_default_context()
353-
# Don't verify certificates when connecting to target
354-
target_ssl_context.check_hostname = False
355-
target_ssl_context.verify_mode = ssl.CERT_NONE
356353

357-
# Connect directly to target host
354+
# Ensure that the target SSL certificate is verified
355+
target_ssl_context.check_hostname = True
356+
target_ssl_context.verify_mode = ssl.CERT_REQUIRED
357+
358+
# Connect to target
358359
logger.debug(f"Connecting to {self.target_host}:{self.target_port}")
359360
target_protocol = CopilotProxyTargetProtocol(self)
360361
transport, _ = await self.loop.create_connection(
361-
lambda: target_protocol, self.target_host, self.target_port, ssl=target_ssl_context
362+
lambda: target_protocol,
363+
self.target_host,
364+
self.target_port,
365+
ssl=target_ssl_context,
366+
server_hostname=self.target_host,
362367
)
363368

364369
logger.debug(f"Successfully connected to {self.target_host}:{self.target_port}")

0 commit comments

Comments
 (0)