fix: Flatpak provider auth and provider UI #5

Merged
BlackHatMagic merged 9 commits from fix/provider-ui-followup into master 2026-10-25 07:16:08 +00:00

PR Type Selection

  • 🐛 Bug Fix - Fixing incorrect behavior

Problem

On silverquill, Pi works from the terminal but the Obsidian plugin fails with API key auth failed for provider proxy: authHeader requires a resolved API key.

Root cause: Obsidian is a Flatpak. Flatpak sets XDG_STATE_HOME to ~/.var/app/md.obsidian.Obsidian/.local/state, so the provider-proxy extension looks for its token there. Terminal Pi uses ~/.local/state/provider-proxy/token. The plugin inherited the sandbox state path, so Pi registered proxy with an empty key.

The provider panel also only listed auth.json/models.json, missing extension providers like proxy; endpoints were not editable; and model IDs had to be typed as a comma-separated list.

Fix

  • Map Flatpak-style XDG_STATE_HOME back to ~/.local/state for the Pi child. This lets Pi use its own extension auth exactly as terminal Pi does.
  • Show the providers/models Pi actually reports (including proxy) in Settings. Extension-owned providers are read-only.
  • Add Edit for compatible endpoints, with prefilled fields.
  • Remove the manual comma-separated model field. Fetch model IDs from the provider's /models endpoint, with bearer, x-api-key (Anthropic), or x-goog-api-key (Google) auth.
  • Save uses the discovered list; an existing endpoint can be reopened and refreshed.

Testing

  • Added tests for Flatpak XDG_STATE_HOME mapping and provider model discovery.
  • bun run check: 35 tests pass.
  • bun run build: passes.
  • Verified on silverquill that the host token exists at ~/.local/state/provider-proxy/token and is readable inside the Flatpak sandbox; only the redirected state path caused the mismatch.

Additional Notes

OAuth still uses Pi's /login; this PR does not reimplement provider auth. Version 0.4.0.

## PR Type Selection - [x] 🐛 **Bug Fix** - Fixing incorrect behavior ## Problem On silverquill, Pi works from the terminal but the Obsidian plugin fails with `API key auth failed for provider proxy: authHeader requires a resolved API key`. Root cause: Obsidian is a Flatpak. Flatpak sets `XDG_STATE_HOME` to `~/.var/app/md.obsidian.Obsidian/.local/state`, so the provider-proxy extension looks for its token there. Terminal Pi uses `~/.local/state/provider-proxy/token`. The plugin inherited the sandbox state path, so Pi registered `proxy` with an empty key. The provider panel also only listed `auth.json`/`models.json`, missing extension providers like `proxy`; endpoints were not editable; and model IDs had to be typed as a comma-separated list. ## Fix - Map Flatpak-style `XDG_STATE_HOME` back to `~/.local/state` for the Pi child. This lets Pi use its own extension auth exactly as terminal Pi does. - Show the providers/models Pi actually reports (including `proxy`) in Settings. Extension-owned providers are read-only. - Add **Edit** for compatible endpoints, with prefilled fields. - Remove the manual comma-separated model field. Fetch model IDs from the provider's `/models` endpoint, with bearer, `x-api-key` (Anthropic), or `x-goog-api-key` (Google) auth. - Save uses the discovered list; an existing endpoint can be reopened and refreshed. ## Testing - Added tests for Flatpak `XDG_STATE_HOME` mapping and provider model discovery. - `bun run check`: **35 tests** pass. - `bun run build`: passes. - Verified on silverquill that the host token exists at `~/.local/state/provider-proxy/token` and is readable inside the Flatpak sandbox; only the redirected state path caused the mismatch. ## Additional Notes OAuth still uses Pi's `/login`; this PR does not reimplement provider auth. Version 0.4.0.
- Map Flatpak's redirected XDG_STATE_HOME back to ~/.local/state so
  provider-proxy finds its token exactly as terminal Pi does.
- Show the providers and models Pi actually reports, including extension
  providers such as proxy.
- Allow editing existing compatible endpoints.
- Fetch model IDs from the provider's /models endpoint instead of requiring
  a comma-separated list.
Code-Reviewer left a comment

Pi code review

2 new actionable findings

  • [P2] Google model discovery discards native ListModels responses — src/provider-store.ts:276
  • [P2] Renderer CORS restrictions block adding otherwise usable endpoints — src/provider-store.ts:268

Merged the candidate reviews against the pinned head and base, retaining two distinct model-discovery defects and deduplicating the Google-response finding. Verification was read-only and static; no tests, builds, or Obsidian/Flatpak runtime checks were run.

Change walkthrough
Area Files Changes
Other code (6) src/launcher.ts, src/main.ts, src/provider-store.ts, src/settings.ts (+2 more) Maps Flatpak-style XDG_STATE_HOME to ~/.local/state for the Pi child. Exposes the active Pi session's provider and model catalog to Settings. Adds stored-key lookup and authenticated /models discovery. Adds provider visibility and endpoint editing, replacing manual model IDs with discovery.
Tests (2) tests/launcher.test.ts, tests/provider-store.test.ts Adds coverage for Flatpak state-directory mapping. Adds OpenAI-compatible model-discovery coverage.
Documentation (1) README.md Documents provider visibility, endpoint editing, and fetched model lists.
Deployment & tooling (1) package.json Bumps the package version to 0.4.0.

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 10 files, +161/-21.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed 91a7a78003df6dbf37a988048871ed820b38e81b with proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol. Automated advisory review; no project commands or tests were executed.

<!-- forgejo-pi-review:82ec79d4fe453a6b0ff2ae56ace71911a25fba64b18c89423b613b239d4c2cd7 --> ## Pi code review **2 new actionable findings** - **[P2] Google model discovery discards native ListModels responses** — `src/provider-store.ts:276` - **[P2] Renderer CORS restrictions block adding otherwise usable endpoints** — `src/provider-store.ts:268` Merged the candidate reviews against the pinned head and base, retaining two distinct model-discovery defects and deduplicating the Google-response finding. Verification was read-only and static; no tests, builds, or Obsidian/Flatpak runtime checks were run. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Other code (6) | `src/launcher.ts`, `src/main.ts`, `src/provider-store.ts`, `src/settings.ts` (+2 more) | Maps Flatpak-style XDG_STATE_HOME to ~/.local/state for the Pi child. Exposes the active Pi session's provider and model catalog to Settings. Adds stored-key lookup and authenticated /models discovery. Adds provider visibility and endpoint editing, replacing manual model IDs with discovery. | | Tests (2) | `tests/launcher.test.ts`, `tests/provider-store.test.ts` | Adds coverage for Flatpak state-directory mapping. Adds OpenAI-compatible model-discovery coverage. | | Documentation (1) | `README.md` | Documents provider visibility, endpoint editing, and fetched model lists. | | Deployment & tooling (1) | `package.json` | Bumps the package version to 0.4.0. | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 10 files, +161/-21. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `91a7a78003df6dbf37a988048871ed820b38e81b` with `proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol`. Automated advisory review; no project commands or tests were executed.
@ -249,0 +265,4 @@
headers.authorization = `Bearer ${key.trim()}`;
}
}
const response = await fetch(url, { headers, signal: AbortSignal.timeout(15_000) });
Collaborator

[P2] Renderer CORS restrictions block adding otherwise usable endpoints

[Quality] Model discovery uses the Obsidian renderer's global fetch, requiring the provider to allow Obsidian's origin through CORS. An endpoint usable by the Pi CLI can therefore fail discovery in Settings. Since discovery is now mandatory for new endpoints, this prevents saving those endpoints rather than merely disabling an optional refresh.

Trigger: Add an OpenAI-compatible endpoint whose /models response does not allow Obsidian's renderer origin through CORS, then click Fetch models or Add endpoint.

Impact: Users cannot configure an otherwise working local or remote Pi endpoint through Settings; the previous manual-model workflow did not impose browser-origin access requirements.

Evidence: src/provider-store.ts:268 calls unqualified global fetch without importing a Node HTTP implementation or using Obsidian's CORS-independent request API. src/settings.ts imports discoverModels directly into PluginSettingTab and awaits it before saving whenever a new endpoint's customModels array is empty. The catch handler only displays a notice, and the former manual model input is gone. The added Bun test exercises server-side fetch, not the deployed renderer's CORS behavior.

**[P2] Renderer CORS restrictions block adding otherwise usable endpoints** [Quality] Model discovery uses the Obsidian renderer's global fetch, requiring the provider to allow Obsidian's origin through CORS. An endpoint usable by the Pi CLI can therefore fail discovery in Settings. Since discovery is now mandatory for new endpoints, this prevents saving those endpoints rather than merely disabling an optional refresh. **Trigger:** Add an OpenAI-compatible endpoint whose /models response does not allow Obsidian's renderer origin through CORS, then click Fetch models or Add endpoint. **Impact:** Users cannot configure an otherwise working local or remote Pi endpoint through Settings; the previous manual-model workflow did not impose browser-origin access requirements. **Evidence:** src/provider-store.ts:268 calls unqualified global fetch without importing a Node HTTP implementation or using Obsidian's CORS-independent request API. src/settings.ts imports discoverModels directly into PluginSettingTab and awaits it before saving whenever a new endpoint's customModels array is empty. The catch handler only displays a notice, and the former manual model input is gone. The added Bun test exercises server-side fetch, not the deployed renderer's CORS behavior.
@ -249,0 +273,4 @@
: [];
const ids = entries.flatMap((entry) => {
if (typeof entry === "string") return [entry];
if (typeof entry === "object" && entry !== null && "id" in entry && typeof entry.id === "string") return [entry.id];
Collaborator

[P2] Google model discovery discards native ListModels responses

[Compliance/Quality] Google's ListModels response identifies models with a name such as "models/gemini-…", not an id. Although discovery accepts the top-level models array and supplies Google's authentication header, it discards every native Google entry and throws "Provider returned no model IDs." Removing manual model entry makes this failure block adding these endpoints.

Trigger: Select google-generative-ai with a valid key and a Google Generative Language API base URL such as https://generativelanguage.googleapis.com/v1beta, then click Fetch models or Add endpoint, assuming the request succeeds.

Impact: Users cannot add endpoints using Google's native model-list format through Settings, and existing Google endpoints cannot refresh their model catalog.

Evidence: src/provider-store.ts:271-280 accepts payload.models but retains only bare strings or objects with a string id; Google's name-only entries produce an empty list and reach the throwing guard. In src/settings.ts, new endpoints initialize customModels to an empty array, and the save handler awaits fetchCustomModels before saveCustomProvider. At the base commit, the form accepted manually entered model IDs without requiring discovery.

**[P2] Google model discovery discards native ListModels responses** [Compliance/Quality] Google's ListModels response identifies models with a name such as "models/gemini-…", not an id. Although discovery accepts the top-level models array and supplies Google's authentication header, it discards every native Google entry and throws "Provider returned no model IDs." Removing manual model entry makes this failure block adding these endpoints. **Trigger:** Select google-generative-ai with a valid key and a Google Generative Language API base URL such as https://generativelanguage.googleapis.com/v1beta, then click Fetch models or Add endpoint, assuming the request succeeds. **Impact:** Users cannot add endpoints using Google's native model-list format through Settings, and existing Google endpoints cannot refresh their model catalog. **Evidence:** src/provider-store.ts:271-280 accepts payload.models but retains only bare strings or objects with a string id; Google's name-only entries produce an empty list and reach the throwing guard. In src/settings.ts, new endpoints initialize customModels to an empty array, and the save handler awaits fetchCustomModels before saveCustomProvider. At the base commit, the form accepted manually entered model IDs without requiring discovery.
Code-Reviewer left a comment

Pi code review

3 new actionable findings

  • [P1] Model-list redirects forward credentials across origins — src/provider-store.ts:266
  • [P2] Adding an endpoint ignores its already-saved API key — src/settings.ts:243
  • [P2] Changing the endpoint URL retains the previous server's models — src/settings.ts:284
Earlier findings: 2 rechecked
  • Resolved: Renderer CORS restrictions block adding otherwise usable endpoints (src/provider-store.ts:268, first reported in review #313) — Current src/provider-store.ts imports node:http and node:https at lines 1-2, uses their request implementations in requestJson, and calls requestJson from discoverModels at line 310. Discovery no longer uses renderer fetch, removing the reported renderer-CORS dependency; Obsidian runtime behavior was not exercised.
  • Resolved: Google model discovery discards native ListModels responses (src/provider-store.ts:276, first reported in review #313) — Current src/provider-store.ts:317 accepts entries with a string name and strips the models/ prefix, so native Google ListModels entries are no longer discarded. tests/provider-store.test.ts includes a name-only Google response and expects the corresponding unprefixed model IDs; the test was inspected but not run.

Merged the candidate reviews of head 432e6ca against base 70c11315, verifying the provider-discovery and Settings findings against current code and rechecking both previous findings. This was a read-only static review; no tests, builds, or Obsidian/Flatpak runtime checks were run.

Change walkthrough
Area Files Changes
Documentation (1) README.md Documents endpoint editing, automatic model discovery, and read-only extension providers.
Other code (6) manifest.json, src/launcher.ts, src/main.ts, src/provider-store.ts (+2 more) Bumps the plugin version to 0.4.0. Maps Flatpak-style XDG_STATE_HOME to the host state directory for the Pi child. Exposes providers grouped from Pi's available model catalog. Adds stored-key lookup and authenticated model discovery using Node HTTP.
Deployment & tooling (1) package.json Bumps the package version to 0.4.0.
Tests (2) tests/launcher.test.ts, tests/provider-store.test.ts Adds coverage for Flatpak state-directory mapping. Adds OpenAI-compatible and Google model-discovery tests.

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 10 files, +217/-21.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed 432e6ca00ed83d3dcbd59d3e0ae5a410eabd3f70 with proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol. Automated advisory review; no project commands or tests were executed.

<!-- forgejo-pi-review:af9c5afe489c19c0ad161918addc9848ed3ffbc9b2e0440e23190a9766d273b0 --> ## Pi code review **3 new actionable findings** - **[P1] Model-list redirects forward credentials across origins** — `src/provider-store.ts:266` - **[P2] Adding an endpoint ignores its already-saved API key** — `src/settings.ts:243` - **[P2] Changing the endpoint URL retains the previous server's models** — `src/settings.ts:284` <details> <summary>Earlier findings: 2 rechecked</summary> - **Resolved:** Renderer CORS restrictions block adding otherwise usable endpoints (`src/provider-store.ts:268`, first reported in review #313) — Current src/provider-store.ts imports node:http and node:https at lines 1-2, uses their request implementations in requestJson, and calls requestJson from discoverModels at line 310. Discovery no longer uses renderer fetch, removing the reported renderer-CORS dependency; Obsidian runtime behavior was not exercised. - **Resolved:** Google model discovery discards native ListModels responses (`src/provider-store.ts:276`, first reported in review #313) — Current src/provider-store.ts:317 accepts entries with a string name and strips the models/ prefix, so native Google ListModels entries are no longer discarded. tests/provider-store.test.ts includes a name-only Google response and expects the corresponding unprefixed model IDs; the test was inspected but not run. </details> Merged the candidate reviews of head 432e6ca against base 70c11315, verifying the provider-discovery and Settings findings against current code and rechecking both previous findings. This was a read-only static review; no tests, builds, or Obsidian/Flatpak runtime checks were run. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Documentation (1) | `README.md` | Documents endpoint editing, automatic model discovery, and read-only extension providers. | | Other code (6) | `manifest.json`, `src/launcher.ts`, `src/main.ts`, `src/provider-store.ts` (+2 more) | Bumps the plugin version to 0.4.0. Maps Flatpak-style XDG_STATE_HOME to the host state directory for the Pi child. Exposes providers grouped from Pi's available model catalog. Adds stored-key lookup and authenticated model discovery using Node HTTP. | | Deployment & tooling (1) | `package.json` | Bumps the package version to 0.4.0. | | Tests (2) | `tests/launcher.test.ts`, `tests/provider-store.test.ts` | Adds coverage for Flatpak state-directory mapping. Adds OpenAI-compatible and Google model-discovery tests. | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 10 files, +217/-21. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `432e6ca00ed83d3dcbd59d3e0ae5a410eabd3f70` with `proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol`. Automated advisory review; no project commands or tests were executed.
@ -249,0 +263,4 @@
if (status >= 300 && status < 400 && response.headers.location && redirects < 5) {
response.resume();
const next = new URL(response.headers.location, parsed).toString();
requestJson(next, headers, redirects + 1).then(resolve, reject);
Collaborator

[P1] Model-list redirects forward credentials across origins

[Quality/Security] Redirect handling forwards all authentication headers to the redirect destination without checking its origin or preventing an HTTPS-to-HTTP downgrade. Fetching a model list can therefore disclose the provider's API key to another service or transmit it in plaintext.

Trigger: Click Fetch models or Add endpoint for an authenticated endpoint whose /models response redirects to a different origin or from HTTPS to HTTP.

Impact: The redirected service receives the provider credential, potentially enabling unauthorized API usage and charges; an HTTP downgrade also exposes it to network observers.

Evidence: src/provider-store.ts:263-266 resolves Location and calls requestJson(next, headers, redirects + 1), preserving the complete header object. discoverModels at lines 300-307 populates authorization, x-api-key, or x-goog-api-key, and the Settings caller invokes it directly. The redirect-count limit does not restrict destination origins or transport security. The base implementation made no model-discovery requests.

**[P1] Model-list redirects forward credentials across origins** [Quality/Security] Redirect handling forwards all authentication headers to the redirect destination without checking its origin or preventing an HTTPS-to-HTTP downgrade. Fetching a model list can therefore disclose the provider's API key to another service or transmit it in plaintext. **Trigger:** Click Fetch models or Add endpoint for an authenticated endpoint whose /models response redirects to a different origin or from HTTPS to HTTP. **Impact:** The redirected service receives the provider credential, potentially enabling unauthorized API usage and charges; an HTTP downgrade also exposes it to network observers. **Evidence:** src/provider-store.ts:263-266 resolves Location and calls requestJson(next, headers, redirects + 1), preserving the complete header object. discoverModels at lines 300-307 populates authorization, x-api-key, or x-goog-api-key, and the Settings caller invokes it directly. The redirect-count limit does not restrict destination origins or transport security. The base implementation made no model-discovery requests.
src/settings.ts Outdated
@ -211,0 +240,4 @@
cls: "pi-chat-diagnostics-note",
});
const fetchCustomModels = async (): Promise<string[]> => {
const key = customKey.trim() || (editing ? await storedApiKey(state.agentDir, editing.id) ?? "" : "");
Collaborator

[P2] Adding an endpoint ignores its already-saved API key

[Quality] Model discovery only falls back to the saved credential when editing an existing endpoint. If a user saves a provider's API key first and then adds its endpoint with the key field blank, discovery sends no authentication and blocks saving despite the credential already being present.

Trigger: Save a literal API key using Add or update an API key, then add an authenticated compatible endpoint with the same provider ID while leaving the endpoint's API key field blank.

Impact: The endpoint cannot be added through this workflow because mandatory discovery fails authentication; the user must supply the same credential again.

Evidence: src/settings.ts:243 calls storedApiKey only when editing is non-null, so a new endpoint uses an empty key regardless of customId's saved credential. New endpoints start with an empty customModels array, and line 284 requires discovery to succeed before saveCustomProvider runs. The separate Save API key action writes auth.json through saveApiKey. At base, saving an endpoint accepted manually supplied model IDs without requiring an authenticated discovery request.

**[P2] Adding an endpoint ignores its already-saved API key** [Quality] Model discovery only falls back to the saved credential when editing an existing endpoint. If a user saves a provider's API key first and then adds its endpoint with the key field blank, discovery sends no authentication and blocks saving despite the credential already being present. **Trigger:** Save a literal API key using Add or update an API key, then add an authenticated compatible endpoint with the same provider ID while leaving the endpoint's API key field blank. **Impact:** The endpoint cannot be added through this workflow because mandatory discovery fails authentication; the user must supply the same credential again. **Evidence:** src/settings.ts:243 calls storedApiKey only when editing is non-null, so a new endpoint uses an empty key regardless of customId's saved credential. New endpoints start with an empty customModels array, and line 284 requires discovery to succeed before saveCustomProvider runs. The separate Save API key action writes auth.json through saveApiKey. At base, saving an endpoint accepted manually supplied model IDs without requiring an authenticated discovery request.
@ -237,0 +281,4 @@
}))
.addButton((button) => button.setButtonText(editing ? "Save endpoint" : "Add endpoint").setCta().onClick(async () => {
try {
const models = customModels.length ? customModels : await fetchCustomModels();
Collaborator

[P2] Changing the endpoint URL retains the previous server's models

[Quality] The discovered model list is cached independently of the endpoint fields. Changing the base URL after fetching models, or while editing an existing endpoint, leaves the old list intact, and Save associates it with the new server without fetching that server's catalog.

Trigger: Fetch models from endpoint A, change the Base URL to endpoint B with different model IDs, and click Add endpoint; alternatively, edit an existing endpoint's URL and click Save endpoint without explicitly fetching again.

Impact: Pi's models.json contains model IDs unavailable at the saved endpoint, causing those model selections to fail until the user refreshes and saves the catalog.

Evidence: src/settings.ts:237 prepopulates customModels when editing, and fetchCustomModels replaces it with discovery results. The Base URL handler at line 257 updates only customUrl, while line 284 skips discovery whenever customModels is nonempty. saveCustomProvider persists those IDs with the changed baseUrl, validating only that the list is nonempty. The base form required explicit model entry rather than automatically reusing a previously discovered catalog.

**[P2] Changing the endpoint URL retains the previous server's models** [Quality] The discovered model list is cached independently of the endpoint fields. Changing the base URL after fetching models, or while editing an existing endpoint, leaves the old list intact, and Save associates it with the new server without fetching that server's catalog. **Trigger:** Fetch models from endpoint A, change the Base URL to endpoint B with different model IDs, and click Add endpoint; alternatively, edit an existing endpoint's URL and click Save endpoint without explicitly fetching again. **Impact:** Pi's models.json contains model IDs unavailable at the saved endpoint, causing those model selections to fail until the user refreshes and saves the catalog. **Evidence:** src/settings.ts:237 prepopulates customModels when editing, and fetchCustomModels replaces it with discovery results. The Base URL handler at line 257 updates only customUrl, while line 284 skips discovery whenever customModels is nonempty. saveCustomProvider persists those IDs with the changed baseUrl, validating only that the list is nonempty. The base form required explicit model entry rather than automatically reusing a previously discovered catalog.
Code-Reviewer left a comment

Pi code review

1 new actionable finding

  • [P2] Endpoint discovery ignores credentials stored in models.json — src/provider-store.ts:252
Earlier findings: 3 rechecked
  • Still open (not reposted): Changing the endpoint URL retains the previous server's models (src/settings.ts:284, first reported in review #314) — src/settings.ts:242-261 now clears cached models when endpoint fields change, fixing changes made after discovery completes. However, lines 248-249 still publish an in-flight request's results unconditionally after such a change, and lines 288-296 can save that stale catalog with the new endpoint URL, producing unavailable model selections. The finding is updated to this remaining trigger.
  • Resolved: Adding an endpoint ignores its already-saved API key (src/settings.ts:243, first reported in review #314) — src/settings.ts:247 now calls storedApiKey(state.agentDir, editing?.id ?? customId), so adding a new endpoint with a blank key falls back to its provider ID's saved literal auth.json credential even when editing is null.
  • Resolved: Model-list redirects forward credentials across origins (src/provider-store.ts:266, first reported in review #314) — src/provider-store.ts:270-278 rejects redirects whose host, including port, differs and rejects HTTPS-to-non-HTTPS redirects before recursively forwarding authentication headers. This blocks the previously reported cross-host disclosure and HTTPS downgrade paths; the added cross-host rejection test was inspected but not run.

Merged the candidate reviews of the Flatpak environment fix, provider settings, endpoint editing, and model discovery against base 70c11315 and head 8b1d0f39, retaining two evidence-supported defects and rechecking all three previous findings. Verification was limited to repository inspection; no tests, builds, or live Flatpak/provider checks were run.

Change walkthrough
Area Files Changes
Other code (6) src/launcher.ts, src/main.ts, src/provider-store.ts, src/settings.ts (+2 more) Maps Flatpak-style XDG_STATE_HOME to the host's default state directory for Pi. Exposes providers and model names from the loaded Pi catalog. Adds stored credential lookup and authenticated model discovery with redirect restrictions. Displays Pi's provider catalog and adds endpoint editing and model discovery.
Tests (2) tests/launcher.test.ts, tests/provider-store.test.ts Adds coverage for Flatpak state-directory mapping. Adds model discovery and cross-host redirect rejection tests.
Documentation (1) README.md Documents model discovery, endpoint editing, and read-only extension providers.
Deployment & tooling (1) package.json Updates the package version to 0.4.0.

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 10 files, +250/-23.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed 8b1d0f39bfe0a35c3c399509749df1e96b7195fd with proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol. Automated advisory review; no project commands or tests were executed.

<!-- forgejo-pi-review:03aea24e98bc857c91ee4f7782b3d2d937e926f31769c2da1b79826fa51eb195 --> ## Pi code review **1 new actionable finding** - **[P2] Endpoint discovery ignores credentials stored in models.json** — `src/provider-store.ts:252` <details> <summary>Earlier findings: 3 rechecked</summary> - **Still open (not reposted):** Changing the endpoint URL retains the previous server's models (`src/settings.ts:284`, first reported in review #314) — src/settings.ts:242-261 now clears cached models when endpoint fields change, fixing changes made after discovery completes. However, lines 248-249 still publish an in-flight request's results unconditionally after such a change, and lines 288-296 can save that stale catalog with the new endpoint URL, producing unavailable model selections. The finding is updated to this remaining trigger. - **Resolved:** Adding an endpoint ignores its already-saved API key (`src/settings.ts:243`, first reported in review #314) — src/settings.ts:247 now calls storedApiKey(state.agentDir, editing?.id ?? customId), so adding a new endpoint with a blank key falls back to its provider ID's saved literal auth.json credential even when editing is null. - **Resolved:** Model-list redirects forward credentials across origins (`src/provider-store.ts:266`, first reported in review #314) — src/provider-store.ts:270-278 rejects redirects whose host, including port, differs and rejects HTTPS-to-non-HTTPS redirects before recursively forwarding authentication headers. This blocks the previously reported cross-host disclosure and HTTPS downgrade paths; the added cross-host rejection test was inspected but not run. </details> Merged the candidate reviews of the Flatpak environment fix, provider settings, endpoint editing, and model discovery against base 70c11315 and head 8b1d0f39, retaining two evidence-supported defects and rechecking all three previous findings. Verification was limited to repository inspection; no tests, builds, or live Flatpak/provider checks were run. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Other code (6) | `src/launcher.ts`, `src/main.ts`, `src/provider-store.ts`, `src/settings.ts` (+2 more) | Maps Flatpak-style XDG_STATE_HOME to the host's default state directory for Pi. Exposes providers and model names from the loaded Pi catalog. Adds stored credential lookup and authenticated model discovery with redirect restrictions. Displays Pi's provider catalog and adds endpoint editing and model discovery. | | Tests (2) | `tests/launcher.test.ts`, `tests/provider-store.test.ts` | Adds coverage for Flatpak state-directory mapping. Adds model discovery and cross-host redirect rejection tests. | | Documentation (1) | `README.md` | Documents model discovery, endpoint editing, and read-only extension providers. | | Deployment & tooling (1) | `package.json` | Updates the package version to 0.4.0. | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 10 files, +250/-23. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `8b1d0f39bfe0a35c3c399509749df1e96b7195fd` with `proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol`. Automated advisory review; no project commands or tests were executed.
@ -247,2 +249,4 @@
}
export async function storedApiKey(agentDir: string, providerId: string): Promise<string | undefined> {
const auth = await readJson<Record<string, StoredCredential>>(join(agentDir, "auth.json"), {});
Collaborator

[P2] Endpoint discovery ignores credentials stored in models.json

[Quality] Editing an existing endpoint with a blank key promises to keep its saved credential, but discovery only looks in auth.json. An authenticated endpoint whose apiKey is configured in models.json cannot refresh its catalog without the user supplying the credential again.

Trigger: Edit an existing compatible endpoint with a literal apiKey in models.json and no corresponding auth.json entry, leave API key blank, and click Fetch models. Changing its Base URL also makes Save require discovery.

Impact: Catalog refresh fails authentication, and endpoint URL changes cannot be saved through the advertised keep-saved-key workflow despite the endpoint already having valid credentials.

Evidence: src/settings.ts:247 resolves a blank key exclusively through storedApiKey, whose implementation at src/provider-store.ts:251-255 reads only auth.json. readProviderState omits models.json's apiKey from the editing state, while saveCustomProvider preserves an existing string provider.apiKey, demonstrating support for that credential location. discoverModels sends no authentication when the lookup returns empty. At base, endpoint updates accepted manually supplied model IDs and preserved the existing apiKey without requiring discovery.

**[P2] Endpoint discovery ignores credentials stored in models.json** [Quality] Editing an existing endpoint with a blank key promises to keep its saved credential, but discovery only looks in auth.json. An authenticated endpoint whose apiKey is configured in models.json cannot refresh its catalog without the user supplying the credential again. **Trigger:** Edit an existing compatible endpoint with a literal apiKey in models.json and no corresponding auth.json entry, leave API key blank, and click Fetch models. Changing its Base URL also makes Save require discovery. **Impact:** Catalog refresh fails authentication, and endpoint URL changes cannot be saved through the advertised keep-saved-key workflow despite the endpoint already having valid credentials. **Evidence:** src/settings.ts:247 resolves a blank key exclusively through storedApiKey, whose implementation at src/provider-store.ts:251-255 reads only auth.json. readProviderState omits models.json's apiKey from the editing state, while saveCustomProvider preserves an existing string provider.apiKey, demonstrating support for that credential location. discoverModels sends no authentication when the lookup returns empty. At base, endpoint updates accepted manually supplied model IDs and preserved the existing apiKey without requiring discovery.
Code-Reviewer left a comment

Pi code review

2 new actionable findings

  • [P2] Mandatory discovery blocks command-backed endpoint credentials — src/provider-store.ts:254
  • [P2] Anthropic discovery omits the required version path — src/provider-store.ts:318
Earlier findings: 2 rechecked
  • Resolved: In-flight discovery can restore models from the previous endpoint (src/settings.ts:249, first reported in review #314) — Current src/settings.ts:244-248 increments discoveryGeneration and clears cached models on field changes. fetchCustomModels captures the generation at line 250 and checks it at lines 256-258 after discovery, throwing before assigning or returning models when the fields changed. The reported stale-response sequence can no longer repopulate the cache or continue the awaiting save.
  • Resolved: Endpoint discovery ignores credentials stored in models.json (src/provider-store.ts:252, first reported in review #315) — Current src/settings.ts:252-254 falls back from the entered key and storedApiKey to storedEndpointKey. Current src/provider-store.ts:309-315 reads models.providers[providerId].apiKey and returns a saved literal credential, fixing the reported discovery failure for models.json-only literal keys.

Aggregated the three candidate reviews of head 6e8d7a6 against base 70c1131, verifying the supported findings and both previous findings against repository code. Verification was read-only; tests, typechecking, builds, and live Pi/Obsidian/Flatpak behavior were not run.

Change walkthrough
Area Files Changes
Documentation (1) README.md Document endpoint editing, model discovery, and read-only extension-provider display.
Other code (6) manifest.json, src/launcher.ts, src/main.ts, src/provider-store.ts (+2 more) Bump the plugin version to 0.4.0. Map Flatpak-style XDG_STATE_HOME to the host's default state directory for Pi. Expose Pi's loaded provider and model catalog to settings. Add stored-credential lookup and authenticated HTTP model discovery with redirect restrictions.
Deployment & tooling (1) package.json Bump the package version to 0.4.0.
Tests (2) tests/launcher.test.ts, tests/provider-store.test.ts Add coverage for Flatpak state-directory mapping. Add OpenAI/Google model-discovery and cross-host redirect tests.

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 10 files, +268/-23.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed 6e8d7a6715354fb3b94ced7e5c02198e0953c4d0 with proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol. Automated advisory review; no project commands or tests were executed.

<!-- forgejo-pi-review:3444a21de4a1d1ab4526a39b1e40c018062de755c92bb242924a90cec7086c21 --> ## Pi code review **2 new actionable findings** - **[P2] Mandatory discovery blocks command-backed endpoint credentials** — `src/provider-store.ts:254` - **[P2] Anthropic discovery omits the required version path** — `src/provider-store.ts:318` <details> <summary>Earlier findings: 2 rechecked</summary> - **Resolved:** In-flight discovery can restore models from the previous endpoint (`src/settings.ts:249`, first reported in review #314) — Current src/settings.ts:244-248 increments discoveryGeneration and clears cached models on field changes. fetchCustomModels captures the generation at line 250 and checks it at lines 256-258 after discovery, throwing before assigning or returning models when the fields changed. The reported stale-response sequence can no longer repopulate the cache or continue the awaiting save. - **Resolved:** Endpoint discovery ignores credentials stored in models.json (`src/provider-store.ts:252`, first reported in review #315) — Current src/settings.ts:252-254 falls back from the entered key and storedApiKey to storedEndpointKey. Current src/provider-store.ts:309-315 reads models.providers[providerId].apiKey and returns a saved literal credential, fixing the reported discovery failure for models.json-only literal keys. </details> Aggregated the three candidate reviews of head 6e8d7a6 against base 70c1131, verifying the supported findings and both previous findings against repository code. Verification was read-only; tests, typechecking, builds, and live Pi/Obsidian/Flatpak behavior were not run. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Documentation (1) | `README.md` | Document endpoint editing, model discovery, and read-only extension-provider display. | | Other code (6) | `manifest.json`, `src/launcher.ts`, `src/main.ts`, `src/provider-store.ts` (+2 more) | Bump the plugin version to 0.4.0. Map Flatpak-style XDG_STATE_HOME to the host's default state directory for Pi. Expose Pi's loaded provider and model catalog to settings. Add stored-credential lookup and authenticated HTTP model discovery with redirect restrictions. | | Deployment & tooling (1) | `package.json` | Bump the package version to 0.4.0. | | Tests (2) | `tests/launcher.test.ts`, `tests/provider-store.test.ts` | Add coverage for Flatpak state-directory mapping. Add OpenAI/Google model-discovery and cross-host redirect tests. | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 10 files, +268/-23. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `6e8d7a6715354fb3b94ced7e5c02198e0953c4d0` with `proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol`. Automated advisory review; no project commands or tests were executed.
@ -249,0 +251,4 @@
export async function storedApiKey(agentDir: string, providerId: string): Promise<string | undefined> {
const auth = await readJson<Record<string, StoredCredential>>(join(agentDir, "auth.json"), {});
const key = auth[providerId]?.key;
return typeof key === "string" && !key.startsWith("!") ? key.trim() || undefined : undefined;
Collaborator

[P2] Mandatory discovery blocks command-backed endpoint credentials

[Quality] Endpoint saving now requires model discovery, but discovery discards saved command-backed credentials. Entering the command directly in the endpoint form instead sends the command text as the authentication header, so neither path authenticates successfully.

Trigger: Add an authenticated compatible endpoint using a command-backed key, or edit an existing endpoint with such a saved key and change its Base URL while leaving the key field blank.

Impact: Users relying on Pi's command-backed credentials cannot add or change authenticated endpoints through this form without extracting a literal secret or editing configuration outside the plugin.

Evidence: src/provider-store.ts:251-255 excludes auth.json keys beginning with '!'; storedEndpointKey at lines 309-315 also excludes command credentials. src/settings.ts:250-255 uses those helpers unless customKey is nonempty, which is passed directly to discoverModels and placed in an authentication header. Field changes clear customModels, and line 298 requires successful discovery before saving. The existing 'masks key commands without executing them' test establishes command credentials as a supported stored form; the base settings workflow saved manually supplied model IDs and passed the credential to Pi without making this HTTP request.

**[P2] Mandatory discovery blocks command-backed endpoint credentials** [Quality] Endpoint saving now requires model discovery, but discovery discards saved command-backed credentials. Entering the command directly in the endpoint form instead sends the command text as the authentication header, so neither path authenticates successfully. **Trigger:** Add an authenticated compatible endpoint using a command-backed key, or edit an existing endpoint with such a saved key and change its Base URL while leaving the key field blank. **Impact:** Users relying on Pi's command-backed credentials cannot add or change authenticated endpoints through this form without extracting a literal secret or editing configuration outside the plugin. **Evidence:** src/provider-store.ts:251-255 excludes auth.json keys beginning with '!'; storedEndpointKey at lines 309-315 also excludes command credentials. src/settings.ts:250-255 uses those helpers unless customKey is nonempty, which is passed directly to discoverModels and placed in an authentication header. Field changes clear customModels, and line 298 requires successful discovery before saving. The existing 'masks key commands without executing them' test establishes command credentials as a supported stored form; the base settings workflow saved manually supplied model IDs and passed the credential to Pi without making this HTTP request.
@ -249,0 +315,4 @@
}
export async function discoverModels(baseUrl: string, api: ProviderApi, key: string): Promise<string[]> {
const url = `${validateUrl(baseUrl)}/models`;
Collaborator

[P2] Anthropic discovery omits the required version path

[Quality] discoverModels appends '/models' uniformly, but an Anthropic SDK-style base URL is the origin without '/v1'. For the canonical Anthropic endpoint, discovery therefore requests https://api.anthropic.com/models instead of https://api.anthropic.com/v1/models, blocking the discovery-dependent save workflow.

Trigger: Select anthropic-messages with base URL https://api.anthropic.com and a valid key, then add the endpoint or change an existing endpoint field and save.

Impact: Adding a canonical Anthropic endpoint or saving changed endpoint fields fails because discovery requests the wrong route and there is no manual model-list fallback.

Evidence: src/provider-store.ts:318 constructs ${validateUrl(baseUrl)}/models without an Anthropic-specific path, although lines 322-325 supply Anthropic authentication headers. Anthropic's canonical model-list route is '/v1/models', while its SDK base URL omits '/v1'. src/settings.ts clears the model cache on field changes and line 298 awaits discovery when that cache is empty; requestJson rejects non-2xx responses. The base workflow accepted manually entered model IDs and did not require this route to succeed.

**[P2] Anthropic discovery omits the required version path** [Quality] discoverModels appends '/models' uniformly, but an Anthropic SDK-style base URL is the origin without '/v1'. For the canonical Anthropic endpoint, discovery therefore requests https://api.anthropic.com/models instead of https://api.anthropic.com/v1/models, blocking the discovery-dependent save workflow. **Trigger:** Select anthropic-messages with base URL https://api.anthropic.com and a valid key, then add the endpoint or change an existing endpoint field and save. **Impact:** Adding a canonical Anthropic endpoint or saving changed endpoint fields fails because discovery requests the wrong route and there is no manual model-list fallback. **Evidence:** src/provider-store.ts:318 constructs `${validateUrl(baseUrl)}/models` without an Anthropic-specific path, although lines 322-325 supply Anthropic authentication headers. Anthropic's canonical model-list route is '/v1/models', while its SDK base URL omits '/v1'. src/settings.ts clears the model cache on field changes and line 298 awaits discovery when that cache is empty; requestJson rejects non-2xx responses. The base workflow accepted manually entered model IDs and did not require this route to succeed.
Code-Reviewer left a comment

Pi code review

1 new actionable finding

  • [P2] Changing providers during credential resolution can disclose the previous provider's key — src/settings.ts:255
Earlier findings: 2 rechecked
  • Resolved: Anthropic discovery omits the required version path (src/provider-store.ts:318, first reported in review #316) — Current discoverModels in src/provider-store.ts constructs ${base}/v1/models for anthropic-messages unless the validated base already ends in /v1. A canonical https://api.anthropic.com base therefore reaches the required route, and the added Anthropic discovery test asserts the /v1/models path; the test was inspected but not run.
  • Resolved: Mandatory discovery blocks command-backed endpoint credentials (src/provider-store.ts:254, first reported in review #316) — Current resolveCredential in src/provider-store.ts executes !-prefixed commands and returns trimmed stdout. Both storedApiKey and storedEndpointKey use this resolver, and discoverModels also resolves directly entered credentials before constructing authentication headers, fixing the discarded or literal-command behavior. The added Anthropic test covers a directly entered command-backed key; it was inspected but not run.

Merged the candidate reviews for head 09838a4 against base 70c1131, verifying the credential-routing finding and both prior findings against current code. One new bug remains and both prior findings are resolved; verification was static only, with no tests, builds, or Flatpak runtime checks executed.

Change walkthrough
Area Files Changes
Other code (6) src/launcher.ts, src/main.ts, src/provider-store.ts, src/settings.ts (+2 more) Maps Flatpak-style XDG_STATE_HOME to ~/.local/state for the Pi child process. Groups Pi's reported models into a provider catalog for settings. Adds credential resolution and authenticated model discovery with redirect guards and Anthropic-specific routing. Displays Pi providers, adds endpoint editing, and replaces manual model entry with discovery.
Tests (2) tests/launcher.test.ts, tests/provider-store.test.ts Adds coverage for Flatpak state-directory mapping. Adds model discovery, command-backed authentication, and cross-host redirect tests.
Documentation (1) README.md Documents endpoint editing, model discovery, and read-only extension providers.
Deployment & tooling (1) package.json Bumps the package version to 0.4.0.

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 10 files, +302/-23.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed 09838a4261fe649efc7e4834ce41479319bf844d with proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol. Automated advisory review; no project commands or tests were executed.

<!-- forgejo-pi-review:753bef569f748bf80cdbaa16a2c52daaab621eb78e011727accd7f643d9921af --> ## Pi code review **1 new actionable finding** - **[P2] Changing providers during credential resolution can disclose the previous provider's key** — `src/settings.ts:255` <details> <summary>Earlier findings: 2 rechecked</summary> - **Resolved:** Anthropic discovery omits the required version path (`src/provider-store.ts:318`, first reported in review #316) — Current discoverModels in src/provider-store.ts constructs ${base}/v1/models for anthropic-messages unless the validated base already ends in /v1. A canonical https://api.anthropic.com base therefore reaches the required route, and the added Anthropic discovery test asserts the /v1/models path; the test was inspected but not run. - **Resolved:** Mandatory discovery blocks command-backed endpoint credentials (`src/provider-store.ts:254`, first reported in review #316) — Current resolveCredential in src/provider-store.ts executes !-prefixed commands and returns trimmed stdout. Both storedApiKey and storedEndpointKey use this resolver, and discoverModels also resolves directly entered credentials before constructing authentication headers, fixing the discarded or literal-command behavior. The added Anthropic test covers a directly entered command-backed key; it was inspected but not run. </details> Merged the candidate reviews for head 09838a4 against base 70c1131, verifying the credential-routing finding and both prior findings against current code. One new bug remains and both prior findings are resolved; verification was static only, with no tests, builds, or Flatpak runtime checks executed. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Other code (6) | `src/launcher.ts`, `src/main.ts`, `src/provider-store.ts`, `src/settings.ts` (+2 more) | Maps Flatpak-style XDG_STATE_HOME to ~/.local/state for the Pi child process. Groups Pi's reported models into a provider catalog for settings. Adds credential resolution and authenticated model discovery with redirect guards and Anthropic-specific routing. Displays Pi providers, adds endpoint editing, and replaces manual model entry with discovery. | | Tests (2) | `tests/launcher.test.ts`, `tests/provider-store.test.ts` | Adds coverage for Flatpak state-directory mapping. Adds model discovery, command-backed authentication, and cross-host redirect tests. | | Documentation (1) | `README.md` | Documents endpoint editing, model discovery, and read-only extension providers. | | Deployment & tooling (1) | `package.json` | Bumps the package version to 0.4.0. | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 10 files, +302/-23. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `09838a4261fe649efc7e4834ce41479319bf844d` with `proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol`. Automated advisory review; no project commands or tests were executed.
src/settings.ts Outdated
@ -211,0 +252,4 @@
const key = customKey.trim()
|| (await storedApiKey(state.agentDir, providerId) ?? "")
|| (await storedEndpointKey(state.agentDir, providerId) ?? "");
const models = await discoverModels(customUrl, customApi, key);
Collaborator

[P2] Changing providers during credential resolution can disclose the previous provider's key

[Quality] Model discovery captures the provider ID before awaiting credential resolution but reads the endpoint URL and API type afterward. Changing the form during that wait sends the original provider's resolved secret to the newly entered endpoint; the generation check rejects the result only after the authenticated request has completed.

Trigger: In the Add endpoint form, select a provider ID with a saved command-backed key that takes time to resolve, click Fetch models, then change the Provider ID and Base URL to another provider before resolution finishes.

Impact: The original provider's API key can be disclosed to an unrelated provider or local service even though the operation subsequently reports that the endpoint changed.

Evidence: src/settings.ts:249-255 captures providerId, awaits storedApiKey/storedEndpointKey, then calls discoverModels(customUrl, customApi, key) using mutable form values. The controls at lines 267-281 remain editable and only invalidate the model generation; the generation guard at lines 256-258 runs after discovery. src/provider-store.ts resolves command-backed credentials asynchronously with a 10-second timeout and attaches the resolved key to the supplied destination. Its redirect guard does not help because the changed URL is the initial destination. The base settings workflow did not issue a discovery request.

**[P2] Changing providers during credential resolution can disclose the previous provider's key** [Quality] Model discovery captures the provider ID before awaiting credential resolution but reads the endpoint URL and API type afterward. Changing the form during that wait sends the original provider's resolved secret to the newly entered endpoint; the generation check rejects the result only after the authenticated request has completed. **Trigger:** In the Add endpoint form, select a provider ID with a saved command-backed key that takes time to resolve, click Fetch models, then change the Provider ID and Base URL to another provider before resolution finishes. **Impact:** The original provider's API key can be disclosed to an unrelated provider or local service even though the operation subsequently reports that the endpoint changed. **Evidence:** src/settings.ts:249-255 captures providerId, awaits storedApiKey/storedEndpointKey, then calls discoverModels(customUrl, customApi, key) using mutable form values. The controls at lines 267-281 remain editable and only invalidate the model generation; the generation guard at lines 256-258 runs after discovery. src/provider-store.ts resolves command-backed credentials asynchronously with a 10-second timeout and attaches the resolved key to the supplied destination. Its redirect guard does not help because the changed URL is the initial destination. The base settings workflow did not issue a discovery request.
Code-Reviewer left a comment

Pi code review

2 new actionable findings

  • [P2] Paginated discovery drops models when endpoints are refreshed — src/provider-store.ts:347
  • [P2] Discovery runs credential commands outside Pi's working environment — src/provider-store.ts:258
Earlier findings: 1 rechecked
  • Resolved: Changing providers during credential resolution can disclose the previous provider's key (src/settings.ts:255, first reported in review #317) — Current src/settings.ts:249-257 snapshots endpointUrl, endpointApi, providerId, and enteredKey before awaiting stored credential resolution, then calls discoverModels(endpointUrl, endpointApi, key). Changing the form during credential resolution no longer redirects the captured provider's key to a newly entered destination; the generation check at lines 258-260 rejects stale results.

Aggregated the three candidate reviews against the pinned base and head, retaining two evidence-supported correctness findings and confirming that the previous credential-disclosure issue is fixed. Verification was limited to repository reads; no tests, builds, live provider requests, or Flatpak runtime checks were run.

Change walkthrough
Area Files Changes
Other code (6) src/launcher.ts, src/main.ts, src/provider-store.ts, src/settings.ts (+2 more) Maps Flatpak-style XDG_STATE_HOME to the host state directory for the Pi child. Exposes the session's provider and model catalog to settings. Adds credential resolution, stored-key lookups, and authenticated HTTP model discovery. Adds read-only Pi provider listings, endpoint editing, and discovery-backed model saving.
Tests (2) tests/launcher.test.ts, tests/provider-store.test.ts Adds coverage for Flatpak state-directory mapping. Adds model-discovery, authentication, and cross-host redirect tests.
Documentation (1) README.md Documents endpoint editing, model discovery, and extension-provided provider visibility.
Deployment & tooling (1) package.json Bumps the package version to 0.4.0.

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 10 files, +305/-23.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed 69b8b5349fd3ee7dabda49744e0fa0fc0aa798d4 with proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol. Automated advisory review; no project commands or tests were executed.

<!-- forgejo-pi-review:f459396d1e8a89d86be5b55ff4c26377545d5fd777fcf18d11dd4db7c5f9fdd6 --> ## Pi code review **2 new actionable findings** - **[P2] Paginated discovery drops models when endpoints are refreshed** — `src/provider-store.ts:347` - **[P2] Discovery runs credential commands outside Pi's working environment** — `src/provider-store.ts:258` <details> <summary>Earlier findings: 1 rechecked</summary> - **Resolved:** Changing providers during credential resolution can disclose the previous provider's key (`src/settings.ts:255`, first reported in review #317) — Current src/settings.ts:249-257 snapshots endpointUrl, endpointApi, providerId, and enteredKey before awaiting stored credential resolution, then calls discoverModels(endpointUrl, endpointApi, key). Changing the form during credential resolution no longer redirects the captured provider's key to a newly entered destination; the generation check at lines 258-260 rejects stale results. </details> Aggregated the three candidate reviews against the pinned base and head, retaining two evidence-supported correctness findings and confirming that the previous credential-disclosure issue is fixed. Verification was limited to repository reads; no tests, builds, live provider requests, or Flatpak runtime checks were run. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Other code (6) | `src/launcher.ts`, `src/main.ts`, `src/provider-store.ts`, `src/settings.ts` (+2 more) | Maps Flatpak-style XDG_STATE_HOME to the host state directory for the Pi child. Exposes the session's provider and model catalog to settings. Adds credential resolution, stored-key lookups, and authenticated HTTP model discovery. Adds read-only Pi provider listings, endpoint editing, and discovery-backed model saving. | | Tests (2) | `tests/launcher.test.ts`, `tests/provider-store.test.ts` | Adds coverage for Flatpak state-directory mapping. Adds model-discovery, authentication, and cross-host redirect tests. | | Documentation (1) | `README.md` | Documents endpoint editing, model discovery, and extension-provided provider visibility. | | Deployment & tooling (1) | `package.json` | Bumps the package version to 0.4.0. | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 10 files, +305/-23. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `69b8b5349fd3ee7dabda49744e0fa0fc0aa798d4` with `proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol`. Automated advisory review; no project commands or tests were executed.
@ -249,0 +255,4 @@
const key = value?.trim();
if (!key || key === "local") return undefined;
if (key.startsWith("!")) {
try {
Collaborator

[P2] Discovery runs credential commands outside Pi's working environment

[Quality] Command-backed keys execute with Obsidian's inherited environment and working directory rather than those used for the Pi child. A credential command that works in Pi can therefore fail during discovery, which is now required before adding an endpoint or saving changed endpoint fields.

Trigger: GUI-launched Obsidian lacks a mise-managed Node executable on PATH, and an entered or stored credential command invokes node; alternatively, the credential command uses a script relative to the vault root while Obsidian's working directory differs.

Impact: Model discovery fails with a credential-command error, blocking endpoint creation or updates despite the credential command working in the spawned Pi process.

Evidence: src/provider-store.ts:258 calls execAsync with only timeout and maxBuffer, inheriting process.env and process.cwd(). In contrast, src/session.ts constructs PiClient with the vault working directory and piEnvironment(), and src/pi-client.ts passes those values to spawn. src/launcher.ts augments Pi's PATH with discovered mise binaries and common installation directories. The settings discovery caller supplies neither that environment nor the vault working directory; unlike the base form, it executes credential commands before saving endpoint changes.

**[P2] Discovery runs credential commands outside Pi's working environment** [Quality] Command-backed keys execute with Obsidian's inherited environment and working directory rather than those used for the Pi child. A credential command that works in Pi can therefore fail during discovery, which is now required before adding an endpoint or saving changed endpoint fields. **Trigger:** GUI-launched Obsidian lacks a mise-managed Node executable on PATH, and an entered or stored credential command invokes node; alternatively, the credential command uses a script relative to the vault root while Obsidian's working directory differs. **Impact:** Model discovery fails with a credential-command error, blocking endpoint creation or updates despite the credential command working in the spawned Pi process. **Evidence:** src/provider-store.ts:258 calls execAsync with only timeout and maxBuffer, inheriting process.env and process.cwd(). In contrast, src/session.ts constructs PiClient with the vault working directory and piEnvironment(), and src/pi-client.ts passes those values to spawn. src/launcher.ts augments Pi's PATH with discovered mise binaries and common installation directories. The settings discovery caller supplies neither that environment nor the vault working directory; unlike the base form, it executes credential commands before saving endpoint changes.
@ -249,0 +344,4 @@
headers.authorization = `Bearer ${resolvedKey}`;
}
}
const payload = await requestJson(url, headers);
Collaborator

[P2] Paginated discovery drops models when endpoints are refreshed

[Quality] Discovery reads only the first response page, ignoring Google nextPageToken and Anthropic has_more/last_id pagination. Saving then replaces the endpoint's model array with that incomplete result. With manual model entry removed, later-page models cannot be configured through the panel, and refreshing an existing endpoint can remove previously configured models.

Trigger: Add an endpoint or fetch and save an existing endpoint whose model list spans multiple pages, with a desired or previously configured model on a later page.

Impact: Later-page models are omitted from the saved catalog, and refreshing and saving can delete their existing configuration and metadata.

Evidence: src/provider-store.ts:347-359 makes one request, extracts only payload.data or payload.models, and returns those IDs without following pagination. src/settings.ts:257-263 assigns that result to customModels, and its save handler passes the list to saveCustomProvider. src/provider-store.ts:210-216 constructs the replacement models array solely from supplied IDs, retaining metadata only for IDs still present. The base settings form allowed model IDs to be entered directly.

**[P2] Paginated discovery drops models when endpoints are refreshed** [Quality] Discovery reads only the first response page, ignoring Google nextPageToken and Anthropic has_more/last_id pagination. Saving then replaces the endpoint's model array with that incomplete result. With manual model entry removed, later-page models cannot be configured through the panel, and refreshing an existing endpoint can remove previously configured models. **Trigger:** Add an endpoint or fetch and save an existing endpoint whose model list spans multiple pages, with a desired or previously configured model on a later page. **Impact:** Later-page models are omitted from the saved catalog, and refreshing and saving can delete their existing configuration and metadata. **Evidence:** src/provider-store.ts:347-359 makes one request, extracts only payload.data or payload.models, and returns those IDs without following pagination. src/settings.ts:257-263 assigns that result to customModels, and its save handler passes the list to saveCustomProvider. src/provider-store.ts:210-216 constructs the replacement models array solely from supplied IDs, retaining metadata only for IDs still present. The base settings form allowed model IDs to be entered directly.
Code-Reviewer left a comment

Pi code review

1 new actionable finding

  • [P2] Discovery sends bare environment-variable names as API keys — src/provider-store.ts:265
Earlier findings: 2 rechecked
  • Resolved: Discovery runs credential commands outside Pi's working environment (src/provider-store.ts:258, first reported in review #318) — resolveCredential now calls execAsync with the supplied cwd and env: piEnvironment(). The settings discovery flow passes this.host.vaultPath || process.cwd() through storedApiKey, storedEndpointKey, and discoverModels, addressing the reported working-directory and augmented-PATH mismatch with the Pi child.
  • Resolved: Paginated discovery drops models when endpoints are refreshed (src/provider-store.ts:347, first reported in review #318) — discoverModels now accumulates model IDs across a bounded pagination loop, following Google's nextPageToken through pageToken and Anthropic's has_more/last_id through after_id before deduplicating the result. The reported first-page-only behavior is fixed in the current code; pagination was inspected statically, not exercised.

Merged the candidate reviews of head 1302ae8 against base 70c1131, covering Flatpak environment handling, provider settings, endpoint editing, and model discovery. Verification was static and read-only; tests, builds, live provider behavior, and the installed Pi credential resolver could not be exercised.

Change walkthrough
Area Files Changes
Other code (6) src/launcher.ts, src/main.ts, src/provider-store.ts, src/settings.ts (+2 more) Maps Flatpak-style XDG_STATE_HOME to the host state directory for Pi. Exposes providers and models from the live Pi session catalog. Adds credential resolution, stored-key lookups, and authenticated model discovery with pagination and redirect guards. Displays Pi-reported providers and adds endpoint editing with discovery-based model selection.
Tests (2) tests/launcher.test.ts, tests/provider-store.test.ts Adds coverage for Flatpak state-directory mapping. Adds model-discovery, command-backed credential, and cross-host redirect coverage.
Documentation (1) README.md Documents endpoint editing, discovered models, and read-only extension providers.
Deployment & tooling (1) package.json Updates the package version to 0.4.0.

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 10 files, +316/-24.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed 1302ae845a069591a4724c2d188218b88d96c1b0 with proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol. Automated advisory review; no project commands or tests were executed.

<!-- forgejo-pi-review:7a93b70328b93a64a4f86ff2a3f5734ab4202d235a0d1deb2b0e227ef40601ee --> ## Pi code review **1 new actionable finding** - **[P2] Discovery sends bare environment-variable names as API keys** — `src/provider-store.ts:265` <details> <summary>Earlier findings: 2 rechecked</summary> - **Resolved:** Discovery runs credential commands outside Pi's working environment (`src/provider-store.ts:258`, first reported in review #318) — resolveCredential now calls execAsync with the supplied cwd and env: piEnvironment(). The settings discovery flow passes this.host.vaultPath \|\| process.cwd() through storedApiKey, storedEndpointKey, and discoverModels, addressing the reported working-directory and augmented-PATH mismatch with the Pi child. - **Resolved:** Paginated discovery drops models when endpoints are refreshed (`src/provider-store.ts:347`, first reported in review #318) — discoverModels now accumulates model IDs across a bounded pagination loop, following Google's nextPageToken through pageToken and Anthropic's has_more/last_id through after_id before deduplicating the result. The reported first-page-only behavior is fixed in the current code; pagination was inspected statically, not exercised. </details> Merged the candidate reviews of head 1302ae8 against base 70c1131, covering Flatpak environment handling, provider settings, endpoint editing, and model discovery. Verification was static and read-only; tests, builds, live provider behavior, and the installed Pi credential resolver could not be exercised. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Other code (6) | `src/launcher.ts`, `src/main.ts`, `src/provider-store.ts`, `src/settings.ts` (+2 more) | Maps Flatpak-style XDG_STATE_HOME to the host state directory for Pi. Exposes providers and models from the live Pi session catalog. Adds credential resolution, stored-key lookups, and authenticated model discovery with pagination and redirect guards. Displays Pi-reported providers and adds endpoint editing with discovery-based model selection. | | Tests (2) | `tests/launcher.test.ts`, `tests/provider-store.test.ts` | Adds coverage for Flatpak state-directory mapping. Adds model-discovery, command-backed credential, and cross-host redirect coverage. | | Documentation (1) | `README.md` | Documents endpoint editing, discovered models, and read-only extension providers. | | Deployment & tooling (1) | `package.json` | Updates the package version to 0.4.0. | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 10 files, +316/-24. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `1302ae845a069591a4724c2d188218b88d96c1b0` with `proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol`. Automated advisory review; no project commands or tests were executed.
@ -249,0 +262,4 @@
throw new Error(`API key command failed: ${error instanceof Error ? error.message : String(error)}`);
}
}
const match = key.match(/^\$\{?([A-Za-z_][A-Za-z0-9_]*)\}?$/);
Collaborator

[P2] Discovery sends bare environment-variable names as API keys

[Quality] Pi supports bare environment-variable names in credential configuration, but the new resolver only looks up dollar-prefixed references. An existing endpoint using an environment-backed key therefore sends the variable name itself during discovery rather than the credential that Pi uses.

Trigger: An existing models.json endpoint has an apiKey such as MY_PROVIDER_API_KEY, that variable is present in Obsidian's environment with the actual credential, and the user fetches models or changes endpoint fields and saves without entering a replacement key.

Impact: Authenticated model discovery fails, preventing catalog refresh and blocking endpoint updates that require a fresh model list.

Evidence: src/provider-store.ts:265-266 returns non-command values literally unless they match the dollar-prefixed expression. storedEndpointKey passes models.json apiKey through this resolver, and src/settings.ts:255-258 uses that result when no entered or auth.json key is available. discoverModels then places the unresolved name in the authentication header. The base settings form saved supplied model IDs without authenticating against the model-list endpoint, so this discovery requirement introduces the incompatibility.

**[P2] Discovery sends bare environment-variable names as API keys** [Quality] Pi supports bare environment-variable names in credential configuration, but the new resolver only looks up dollar-prefixed references. An existing endpoint using an environment-backed key therefore sends the variable name itself during discovery rather than the credential that Pi uses. **Trigger:** An existing models.json endpoint has an apiKey such as MY_PROVIDER_API_KEY, that variable is present in Obsidian's environment with the actual credential, and the user fetches models or changes endpoint fields and saves without entering a replacement key. **Impact:** Authenticated model discovery fails, preventing catalog refresh and blocking endpoint updates that require a fresh model list. **Evidence:** src/provider-store.ts:265-266 returns non-command values literally unless they match the dollar-prefixed expression. storedEndpointKey passes models.json apiKey through this resolver, and src/settings.ts:255-258 uses that result when no entered or auth.json key is available. discoverModels then places the unresolved name in the authentication header. The base settings form saved supplied model IDs without authenticating against the model-list endpoint, so this discovery requirement introduces the incompatibility.
Code-Reviewer left a comment

Pi code review

2 new actionable findings

  • [P2] Adding an endpoint silently forwards an existing provider's key — src/settings.ts:255
  • [P2] Discovery registers non-chat models as selectable chat models — src/provider-store.ts:358
Earlier findings: 1 rechecked
  • Resolved: Discovery sends bare environment-variable names as API keys (src/provider-store.ts:265, first reported in review #319) — Current src/provider-store.ts:267 recognizes bare uppercase environment-variable names and returns their nonempty process.env value before falling back to a literal. Both storedApiKey and storedEndpointKey use this resolver, so the reported MY_PROVIDER_API_KEY trigger now resolves to the actual credential before discovery constructs its authentication header.

Merged the candidate reviews for head 20a25a7 against base 70c1131, validating the reported discovery issues and prior finding against the supplied diff and available surrounding code. Verification was read-only and static; no tests or builds were run, and live Obsidian/provider behavior was not exercised.

Change walkthrough
Area Files Changes
Other code (6) src/launcher.ts, src/main.ts, src/provider-store.ts, src/settings.ts (+2 more) Map Flatpak-style XDG_STATE_HOME to the host state directory for Pi. Expose providers and model names from Pi's loaded catalog. Add credential resolution and authenticated, paginated model discovery. Display Pi providers and add endpoint editing with fetched model lists.
Tests (2) tests/launcher.test.ts, tests/provider-store.test.ts Add coverage for Flatpak state-directory mapping. Add discovery, authentication, and redirect-credential protection tests.
Documentation (1) README.md Document endpoint editing, model discovery, and extension-provider display.
Deployment & tooling (1) package.json Bump the package version to 0.4.0.

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 10 files, +318/-24.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed 20a25a738b44b97453ae07253e682afa2b3ec189 with proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol. Automated advisory review; no project commands or tests were executed.

<!-- forgejo-pi-review:86f0de1df041f22f4a27eba35ebddc546ad7fe795aecc473a6ca0a7dd30b630b --> ## Pi code review **2 new actionable findings** - **[P2] Adding an endpoint silently forwards an existing provider's key** — `src/settings.ts:255` - **[P2] Discovery registers non-chat models as selectable chat models** — `src/provider-store.ts:358` <details> <summary>Earlier findings: 1 rechecked</summary> - **Resolved:** Discovery sends bare environment-variable names as API keys (`src/provider-store.ts:265`, first reported in review #319) — Current src/provider-store.ts:267 recognizes bare uppercase environment-variable names and returns their nonempty process.env value before falling back to a literal. Both storedApiKey and storedEndpointKey use this resolver, so the reported MY_PROVIDER_API_KEY trigger now resolves to the actual credential before discovery constructs its authentication header. </details> Merged the candidate reviews for head 20a25a7 against base 70c1131, validating the reported discovery issues and prior finding against the supplied diff and available surrounding code. Verification was read-only and static; no tests or builds were run, and live Obsidian/provider behavior was not exercised. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Other code (6) | `src/launcher.ts`, `src/main.ts`, `src/provider-store.ts`, `src/settings.ts` (+2 more) | Map Flatpak-style XDG_STATE_HOME to the host state directory for Pi. Expose providers and model names from Pi's loaded catalog. Add credential resolution and authenticated, paginated model discovery. Display Pi providers and add endpoint editing with fetched model lists. | | Tests (2) | `tests/launcher.test.ts`, `tests/provider-store.test.ts` | Add coverage for Flatpak state-directory mapping. Add discovery, authentication, and redirect-credential protection tests. | | Documentation (1) | `README.md` | Document endpoint editing, model discovery, and extension-provider display. | | Deployment & tooling (1) | `package.json` | Bump the package version to 0.4.0. | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 10 files, +318/-24. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `20a25a738b44b97453ae07253e682afa2b3ec189` with `proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol`. Automated advisory review; no project commands or tests were executed.
@ -249,0 +355,4 @@
: [];
for (const entry of entries) {
if (typeof entry === "string") ids.push(entry);
else if (typeof entry === "object" && entry !== null && "id" in entry && typeof entry.id === "string") ids.push(entry.id);
Collaborator

[P2] Discovery registers non-chat models as selectable chat models

[Quality] Discovery treats every returned model ID as compatible with the selected chat API. Mixed catalogs such as OpenAI's /v1/models include embedding, transcription, and image-generation models, which are then saved as chat models without a filtering or selection step.

Trigger: A user adds or refreshes an OpenAI-compatible endpoint whose model catalog includes non-chat models, saves it, restarts Pi, and selects one of those models in the chat header.

Impact: The chat selector offers models that cannot handle its requests, causing prompts using those selections to fail. Unlike the previous manual model list, the new settings form provides no way to exclude those entries.

Evidence: src/provider-store.ts:356-359 collects every entry's ID or name without checking capabilities. src/settings.ts assigns the entire discovery result to customModels and passes it to saveCustomProvider, which persists every ID under the selected API at src/provider-store.ts:211-217. PiSession.hydrate loads get_available_models into state.models; mergeModels only sorts them, and src/chat-view.ts renderControls exposes every loaded model as an option. The base form allowed users to supply only compatible model IDs.

**[P2] Discovery registers non-chat models as selectable chat models** [Quality] Discovery treats every returned model ID as compatible with the selected chat API. Mixed catalogs such as OpenAI's /v1/models include embedding, transcription, and image-generation models, which are then saved as chat models without a filtering or selection step. **Trigger:** A user adds or refreshes an OpenAI-compatible endpoint whose model catalog includes non-chat models, saves it, restarts Pi, and selects one of those models in the chat header. **Impact:** The chat selector offers models that cannot handle its requests, causing prompts using those selections to fail. Unlike the previous manual model list, the new settings form provides no way to exclude those entries. **Evidence:** src/provider-store.ts:356-359 collects every entry's ID or name without checking capabilities. src/settings.ts assigns the entire discovery result to customModels and passes it to saveCustomProvider, which persists every ID under the selected API at src/provider-store.ts:211-217. PiSession.hydrate loads get_available_models into state.models; mergeModels only sorts them, and src/chat-view.ts renderControls exposes every loaded model as an option. The base form allowed users to supply only compatible model IDs.
@ -211,0 +252,4 @@
const endpointApi = customApi;
const providerId = editing?.id ?? customId;
const enteredKey = customKey;
const key = enteredKey.trim()
Collaborator

[P2] Adding an endpoint silently forwards an existing provider's key

[Quality/security] Discovery falls back to stored credentials using the typed provider ID even when adding a new endpoint. Consequently, leaving the optional key blank can send an existing provider secret to the newly entered host merely by clicking Fetch models, before any endpoint configuration is saved.

Trigger: A user has an API key saved for a provider ID such as openai, enters that ID in Add a compatible endpoint with a different gateway or compatible-server URL, leaves the API key blank, and clicks Fetch models or Add endpoint.

Impact: The new host receives the existing provider credential without the user entering that credential or explicitly choosing to reuse it.

Evidence: src/settings.ts:253-258 selects editing?.id ?? customId and unconditionally falls back to storedApiKey and storedEndpointKey when the entered key is blank. src/provider-store.ts:271-274 reads auth.json by that ID, and discoverModels attaches the result as an authentication header to the initial URL. requestJson's cross-host redirect guard only constrains redirects, not this initial destination. The form describes blank-key retention specifically for editing; the base settings flow saved manually supplied models without making this discovery request.

**[P2] Adding an endpoint silently forwards an existing provider's key** [Quality/security] Discovery falls back to stored credentials using the typed provider ID even when adding a new endpoint. Consequently, leaving the optional key blank can send an existing provider secret to the newly entered host merely by clicking Fetch models, before any endpoint configuration is saved. **Trigger:** A user has an API key saved for a provider ID such as openai, enters that ID in Add a compatible endpoint with a different gateway or compatible-server URL, leaves the API key blank, and clicks Fetch models or Add endpoint. **Impact:** The new host receives the existing provider credential without the user entering that credential or explicitly choosing to reuse it. **Evidence:** src/settings.ts:253-258 selects editing?.id ?? customId and unconditionally falls back to storedApiKey and storedEndpointKey when the entered key is blank. src/provider-store.ts:271-274 reads auth.json by that ID, and discoverModels attaches the result as an authentication header to the initial URL. requestJson's cross-host redirect guard only constrains redirects, not this initial destination. The form describes blank-key retention specifically for editing; the base settings flow saved manually supplied models without making this discovery request.
BlackHatMagic deleted branch fix/provider-ui-followup 2026-10-25 07:16:09 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
BlackHatMagic/Pi-Obsidian!5
No description provided.