Commit 466fd65
fix: backup download blocked by CORS (reply.hijack dropped the headers)
Every /admin/backup/:address request failed in the browser with "No
'Access-Control-Allow-Origin' header is present", despite returning 200
with a perfectly valid zip.
streamUserBackup wrote reply.raw directly behind reply.hijack(). That
skips Fastify's reply lifecycle, and @fastify/cors sets
Access-Control-Allow-Origin through reply.header() -- which is only
flushed to the socket by send(). Hijacking meant those headers were
never written, so the browser blocked a response the server considered
successful. Only the two headers I set by hand on reply.raw survived,
which is why the failure looked like a CORS misconfiguration rather than
a bug in this route.
Hand the archive to Fastify with reply.send(archive) instead. It pipes
the stream just the same, but the reply lifecycle runs, so CORS and any
other plugin headers are flushed normally.
The zip test now asserts access-control-allow-origin on the response.
Confirmed it fails against the hijack version and passes against this
one -- status code alone never proved this route worked from a browser.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 65c8854 commit 466fd65
2 files changed
Lines changed: 26 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
266 | | - | |
| 266 | + | |
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
| |||
274 | 274 | | |
275 | 275 | | |
276 | 276 | | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
277 | 287 | | |
278 | 288 | | |
279 | 289 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | 79 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
95 | 91 | | |
96 | 92 | | |
97 | 93 | | |
98 | 94 | | |
99 | | - | |
100 | | - | |
101 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
102 | 98 | | |
103 | 99 | | |
104 | 100 | | |
| |||
146 | 142 | | |
147 | 143 | | |
148 | 144 | | |
149 | | - | |
150 | | - | |
| 145 | + | |
151 | 146 | | |
152 | 147 | | |
153 | 148 | | |
| |||
0 commit comments