Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Send endpoint text and API keys only to the server approved with Connect - #921

Draft
FuJacob wants to merge 1 commit into
mainfrom
security/endpoint-origin-approval
Draft

FuJacob wants to merge 1 commit into
mainfrom
security/endpoint-origin-approval

Conversation

@FuJacob

@FuJacob FuJacob commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

The endpoint's server URL and the selected engine are plain UserDefaults keys. The app is unsandboxed, so any process running as the same user can rewrite them, and on the next launch Cotabby would send the user's text, plus the stored API key, to whatever server they name. The Server URL field also saved on every keystroke, so editing the address to a new provider sent the old provider's key to the new host on the next suggestion, before Connect was pressed. With this change, text and the API key go only to a server (scheme, host, port) the user approved by pressing Connect.

  • Connect is the only commit. The Server URL field edits a view-local draft. Connect (button or Return) validates it, records its origin as approved, commits the address, saves the key draft, and only then sends the first request. "Use Ollama Default" only fills the field. A caption says when the field holds an address that hasn't been saved yet.
  • Approval lives in the Keychain, as a second item (approved-origin) in the same service as the API key, not in UserDefaults. The record exists with or without an API key, so local servers that need no key work the same way.
  • Request-time gate. Generation, Ollama warmup, and model discovery read the new openAICompatibleApprovedConfiguration. It checks the configured origin before the API key is read, and if they differ it throws unapprovedServer and sends nothing. Settings shows "Press Connect to confirm before Cotabby sends it any text." in the pane callout and the connection status, the sidebar shows its attention dot, and the Home card reads "Confirm server". Automatic refreshes (pane appear, engine switch, power profile) never approve anything.
  • Pure helpers with tests. OpenAICompatibleEndpointOrigin (Support/Runtime) normalizes case, default ports, path and trailing slash, and IPv6 brackets. OpenAICompatibleOriginApprovalPolicy (Support/Settings) holds the request gate and the one-time upgrade rule.
  • Upgrade migration. On the first launch with this build there is no record. An existing endpoint user (engine selected, or reached through an active power profile) adopts the configured origin once. Everyone else gets a none sentinel. Because the sentinel is a Keychain record, later edits to the defaults can't make the adoption run again. If the Keychain read fails, nothing is approved and nothing is written. Reset to Defaults writes the sentinel.
  • L1. The fc/fd/fe8–feb "local network" rule now applies only to hosts that parse as IPv6 literals (inet_pton), so DNS names like fdic.gov are public again, and with them plain HTTP is rejected. This also fixes fd::1, which is 00fd::1 and therefore outside fc00::/7.
  • L2. The plain-HTTP LAN warning now says the API key is also sent unencrypted. The warning describes the address in the field, so it is on screen before Connect, and pressing Connect is the explicit confirmation. No new settings.
  • The XCTest host skips the Keychain restore, as it already does for the typing-history archive. Under tests nothing is approved.

Validation

  • swiftlint lint --quiet --strict on the app target: clean.
  • xcodegen generate: the committed Cotabby.xcodeproj includes the four new files.
  • Not built or run locally (no disk space on the authoring machine); CI build and tests are the compile check.
  • New or updated tests: OpenAICompatibleEndpointOriginTests, OpenAICompatibleOriginApprovalPolicyTests, approval cases in SuggestionSettingsModelTests (Connect gate, invalid address leaves state unchanged, one-shot adoption, sentinel, Keychain failure, reset), host-scope and warning rows in OpenAICompatibleEndpointConfigurationTests and OpenAICompatibleAPIClientTests.
  • Not exercised by hand: the Settings pane flow and a real Keychain read and write.

Linked issues

None filed. Addresses H2, L1, and L2 from a static security review of 8cdbea2.

Risk / rollout notes

  • The migration trusts the configuration present at upgrade time. If the defaults were already pointing at a hostile server before this build is installed, that server is adopted once. The stricter alternative is to drop the adoption and require every endpoint user to press Connect once after updating. That is a one-line change in OpenAICompatibleOriginApprovalPolicy.restore, and I'd consider it if endpoint users are few.
  • New behavior for endpoint users who haven't connected yet. This includes anyone who picks "Local endpoint" in onboarding: the default Ollama server also needs one Connect before suggestions start. Loopback is deliberately not exempt. Otherwise a same-user process could switch the engine to the endpoint and listen on the default port.
  • After Connect, the API key in the field goes to the newly approved server. That's an explicit action, but a user switching providers should clear or replace the key first. The pane doesn't clear it automatically.
  • The record is a legacy (file-based) login-keychain item, like the existing API key. Its ACL resists silent rewrites much better than UserDefaults does, but it's not the data protection keychain. Moving there needs a provisioning profile; see L12, handled separately.
  • OpenAICompatibleEndpointOrigin.swift and its test file are byte-identical to the copies in Keep endpoint requests on their own session, the same server, and bounded streams #929, which uses the helper for its redirect check, so either PR can merge first. Both PRs add files, so project.pbxproj may need xcodegen generate after the first one merges.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@FuJacob
FuJacob force-pushed the security/endpoint-origin-approval branch from c1886af to 03f127b Compare November 23, 2026 04:09

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant