feat(sandbox): add per-sandbox CORS header injection for port-forwarded services#514
Closed
feat(sandbox): add per-sandbox CORS header injection for port-forwarded services#514
Conversation
…ed services Adds opt-in CORS configuration to sandbox network policy endpoints. When configured, the SSH direct-tcpip handler injects CORS response headers on HTTP traffic and validates Origin on WebSocket upgrade requests. Non-configured ports remain raw TCP with zero overhead.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds opt-in, per-sandbox CORS configuration for port-forwarded services. When a sandbox policy endpoint has
cors.allowed_originsconfigured, the SSHdirect-tcpiphandler uses a CORS-aware HTTP relay instead of rawcopy_bidirectional, injecting CORS response headers and validating WebSocket upgrade origins.Changes
proto/sandbox.proto— AddedCorsConfigmessage (justallowed_origins) andcorsfield onNetworkEndpointcrates/openshell-policy/src/lib.rs— AddedCorsConfigDefserde struct, YAML/proto wiring,CorsEmptyOriginsvalidation, 4 new testscrates/openshell-sandbox/src/cors_relay.rs— New CORS-aware HTTP relay module with 8 unit tests. Handles:OPTIONSpreflight synthesis (never hits upstream)Originvalidation (rejects with 403 if disallowed)crates/openshell-sandbox/src/ssh.rs—SshHandlernow carriesCorsConfigMap;channel_open_direct_tcpipconditionally uses CORS relaycrates/openshell-sandbox/src/lib.rs— Extracts CORS configs from proto policy at startup, passes to SSH server, hot-reloads on policy updateExample policy YAML
Design decisions
allowed_originsis user-configurable. Methods, headers, and max-age use hardcoded defaults. Keeps the surface minimal and avoids footgun configurations.corsin the policy use the existing rawcopy_bidirectionalpath unchanged.Originheader during the upgrade handshake and rejects unauthorized origins with 403.Testing
mise run pre-commitpassesChecklist