1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//! The trust gate over the project tier (#5428).
//!
//! Why: `<project>/.trusty-code/mcp.toml` is REPO-TRACKED content. Honouring
//! an arbitrary `command` from it means anyone who can land a commit — or
//! anyone whose repo you clone — chooses a subprocess this harness spawns with
//! the operator's ambient credentials. That is remote code execution, and it
//! is the same vector `trusty_agents::mcp::shared::merge_mcp_json` gates
//! `.mcp.json` behind (#3266).
//!
//! What: the project tier may say WHICH of the operator's globally configured
//! servers this project uses, never WHAT a server runs. A `Disable` always
//! passes — switching a connector off can only reduce what runs. A `Set` passes
//! only when it is content-equivalent to a global entry of the same name.
//! "Content-equivalent" is exactly [`transport_equivalent`]: the identical
//! command, args and env for stdio, the identical url and headers for a remote
//! entry. Name-only matching is NOT sufficient; that would let a project keep a
//! trusted name and swap the command behind it, which is the whole attack.
//! Anything else is refused as an [`McpIssue`] whose remedy names the global
//! file — the operator's own file, which they alone write.
//!
//! An accepted `Set` contributes exactly TWO things: its `name` (which matched)
//! and its `enabled` flag. `transport` is byte-identical by construction, and
//! `extensions` is DISCARDED and replaced with the global entry's — see
//! [`gate`]. `extensions` is an uninterpreted `serde_json` map every consumer
//! reads its own semantics out of (`trusty-agents` reads `auth`, `scopes` and
//! `discover` from it), so letting a repo-tracked file write it would hand that
//! file a second, unchecked channel into consumer behaviour — the same trust
//! boundary the transport comparison draws, walked around.
//!
//! // #5428: trust-by-content per the #7422/#3033 ruling.
//!
//! Test: `super::tests::trust_tests` — the whole module.
use Path;
use ;
use ;
/// What the operator must do to let a refused entry through.
const REMEDY: &str = "Add this server to ~/.trusty-tools/mcp/servers.toml, the file only you \
write. A project may choose among the servers configured there and \
disable them; it may not introduce or alter a command this harness runs.";
/// Whether two transports describe the SAME connection, byte for byte.
///
/// Why: the trust decision turns on content, not on a name, so this is the
/// whole comparison the gate rests on. A partial comparison — command but not
/// args, url but not headers — would leave exactly the gap the gate exists to
/// close.
/// What: variants must match, and every field within them. `BTreeMap` equality
/// covers `env` and `headers` including key order-independence and arity.
/// Test: `super::tests::trust_tests::an_identical_stdio_entry_is_equivalent`,
/// `super::tests::trust_tests::a_differing_arg_is_not_equivalent`,
/// `super::tests::trust_tests::a_differing_env_value_is_not_equivalent`,
/// `super::tests::trust_tests::http_and_sse_at_the_same_url_are_not_equivalent`.
/// Split the project's table into overrides the resolver may see and refusals.
///
/// Why: the single place the repo-content trust decision is made, so no caller
/// can reach `trusty_mcp::config::resolve` with an ungated project entry.
/// What: every `disabled` name becomes a `Disable` unconditionally. Every
/// `servers` entry becomes a `Set` only when a global entry of the same name
/// exists AND [`transport_equivalent`] holds — which still lets the project
/// flip `enabled`, because that field is outside the transport. Everything else
/// is refused with an [`McpIssue`] and a `tracing::warn!`. `project_path` names
/// the file in the finding and is never read here.
///
/// An accepted `Set` is emitted with the GLOBAL entry's `extensions`, not its
/// own: only `name` and `enabled` cross the boundary. See the module doc.
///
/// Disables are emitted BEFORE sets, matching
/// `trusty_agents::assistants::mcp::McpOverrides::as_overrides`, so a name in
/// both lists resolves as the more specific `Set` under the resolver's
/// left-to-right fold.
/// Test: `super::tests::trust_tests::a_matching_set_is_accepted`,
/// `super::tests::trust_tests::a_set_with_a_new_command_is_refused`,
/// `super::tests::trust_tests::a_set_naming_no_global_server_is_refused`,
/// `super::tests::trust_tests::a_set_may_re_enable_a_disabled_global_entry`,
/// `super::tests::trust_tests::a_set_cannot_smuggle_its_own_extensions`,
/// `super::tests::trust_tests::a_disable_always_passes`.
/// One refusal, logged and returned.
///
/// What: the detail names the server and what it tried, and NOTHING of the
/// transport — an `env` value or an auth header in a log line is the leak the
/// redacted `Debug` on `McpTransport` exists to prevent, and a refusal message
/// must not reintroduce it.