Commit 92d68ad
Convert every remaining raw-node crossing to shadow copies (#356)
Roll the shadow pattern out beyond templates so no binding hands an lxml
node to xmlsec anymore (fast path unchanged on matched libxml2):
- template.c: all remaining functions, incl. the create shape
(BeginNewDoc/EndNewDoc builds the detached template in a private doc)
and the status-int C14N helper (FindFresh locates the created node).
- tree.c: finders map results back by path (EndFind, None on not-found;
find_parent shadows the whole tree); add_ids records id-attribute
specs instead of writing lxml's ID hash with our libxml2.
- ds.c: sign/verify run on a whole-document copy (BeginDoc) with the
recorded IDs replayed so #id references resolve; sign reflects all
mutation sites (DigestValue/SignatureValue/KeyInfo) via ReflectAll,
verify just discards the copy.
- enc.c: encrypt_binary/encrypt_uri reflect the mutated template;
encrypt_xml/decrypt re-parse everything into one copy and reflect the
replacement through lxml (element, content, or returned bytes).
Replacing the document root cannot be expressed through lxml's API
and raises a clear error on the shadow path.
ReflectAll is two-phase (prefetch payloads from the re-parsed copy in
its final state, then apply to the live tree in document order) because
each graft moves a node out of the copy and would invalidate the
indices later sites resolve through.
Two template tests now attach the created template before asserting
liveness: a shadow-created template lives in its own document until
grafted, as lxml cannot express the raw path's "detached node inside an
existing document".
Validated under a real 2.14<->2.15 mismatch (full suite, 10k-iteration
sign/verify/encrypt/decrypt loop, flat RSS, byte-identical output) and
on a matched static wheel with and without PYXMLSEC_FORCE_SHADOW.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent 72a78cb commit 92d68ad
9 files changed
Lines changed: 1498 additions & 106 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
29 | 34 | | |
30 | 35 | | |
31 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
| 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 | + | |
61 | 107 | | |
62 | 108 | | |
63 | 109 | | |
| |||
114 | 160 | | |
115 | 161 | | |
116 | 162 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 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 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
149 | 182 | | |
150 | 183 | | |
151 | 184 | | |
| |||
189 | 222 | | |
190 | 223 | | |
191 | 224 | | |
| 225 | + | |
| 226 | + | |
192 | 227 | | |
193 | 228 | | |
194 | 229 | | |
195 | 230 | | |
196 | 231 | | |
197 | 232 | | |
198 | 233 | | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
199 | 246 | | |
200 | | - | |
| 247 | + | |
201 | 248 | | |
202 | 249 | | |
203 | 250 | | |
| 251 | + | |
204 | 252 | | |
205 | 253 | | |
206 | 254 | | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
207 | 258 | | |
208 | 259 | | |
209 | 260 | | |
| |||
224 | 275 | | |
225 | 276 | | |
226 | 277 | | |
| 278 | + | |
| 279 | + | |
227 | 280 | | |
228 | 281 | | |
229 | 282 | | |
230 | 283 | | |
231 | 284 | | |
232 | 285 | | |
233 | 286 | | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
234 | 296 | | |
235 | | - | |
| 297 | + | |
236 | 298 | | |
237 | 299 | | |
| 300 | + | |
238 | 301 | | |
239 | 302 | | |
240 | 303 | | |
| |||
0 commit comments