Commit 0901d61
committed
Validate v1 Cloudflare signature; preserve state
Align signature parsing with production Cloudflare format and harden validation, and prevent wiping agent state.
- signature.utils: import SignatureVersionInvalidError, parse headers expecting `t=<timestamp>,v1=<sig>`, validate numeric timestamp and explicit `v1` version, compute HMAC over `<timestamp>.<JSON-payload>` and compare. Improves robustness and throws clear errors for invalid version/timestamp.
- cloudflare/helpers: change rememberLastRef to merge the new STATE_KEY into existing agent.state instead of replacing it, preventing loss of other state properties.
- cloudflare.test: update tests to use the `t=` header format, add a test for invalid signature version, and adjust the fake agent/setState test to ensure other state keys are preserved.1 parent 293d028 commit 0901d61
3 files changed
Lines changed: 21 additions & 9 deletions
Lines changed: 14 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
133 | 141 | | |
134 | 142 | | |
135 | 143 | | |
| |||
252 | 260 | | |
253 | 261 | | |
254 | 262 | | |
255 | | - | |
| 263 | + | |
256 | 264 | | |
257 | 265 | | |
258 | 266 | | |
259 | 267 | | |
260 | | - | |
261 | | - | |
| 268 | + | |
| 269 | + | |
262 | 270 | | |
263 | 271 | | |
264 | 272 | | |
| |||
273 | 281 | | |
274 | 282 | | |
275 | 283 | | |
| 284 | + | |
276 | 285 | | |
277 | 286 | | |
278 | 287 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | | - | |
169 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
170 | 172 | | |
171 | 173 | | |
| 174 | + | |
172 | 175 | | |
173 | 176 | | |
174 | 177 | | |
| |||
183 | 186 | | |
184 | 187 | | |
185 | 188 | | |
186 | | - | |
| 189 | + | |
187 | 190 | | |
0 commit comments