Commit 4cccc0e
committed
fix(images): the CSP blocked every thumbnail, and an image with no words 400'd
Three bugs from a real run, all mine.
1. THE THUMBNAIL WAS BROKEN BECAUSE NOTHING COULD RENDER IT. The webview CSP is
`default-src 'none'` with no img-src, so every image — including a data: URI built from
the attachment's own bytes — was blocked. I added images without touching the policy.
Now `img-src data:`, and deliberately NOT https:, so the panel still cannot fetch a
remote image.
2. AN IMAGE WITH NO WORDS RETURNED A 400. Anthropic rejects an empty text block outright
("text content blocks must be non-empty"), and sending an image with nothing typed
produced exactly that. Both paths now include the text block only when there IS text,
and fall back to the images alone. This is the case I deliberately made valid in I5 —
"look at this" is implied by attaching — so it was the one shape guaranteed to be hit.
3. DRAGGING FROM FINDER DID NOTHING. VS Code's workbench intercepts OS file drops before a
webview iframe sees them, so dataTransfer.files is empty — while the PATH is still
there as a uri-list. The drop handler now falls back to reading the uri-list and handing
the paths to the host, which reads them off disk and sends the bytes back for the same
normalizer a paste uses. Size is checked host-side BEFORE base64 crosses the message
bus, so a 200MB file is refused rather than serialized first.
Also I6: a visible Attach-image button next to +, using showOpenDialog. The picker is the
route that works regardless of what the webview is allowed to receive; the drop fallback is
best-effort on top of it.
Two guards needed updating rather than adding — the empty-text ternary changed the shape
they matched. That is the guards doing their job; I updated them and added one that pins
the 400 itself.
14 tests in imageAttach, 37 suites green.1 parent 9e297f4 commit 4cccc0e
3 files changed
Lines changed: 125 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1617 | 1617 | | |
1618 | 1618 | | |
1619 | 1619 | | |
1620 | | - | |
| 1620 | + | |
1621 | 1621 | | |
1622 | 1622 | | |
1623 | 1623 | | |
| |||
1745 | 1745 | | |
1746 | 1746 | | |
1747 | 1747 | | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
1748 | 1790 | | |
1749 | 1791 | | |
1750 | 1792 | | |
| |||
1821 | 1863 | | |
1822 | 1864 | | |
1823 | 1865 | | |
| 1866 | + | |
| 1867 | + | |
1824 | 1868 | | |
1825 | | - | |
| 1869 | + | |
1826 | 1870 | | |
1827 | 1871 | | |
1828 | 1872 | | |
| |||
2359 | 2403 | | |
2360 | 2404 | | |
2361 | 2405 | | |
| 2406 | + | |
| 2407 | + | |
2362 | 2408 | | |
2363 | 2409 | | |
2364 | 2410 | | |
| |||
2557 | 2603 | | |
2558 | 2604 | | |
2559 | 2605 | | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
2560 | 2609 | | |
2561 | 2610 | | |
2562 | 2611 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
68 | 71 | | |
69 | 72 | | |
70 | 73 | | |
| |||
1333 | 1336 | | |
1334 | 1337 | | |
1335 | 1338 | | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
1336 | 1342 | | |
1337 | 1343 | | |
1338 | 1344 | | |
| |||
3178 | 3184 | | |
3179 | 3185 | | |
3180 | 3186 | | |
| 3187 | + | |
| 3188 | + | |
| 3189 | + | |
| 3190 | + | |
| 3191 | + | |
| 3192 | + | |
| 3193 | + | |
| 3194 | + | |
3181 | 3195 | | |
3182 | 3196 | | |
3183 | 3197 | | |
| |||
3225 | 3239 | | |
3226 | 3240 | | |
3227 | 3241 | | |
3228 | | - | |
3229 | | - | |
3230 | | - | |
| 3242 | + | |
| 3243 | + | |
| 3244 | + | |
| 3245 | + | |
| 3246 | + | |
| 3247 | + | |
| 3248 | + | |
| 3249 | + | |
| 3250 | + | |
| 3251 | + | |
| 3252 | + | |
| 3253 | + | |
| 3254 | + | |
| 3255 | + | |
3231 | 3256 | | |
3232 | | - | |
| 3257 | + | |
| 3258 | + | |
3233 | 3259 | | |
3234 | 3260 | | |
3235 | 3261 | | |
3236 | 3262 | | |
| 3263 | + | |
| 3264 | + | |
| 3265 | + | |
| 3266 | + | |
3237 | 3267 | | |
3238 | 3268 | | |
3239 | 3269 | | |
| |||
3797 | 3827 | | |
3798 | 3828 | | |
3799 | 3829 | | |
| 3830 | + | |
| 3831 | + | |
| 3832 | + | |
3800 | 3833 | | |
3801 | 3834 | | |
3802 | 3835 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
| 140 | + | |
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| |||
151 | 151 | | |
152 | 152 | | |
153 | 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 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
154 | 189 | | |
0 commit comments