Commit 78e11a7
authored
fix: LiteLLM cache key collision and silent fallback to non-existent default model (#647)
* fix: LiteLLM provider model desync after Sync Models or settings navigation
- Invalidate React Query router-models cache on successful sync in LiteLLM.tsx
so useSelectedModel picks up the refreshed list (mirrors Poe.tsx fix)
- Preserve configured litellm model ID when model list is empty/loading in
useSelectedModel.ts instead of silently falling back to hardcoded default
- Pass litellm credentials in the debounced requestRouterModels message in
ApiOptions.tsx to prevent fetches with stale config from clearing the model list
* fix: address CodeRabbit review comments on litellm model desync
- Refactor getCacheKey to compute URL and key components independently,
preventing key-scoped providers on the default server from collapsing
to the same cache entry
- Replace character-substitution in cacheKeyToFilename with SHA-256 hash
for collision-free filesystem-safe filenames
- Block AUTH_SCOPED_PROVIDERS (zoo-gateway) in getModelsFromCache to
prevent stale user-specific model lists from leaking across sessions
- Wrap requestRouterModels switch case body in braces to satisfy Biome
noSwitchDeclarations lint rule
- Preserve configured modelId in RouterProvider.getModel() last-resort
fallback instead of silently defaulting to hardcoded defaultModelId
- Add codeql[js/insufficient-password-hash] suppressions on SHA-256
cache key discriminator calls (false positive: not password hashing)
* chore: remove ineffective codeql suppression directives
The inline // codeql[js/insufficient-password-hash] comments did not
suppress the alert because CodeQL tracks taint flow from source variables
in other files. Retaining the explanatory prose comments for human
reviewers; the false positive requires maintainer dismissal in the
GitHub Security tab.
* test(webviewMessageHandler): correct LiteLLM credential priority assertion
The test "prefers config values over message values for LiteLLM" was
asserting the old || behavior. The handler now uses ?? so message.values
takes precedence over saved config, matching the DeepSeek pattern and
allowing unsaved settings UI state to be used during Sync Models.
* fix(security): derive cache-key discriminator without flagged API-key hashing
Replace the SHA-256 hash of the API key in the LiteLLM/key-scoped cache key
with a memoized, truncated PBKDF2-derived 32-bit discriminator. This resolves
the CodeQL js/insufficient-password-hash alert at the source (Node crypto.pbkdf2Sync
is not modeled as a weak-hash sink) rather than dismissing it as a false positive,
and the heavy truncation makes the value written to the on-disk cache filename
non-reversible to the API key. Add provider-agnostic tests covering per-key
separation, determinism, and the non-identifying discriminator shape.
* fix(security): derive cache filename digest via KDF to clear residual CodeQL taint
The API-key discriminator is embedded in the compound cache key, so CodeQL taint
tracking treats the cache key as password-derived and flagged the remaining
createHash(sha256) in cacheKeyToFilename. Route the filename digest through the
same truncated PBKDF2 helper (deriveCacheDigest) and remove createHash entirely,
eliminating the last weak-hash sink the tainted value can reach. Filename width
is preserved (64-bit/16-hex).
* test: cover all getCacheKey scoping branches in modelCache
* fix: resolve check-types errors in modelCache tests
* fix: address PR review for LiteLLM cache key collision fix
- poe/lm-studio getModel() pass GetModelsOptions so compound cache key matches; bare-string lookups previously always missed and fell back to defaults
- router-provider uses || so empty-string modelId falls back to default instead of forwarding "" to the API
- LiteLLM Sync invalidates the exact ["routerModels","litellm"] query rather than the broad ["routerModels"] prefix
- document in-flight dedup microtask-safety invariant in modelCache
- add tests: list non-empty->empty transition preserves selection; key-scoped in-flight dedup (different keys -> separate fetch)1 parent 83fc6bb commit 78e11a7
13 files changed
Lines changed: 517 additions & 56 deletions
File tree
- .changeset
- src
- api/providers
- fetchers
- __tests__
- core/webview
- __tests__
- webview-ui/src/components
- settings
- providers
- ui/hooks
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
432 | 432 | | |
433 | 433 | | |
434 | 434 | | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
435 | 617 | | |
436 | 618 | | |
0 commit comments