Commit 863ba56
committed
fix: Ollama 403 on Windows — explicit Origin override (v0.3.12-rc1)
A user packet capture on Windows confirmed plugin-http v2.5.8 was
auto-injecting `origin: http://tauri.localhost` into every outbound
request. Ollama's default OLLAMA_ORIGINS allowlist accepts
`tauri://*` (matches macOS/Linux webview origin) but NOT
`http://tauri.localhost`, so Windows users hit 403 even with a
correctly-installed Ollama.
Fix: in `src/lib/llm-providers.ts`, set `Origin` explicitly on
both the `ollama` and `custom` (OpenAI-compat) provider branches,
using the request's own host. Same-origin is always trusted by
Ollama regardless of OLLAMA_ORIGINS contents or version.
Why this works at all:
- plugin-http v2.5.x JS shim only adds browser-default headers
when the user did NOT already set them (verified against
`node_modules/@tauri-apps/plugin-http/dist-js/index.js`,
line 71-75 — the loop after `new Request(input, init)` skips
`headers.set()` if the key is already present).
- The `unsafe-headers` Cargo feature is already enabled, so
Rust-side reqwest forwards `Origin` to the wire instead of
stripping it.
Verification layers:
- Layer 1 (source review of plugin-http): documented in code
comment; high confidence the fix works.
- Layer 2 (mocked unit tests, +6 in __tests__/llm-providers.test.ts):
pin Origin = same-origin for ollama (localhost / LAN / trailing
/v1), pin custom OpenAI-compat does the same, pin commercial
providers DON'T get an Origin override, pin malformed URL
falls back to no-Origin gracefully.
- Layer 3 (real-TCP fake-server test, new file
`src/lib/llm-client.real-llm.test.ts`): stands up a Node HTTP
server mimicking Ollama's CORS check, drives `streamChat`,
asserts Origin reaches the wire correctly. Includes a
"trivially-green" sanity test that proves the server's check
actually fires when Origin doesn't match.
- Layer 4 (manual Windows packet recapture against this rc1
build) — owner is doing this; will tag v0.3.12 if confirmed.
Test count: 651 mocked + 27 real-LLM, all green.1 parent 9f62d36 commit 863ba56
7 files changed
Lines changed: 444 additions & 4 deletions
File tree
- src-tauri
- src/lib
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
0 commit comments