You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow WebSocket connections without Origin header for local/direct connections
Improve connection logging with specific messages for different connection types
Maintain security by still validating browser connections with Origin headers
Diagram Walkthrough
flowchart LR
A["WebSocket Connection"] --> B["Check Origin Header"]
B --> C["Origin is None?"]
C -->|Yes| D["Allow Local Connection"]
C -->|No| E["Check Allowed Origins"]
E -->|Valid| F["Allow Browser Connection"]
E -->|Invalid| G["Reject Connection"]
Loading
File Walkthrough
Relevant files
Enhancement
server.py
Enhanced WebSocket origin validation for local connections
agents/capture-agent-py/capture_agent/server.py
Modified Origin header validation logic to allow null origins
Added specific logging messages for different connection types
Maintained security for browser-based connections with Origin validation
Here are some key observations to aid the review process:
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 Security concerns
Origin validation change: Allowing connections with no Origin header broadens the trust surface. While likely safe for non-browser clients, some reverse proxies or misconfigured clients could omit Origin. Consider adding additional checks (e.g., verify remote address is local, require auth/token, or gate behind a config flag) and ensure ALLOWED_ORIGINS cannot be bypassed via case sensitivity or whitespace.
Using print for connection logs may be too noisy and inconsistent with typical logging; consider using the project's logger with levels (info/warn) and include peer info for traceability.
print("Client connected from local/direct connection (no Origin header)")
eliforigininALLOWED_ORIGINS:
print(f"Client connected from allowed origin: {origin}")
else:
print(f"Connection rejected from disallowed origin: {origin}")
Allowing None Origin is intentional, but consider explicitly documenting and restricting by transport (e.g., localhost or Unix socket) to avoid unintended acceptance of proxy-forwarded connections lacking Origin.
iforiginisNone:
print("Client connected from local/direct connection (no Origin header)")
eliforigininALLOWED_ORIGINS:
print(f"Client connected from allowed origin: {origin}")
else:
print(f"Connection rejected from disallowed origin: {origin}")
-if origin is None:- print("Client connected from local/direct connection (no Origin header)")+if origin is None or origin == "null":+ print(f"Client connected from local/direct connection (Origin: {origin})")
elif origin in ALLOWED_ORIGINS:
print(f"Client connected from allowed origin: {origin}")
else:
print(f"Connection rejected from disallowed origin: {origin}")
return
Apply / Chat
Suggestion importance[1-10]: 6
__
Why: The suggestion correctly identifies that the Origin: "null" header, a common case for local file testing, is not handled by the new logic, and proposes a valid fix to improve support for local development.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Enhancement
Description
Allow WebSocket connections without Origin header for local/direct connections
Improve connection logging with specific messages for different connection types
Maintain security by still validating browser connections with Origin headers
Diagram Walkthrough
File Walkthrough
server.py
Enhanced WebSocket origin validation for local connectionsagents/capture-agent-py/capture_agent/server.py
validation