Skip to content

Secure, Fast, and Extensible Sandbox runtime for AI agents.

fix(egress): review fixes for exchange vault core

高然89a0c374169a
diff --git a/components/egress/pkg/credentialvault/candidate.go b/components/egress/pkg/credentialvault/candidate.go
index f40bcdfb6..89108149a 100644
--- a/components/egress/pkg/credentialvault/candidate.go
+++ b/components/egress/pkg/credentialvault/candidate.go
@@ -396,9 +396,7 @@ func renderActiveSnapshot(
for _, name := range names {
binding := bindings[name]
if binding.Auth.Type == "" {
- // Typeless exchange binding: marker-only. No credential material
- // is rendered locally and no resolve network call happens on this
- // path — header sets are resolved per request by the resolver.
+ // Typeless exchange binding: marker-only, no rendering, no network.
snapshot.Bindings = append(snapshot.Bindings, ActiveBinding{
Name: binding.Name,
Match: binding.Match,
@@ -454,7 +452,7 @@ func cloneActiveSnapshot(snapshot ActiveSnapshot) ActiveSnapshot {
rendered := ActiveBinding{
Name: binding.Name,
Match: cloneMatch(binding.Match),
- Headers: append([]InjectionHeader(nil), binding.Headers...),
+ Headers: cloneInjectionHeaders(binding.Headers),
}
if binding.Substitutions != nil {
subs := make([]InjectionSubstitution, len(*binding.Substitutions))
@@ -475,6 +473,16 @@ func cloneActiveSnapshot(snapshot ActiveSnapshot) ActiveSnapshot {
return clone
}
+// cloneInjectionHeaders preserves nil-ness: passthrough bindings render null
+// headers while exchange markers carry an explicit empty array — degrading
+// the empty array to null would fail the addon parser closed.
+func cloneInjectionHeaders(headers []InjectionHeader) []InjectionHeader {
+ if headers == nil {
+ return nil
+ }
+ return append(make([]InjectionHeader, 0, len(headers)), headers...)
+}
+
func cloneMatch(match Match) Match {
return Match{
Schemes: append([]string(nil), match.Schemes...),
diff --git a/components/egress/pkg/credentialvault/decision_snapshot.go b/components/egress/pkg/credentialvault/decision_snapshot.go
index 4cf4d3a20..667457089 100644
--- a/components/egress/pkg/credentialvault/decision_snapshot.go
+++ b/components/egress/pkg/credentialvault/decision_snapshot.go
@@ -138,11 +138,9 @@ func validRenderedBinding(binding *ActiveBinding, redactions map[string]struct{}
}
binding.Headers = append([]InjectionHeader{}, binding.Headers...)
if binding.Exchange != nil {
- // OSEP-0025 marker binding: a credential-only reference with no
- // rendered material, so no redaction coverage is required. The
- // canonical encoding carries explicit empty headers/substitutions
- // arrays; readers without exchange support reject the unknown key
- // (version-skew fail closed).
+ // Marker binding: no rendered material, so no redaction coverage.
+ // Canonical form keeps explicit empty arrays; the marker plus any
+ // rendered content is non-canonical and rejected.
credential := binding.Exchange.Credential
if credential == "" || credential != strings.TrimSpace(credential) {
return false
@@ -150,6 +148,9 @@ func validRenderedBinding(binding *ActiveBinding, redactions map[string]struct{}
if len(binding.Headers) != 0 {
return false
}
+ if binding.Substitutions != nil && len(*binding.Substitutions) != 0 {
+ return false
+ }
empty := []InjectionSubstitution{}
binding.Substitutions = &empty
return true
diff --git a/components/egress/pkg/credentialvault/decision_snapshot_test.go b/components/egress/pkg/credentialvault/decision_snapshot_test.go
index ebbdb2919..0571d4900 100644
--- a/components/egress/pkg/credentialvault/decision_snapshot_test.go
+++ b/components/egress/pkg/credentialvault/decision_snapshot_test.go
@@ -240,6 +240,9 @@ func TestMarshalDecisionSnapshotRejectsNonCanonicalExchangeMarkers(t *testing.T)
{"blank credential", func(b *ActiveBinding) { b.Exchange.Credential = "" }},
{"padded credential", func(b *ActiveBinding) { b.Exchange.Credential = " spi-signer " }},
{"rendered header", func(b *ActiveBinding) { b.Headers = []InjectionHeader{{Name: "Authorization", Value: "never-log-me"}} }},
+ {"rendered substitution", func(b *ActiveBinding) {
+ b.Substitutions = &[]InjectionSubstitution{{Placeholder: "__t__", Value: "never-log-me", In: []string{"header"}}}
+ }},
{"nil exchange credential", func(b *ActiveBinding) { b.Exchange = &ExchangeRef{} }},
}
for _, tc := range tests {
diff --git a/components/egress/pkg/credentialvault/source_exchange.go b/components/egress/pkg/credentialvault/source_exchange.go
index 5e66ba4eb..2b9cfe901 100644
--- a/components/egress/pkg/credentialvault/source_exchange.go
+++ b/components/egress/pkg/credentialvault/source_exchange.go
@@ -23,11 +23,9 @@ import (
"strings"
)
-// exchangeSource is a credential with no local material: header sets are
-// resolved per request by an external header-resolver service (OSEP-0025).
-// Resolve is deliberately offline — exchange credentials are never rendered
-// into static snapshots; they surface only as binding markers and are
-// resolved on the per-request path.
+// exchangeSource holds no local material: header sets resolve per request
+// from the endpoint's resolver. Resolve fails closed — exchange credentials
+// surface only as snapshot markers, never rendered values.
type exchangeSource struct {
endpoint string
}
@@ -41,9 +39,7 @@ func (s *exchangeSource) Resolve(_ context.Context) (string, error) {
// exchangeSourceFactory creates an exchangeSource from the raw JSON "source"
// object. Expected shape: {"type": "exchange", "endpoint": "<uri>"}.
// Unknown fields are rejected to match the OpenAPI additionalProperties: false
-// contract. Supported endpoint forms are unix:///absolute/path (HTTP over a
-// Unix domain socket) and https://host[:port] (optionally with a path
-// prefix); anything else is rejected.
+// contract.
func exchangeSourceFactory(raw json.RawMessage) (CredentialSource, error) {
var src struct {
Type string `json:"type"`
@@ -77,6 +73,9 @@ func validateResolverEndpoint(endpoint string) (string, error) {
if parsed.Host == "" || parsed.User != nil {
return "", fmt.Errorf("exchange credential endpoint %q must address https://host[:port]", endpoint)
}
+ if parsed.RawQuery != "" || parsed.Fragment != "" || parsed.RawFragment != "" {
+ return "", fmt.Errorf("exchange credential endpoint %q must not carry a query or fragment", endpoint)
+ }
return endpoint, nil
default:
return "", fmt.Errorf("exchange credential endpoint %q must use the unix:/// or https:// scheme", endpoint)
diff --git a/components/egress/pkg/credentialvault/source_exchange_test.go b/components/egress/pkg/credentialvault/source_exchange_test.go
index 026b4fb77..d754e08ba 100644
--- a/components/egress/pkg/credentialvault/source_exchange_test.go
+++ b/components/egress/pkg/credentialvault/source_exchange_test.go
@@ -45,6 +45,8 @@ func TestExchangeSourceFactoryRejects(t *testing.T) {
{"empty endpoint", `{"type":"exchange","endpoint":""}`},
{"http scheme", `{"type":"exchange","endpoint":"http://resolver.internal"}`},
{"bare host", `{"type":"exchange","endpoint":"resolver.internal:8443"}`},
+ {"query string", `{"type":"exchange","endpoint":"https://resolver.internal/prefix?debug=1"}`},
+ {"fragment", `{"type":"exchange","endpoint":"https://resolver.internal/prefix#section"}`},
{"unix relative path", `{"type":"exchange","endpoint":"unix://spi.sock"}`},
{"unix empty path", `{"type":"exchange","endpoint":"unix:///"}`},
{"unknown field", `{"type":"exchange","endpoint":"unix:///run/spi.sock","value":"secret"}`},
diff --git a/components/egress/pkg/credentialvault/vault.go b/components/egress/pkg/credentialvault/vault.go
index bf3894377..9d6284dd4 100644
--- a/components/egress/pkg/credentialvault/vault.go
+++ b/components/egress/pkg/credentialvault/vault.go
@@ -235,10 +235,9 @@ type ActiveSnapshot struct {
Redactions []string `json:"redactions,omitempty"`
}
-// ExchangeRef marks an exchange-resolved binding in snapshots: header sets
-// are not materialized locally, only the credential that the per-request
-// resolve path must consult. The referenced credential is always
-// exchange-sourced (enforced by validateAuthSourceCrossLock).
+// ExchangeRef marks an exchange-resolved binding in snapshots: no material
+// is rendered locally, only the credential the per-request resolve path
+// consults (always exchange-sourced, per the cross-lock).
type ExchangeRef struct {
Credential string `json:"credential"`
}
@@ -270,25 +269,20 @@ func NewLiveStore(gate *mitmproxy.HealthGate, requireToken func() bool, config m
return store
}
-// ResolverConfig reports whether the credential resolver operator
-// configuration (OSEP-0025 D13) is ready: a resolve timeout is configured and
-// the endpoint-scoped auth table parsed successfully. The zero value is not
-// ready — vaults referencing exchange credentials fail closed until the
-// transport layer injects its parsed configuration.
+// ResolverConfig reports whether the resolver operator configuration is
+// ready (D13): resolve timeout configured and the endpoint auth table parsed.
+// The zero value is not ready — exchange vaults fail closed until injected.
type ResolverConfig struct {
TimeoutConfigured bool
AuthTableParsed bool
}
-// Ready reports whether vaults referencing exchange credentials may be
-// admitted.
func (c ResolverConfig) Ready() bool {
return c.TimeoutConfigured && c.AuthTableParsed
}
-// SetResolverConfig installs the resolver operator-config readiness used by
-// the exchange capability gate. Callers must invoke it before serving vault
-// mutations.
+// SetResolverConfig installs the exchange capability gate's readiness. Call
+// before serving vault mutations.
func (v *Store) SetResolverConfig(config ResolverConfig) {
v.mu.Lock()
defer v.mu.Unlock()
@@ -551,11 +545,9 @@ func (v *Store) validateCandidate(credentials map[string]record, bindings map[st
return nil
}
-// validateExchangeAdmission is the exchange fail-closed gate: a vault that
-// carries exchange-sourced credentials is admitted only by stores with the
-// capability to serve the per-request resolve path. The live revision runtime
-// never supports exchange; ordinary stores require the resolver operator
-// configuration (D13). Inline-only vaults are unaffected.
+// validateExchangeAdmission fails closed on exchange-sourced credentials:
+// the live revision runtime never supports them; other stores require the
+// resolver operator configuration (D13). Inline-only vaults are unaffected.
func (v *Store) validateExchangeAdmission(credentials map[string]record) error {
hasExchange := false
for _, credential := range credentials {
@@ -760,9 +752,8 @@ func normalizeAuth(a *Auth) error {
return fmt.Errorf("passthrough auth does not accept headers")
}
case "":
- // Typeless: the exchange-only reference form. The referenced
- // credential must be exchange-sourced (cross-lock) and nothing else
- // may ride along — header sets resolve per request, never locally.
+ // Typeless: the exchange-only reference form; cross-lock enforces
+ // the exchange source. Headers resolve per request, never locally.
a.Credential = strings.TrimSpace(a.Credential)
if a.Credential == "" {
return fmt.Errorf("typeless auth requires credential")
@@ -802,13 +793,10 @@ func validateBindingCredentialRefs(b Binding, credentials map[string]record) err
return nil
}
-// validateAuthSourceCrossLock pins the OSEP-0025 reference discipline: static
-// auth types render locally and must never consume exchange-sourced
-// credentials, while the typeless exchange form exists only for them.
-// Substitution values always render locally, so they reject exchange
-// credentials for every auth type. passthrough references no auth credential
-// and is otherwise unrestricted. Custom (non-exchange) source types keep
-// working with static auth.
+// validateAuthSourceCrossLock pins the exchange reference discipline: static
+// auth types and substitutions render locally and reject exchange-sourced
+// credentials; the typeless form accepts only exchange-sourced ones.
+// passthrough references no auth credential.
func validateAuthSourceCrossLock(b Binding, credentials map[string]record) error {
for _, name := range authCredentialRefs(b.Auth) {
rec, ok := credentials[name]
@@ -913,10 +901,8 @@ func renderInjectionHeaders(ctx context.Context, auth Auth, credentials map[stri
}
case "passthrough":
case "":
- // Typeless bindings reference exchange credentials and are rendered
- // as snapshot markers only; their header sets come from the
- // per-request resolve path. Defensive: renderActiveSnapshot never
- // routes them here.
+ // Typeless bindings render as snapshot markers only; this branch is
+ // defensive — renderActiveSnapshot never routes them here.
return nil, nil, fmt.Errorf("typeless exchange auth cannot be rendered as static injection headers")
default:
return nil, nil, fmt.Errorf("unsupported auth type %q", auth.Type)
diff --git a/components/egress/pkg/credentialvault/vault_test.go b/components/egress/pkg/credentialvault/vault_test.go
index 7f0e1e65c..f5809ecdb 100644
--- a/components/egress/pkg/credentialvault/vault_test.go
+++ b/components/egress/pkg/credentialvault/vault_test.go
@@ -669,6 +669,51 @@ func TestCredentialVaultTypelessExchangeAuthSanitizesAndRendersMarker(t *testing
}`, string(mustMarshal(snapshot)))
}
+func TestCredentialVaultExchangeMarkerSnapshotSurvivesPrepareCommitClone(t *testing.T) {
+ // The relay write path serves the snapshot pinned by CommitCandidate —
+ // a clone. Degrading the marker's empty arrays to null would fail the
+ // addon parser closed; passthrough pins the pre-existing null bytes.
+ store := testResolverReadyStore()
+ request := testExchangeVaultRequest()
+ request.Bindings = append(request.Bindings, Binding{
+ Name: "passthrough-api",
+ Match: Match{Hosts: []string{"plain.internal.example.com"}, Methods: []string{"GET"}, Paths: []string{"/other/*"}},
+ Auth: Auth{Type: "passthrough"},
+ })
+ pol := testCredentialPolicy(t, `{"defaultAction":"deny","egress":[
+ {"action":"allow","target":"api.internal.example.com"},
+ {"action":"allow","target":"plain.internal.example.com"}
+ ]}`)
+ candidate, err := store.PrepareCreate(request, pol)
+ require.NoError(t, err)
+ _, err = candidate.ActiveSnapshot(context.Background())
+ require.NoError(t, err)
+ _, err = store.CommitCandidate(candidate)
+ require.NoError(t, err)
+
+ served, err := store.ActiveSnapshot()
+ require.NoError(t, err)
+ encoded := string(mustMarshal(served))
+ require.Contains(t, encoded, `"headers":[],"substitutions":[],"exchange":{"credential":"spi-signer"}`)
+ require.Contains(t, encoded, `"headers":null`)
+ require.NotContains(t, encoded, `"exchange":null`)
+
+ bindings := map[string]ActiveBinding{}
+ for _, binding := range served.Bindings {
+ bindings[binding.Name] = binding
+ }
+ require.NotNil(t, bindings["internal-api"].Headers)
+ require.Empty(t, bindings["internal-api"].Headers)
+ require.NotNil(t, bindings["internal-api"].Substitutions)
+ require.Empty(t, *bindings["internal-api"].Substitutions)
+
+ // The conditional-lookup path serves the same pinned clone.
+ conditional, _, changed, err := store.ActiveSnapshotIfChanged(context.Background(), "")
+ require.NoError(t, err)
+ require.True(t, changed)
+ require.Equal(t, served, conditional)
+}
+
func TestCredentialVaultTypelessAuthRejectsExtraFields(t *testing.T) {
base := testExchangeVaultRequest()
tests := []struct {
@@ -834,9 +879,7 @@ func TestCredentialVaultLiveRevisionRuntimeRejectsExchange(t *testing.T) {
}
func TestCredentialVaultExchangeReloadRequiresNoResolverListener(t *testing.T) {
- // Reload runs factory validation and the capability gate only — it must
- // never dial the resolver, so it succeeds without anything listening on
- // the endpoint socket.
+ // Reload runs factory validation and gates only — never dials the resolver.
store := testResolverReadyStore()
require.NoError(t, store.Reload(4, testExchangeVaultRequest(), testExchangePolicy(t)))
snapshot, err := store.ActiveSnapshot()