Commit 6e55991
committed
fix: raise ResourceSecurityError instead of falling through on rejection
ResourceTemplate.matches() previously returned None for both "URI
doesn't match this template" and "URI matches but fails security
validation". ResourceManager.get_resource iterates templates and uses
the first non-None result, so a strict template's security rejection
would silently fall through to a later, possibly permissive, template.
Registration order became security-critical without documentation.
matches() now raises ResourceSecurityError on security failure,
halting template iteration at the first rejection. The error carries
the template string and the offending parameter name.
ResourceSecurity.validate() now returns the name of the first failing
parameter (or None if all pass) rather than a bool, so the error can
identify which parameter was rejected.1 parent 8fb3d6f commit 6e55991
File tree
3 files changed
+73
-18
lines changed- src/mcp/server/mcpserver/resources
- tests/server/mcpserver/resources
3 files changed
+73
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
| 66 | + | |
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
73 | | - | |
| 74 | + | |
74 | 75 | | |
75 | | - | |
| 76 | + | |
76 | 77 | | |
77 | | - | |
78 | | - | |
| 78 | + | |
| 79 | + | |
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
85 | 100 | | |
86 | 101 | | |
87 | 102 | | |
| |||
165 | 180 | | |
166 | 181 | | |
167 | 182 | | |
168 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
169 | 191 | | |
170 | 192 | | |
171 | 193 | | |
172 | 194 | | |
173 | | - | |
174 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
175 | 198 | | |
176 | 199 | | |
177 | 200 | | |
| |||
Lines changed: 39 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
| 34 | + | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
38 | | - | |
| 40 | + | |
| 41 | + | |
39 | 42 | | |
40 | 43 | | |
41 | 44 | | |
42 | 45 | | |
43 | 46 | | |
44 | | - | |
| 47 | + | |
| 48 | + | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
49 | | - | |
| 53 | + | |
| 54 | + | |
50 | 55 | | |
51 | 56 | | |
52 | 57 | | |
| |||
71 | 76 | | |
72 | 77 | | |
73 | 78 | | |
74 | | - | |
| 79 | + | |
| 80 | + | |
75 | 81 | | |
76 | | - | |
| 82 | + | |
| 83 | + | |
77 | 84 | | |
78 | 85 | | |
79 | 86 | | |
| |||
82 | 89 | | |
83 | 90 | | |
84 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
85 | 112 | | |
86 | 113 | | |
87 | 114 | | |
88 | 115 | | |
89 | | - | |
| 116 | + | |
| 117 | + | |
90 | 118 | | |
91 | 119 | | |
92 | 120 | | |
93 | 121 | | |
94 | 122 | | |
95 | 123 | | |
96 | | - | |
| 124 | + | |
| 125 | + | |
97 | 126 | | |
98 | 127 | | |
99 | 128 | | |
100 | 129 | | |
101 | 130 | | |
102 | | - | |
| 131 | + | |
| 132 | + | |
103 | 133 | | |
104 | 134 | | |
105 | 135 | | |
| |||
0 commit comments