Skip to content

fix(llm): refuse a base URL that belongs to another provider's API - #235

Merged
goldbarth merged 1 commit into
mainfrom
fix/anthropic-key-foreign-host
Sep 23, 2026
Merged

goldbarth merged 1 commit into
mainfrom
fix/anthropic-key-foreign-host

Conversation

@goldbarth

Copy link
Copy Markdown
Owner

Closes #233

  • Refused at config load, not warned: a Chartula__Llm__BaseUrl whose host belongs to another provider's API stops the run before the history is read, so the key never leaves the machine. The run header already named the mismatch and nothing stopped on it; a key that went out has to be rotated.
  • Two hosts, both certain: api.openai.com is refused for anthropic, api.anthropic.com for openai-compatible. Every other host is accepted, because a proxy or a gateway lives at a host of its own. The list stays short on purpose: several hosted endpoints serve both dialects under one host, so a longer one would refuse working setups.
  • Names both settings, and says when the provider was not set: llm.provider is not set and defaults to 'anthropic' is how the mismatch happens - the endpoint came from the environment, the provider from a chartula.yaml in another repository. The key variable named is the one in force, not the default.
  • Checked where the options are read (ReadOptions), so the refusal holds wherever they are read, not only where the client is built. It lives in ProviderHost, beside EndpointUrl.
  • api.anthropic.com also serves an OpenAI-compatible layer, which openai-compatible can no longer reach; the refusal points at llm.provider: anthropic, the adapter that speaks Anthropic's API in full.
  • Docs: configuration.md (environment-only settings).

Reproduced before the fix with the release binary, a dummy key (ANTHROPIC_API_KEY=sk-ant-dummy) and a local GitHub stub, the way the issue was found - the dummy key went to api.openai.com:

Model:  anthropic at https://api.openai.com/v1, key from ANTHROPIC_API_KEY
        claude-sonnet-5, thinking provider-default
...
--- Technical ---
  (failed) Changelog generation for 'v1.1.0' failed: Status Code: NotFound

Verified after the fix, same command, also with networking disabled (unshare -rn), exit code 1:

Configuration error: Chartula__Llm__BaseUrl 'https://api.openai.com/v1' is OpenAI's API, but llm.provider is not set and defaults to 'anthropic', so the key in ANTHROPIC_API_KEY would be sent to OpenAI. For OpenAI's API, set llm.provider to openai-compatible (in chartula.yaml, or as Chartula__Llm__Provider); otherwise unset Chartula__Llm__BaseUrl.

and the other direction:

Configuration error: Chartula__Llm__BaseUrl 'https://api.anthropic.com/v1' is Anthropic's API, but llm.provider is 'openai-compatible', so the key in OPENAI_API_KEY would be sent to Anthropic. For Anthropic's API, set llm.provider to anthropic (in chartula.yaml, or as Chartula__Llm__Provider); otherwise unset Chartula__Llm__BaseUrl.

Tests: LlmWiringTests (provider not set, both directions, host spelled in upper case with a trailing dot, renamed key variable, gateways and matching hosts accepted), ForeignProviderHostTests (the built CLI stops before any request); full suite 742 passing, build and dotnet format clean.

@goldbarth goldbarth self-assigned this Sep 23, 2026
@goldbarth
goldbarth merged commit 79f2a98 into main Sep 23, 2026
4 checks passed
@goldbarth
goldbarth deleted the fix/anthropic-key-foreign-host branch September 23, 2026 14:03
goldbarth added a commit that referenced this pull request Oct 1, 2026
…rd decided, recorded and amended (#318)

Follows #264, which moved the ADRs to `docs/development/adr/`, and #317,
which ruled out the claim that the audiences "cannot disagree".

- **Why:** the ADRs had one `Date` line that mixed when a decision was
taken with what changed later ("2026-07-16 (#45), extended by #96"), no
record of when each file was written, and no list of their own;
CONTRIBUTING kept the only list. ADR 0003 did not mention #235, which
added a refusal to the decision it records, and ADR 0002's title named
the tools rather than the decision.
- **`docs/development/adr/README.md`** holds the index, when to write an
ADR, and a template with separate fields: **Decided** (when it took
effect in the code, which can precede the record), **Recorded** (when
the file was written), and **Amended** (every later change to the
decision or to a fact in it, each dated with its pull request). A moved
file, a fixed link or a reworded sentence is not an amendment, so the
list stays a record of meaning.
- **0001** gives the date and pull request of each part: facts first on
2026-07-16 (#45), and the structure of a rendering on 2026-09-16 (#129,
for #96), which the Decision now marks as its own paragraph with the
reason #96 found. Amended here: "so they cannot disagree on what
happened" becomes what a shared fact base actually gives, the same
changes, categories and breaking status, and says why texts can still
disagree.
- **0002** is retitled to its decision, "Dependencies that keep a
native-AOT build reachable", and the file renamed to match; the Decision
opens on the rule the bullets implement. #268's correction of the
platform count is listed as its amendment.
- **0003** records #235: a model endpoint on the API host of the other
provider is refused before any request, with the reason (a key sent
there must be rotated) and why the list of hosts stays short. Dated
2026-09-23, the day of #235, and marked as recorded here.
- **CONTRIBUTING** links the index instead of listing the ADRs, and the
README's "Contribute" table gains a row for it, so the list exists in
one place.

**Verified:**
- Every date and number was taken from GitHub: the merge dates of #42,
#43, #45, #129, #166, #216, #235 and #268, and the issues each closes
(#3, #4, #6, #96, #158, #184, #233).
- What #268 changed in 0002 was read from its diff: the platform count,
nothing else. #264, #270 and #316 only moved the files or changed a
link, so they are not amendments.
- The rule 0003 now states was checked against `ProviderHost.cs` and
#235's description.
- Every relative link and anchor in all Markdown files of the repository
resolves (script, with a negative test); the renamed 0002 had no inbound
link besides CONTRIBUTING's list.

Tests: none, documentation only.
goldbarth added a commit that referenced this pull request Oct 1, 2026
…320)

Follows #319 (ADR 0004); this branch builds on it for the index row and
is rebased onto `main` once #319 is merged.

- **Why:** seven changes since September made Chartula stop where it
used to choose silently, each with its own reasoning in its pull
request, but the rule they share was written down nowhere. A contributor
adding an option or a setting could not tell whether to refuse an
ambiguous value or take the likelier reading, nor when refusing goes too
far.
- **Context** lists the seven cases in one table, each with what the
silent choice did and the change that ended it: a first tag (#198 for
#138, #282), a key sent to the other provider's host (#235), an unknown
or misindented key (#238), a shallow clone read as a first release
(#244), review mode approving unseen text (#247), two configuration
files (#287 for #278), and options a command does not take (#301).
Decided is #198, the first of them.
- **Decision:** stop and say so instead of choosing; before anything is
spent; with a message that names the cause and the fix, shown with two
real messages; ask at a terminal where the answer is the user's, and
stop naming the option without one; refuse only what Chartula can tell
for certain (an empty list, an unknown host and an unknown model id are
taken as written); refuse a setting that would have no effect. The rule
is about what the user meant, not about what the release says, which is
what flags are for.
- **Consequences** name the cost: a run that could have produced
something stops, and a CI job fails until the input says what it means.
The ADR weighs that rerun against what a silent choice cost in the seven
cases. For a new case, four questions in order, so a contributor can
apply the rule rather than match it against the examples.
- The index in `adr/README.md` lists 0005.

**Verified:**
- Each case was checked against its pull request's description and the
issue it closes (#237, #243, #233, #278, #300, #138); the dates are the
merge dates.
- Both messages are the ones `docs/cli.md` and `docs/configuration.md`
show from the built binary.
- The counter-cases were checked in the code: `ProviderHost` accepts
every host but two, `ClaudeThinkingSupport` passes an unknown model id,
#289 reads an empty list as written, and #244 still runs `--since` in a
shallow clone when the range holds.
- Every relative link and anchor in all Markdown files of the repository
resolves (script, with a negative test).

Tests: none, documentation only.
goldbarth added a commit that referenced this pull request Oct 1, 2026
…d writes (#323)

Follows #318, which gave ADR 0003 its record of the provider-host
refusal (#235), and #306, which made `outputs.md` the home of what each
file holds.

- **Why:** SECURITY named the line between repository content and the
operator's credentials as the part worth protecting, but did not say
where that line runs or link the decision that draws it. A reporter
could not tell from it what a run sends to the model provider, what it
writes to GitHub, or what a published `changelog.json` holds, which is
what decides whether a finding crosses the line.
- **"The trust boundary"** links ADR 0003 and states its four rules in a
sentence each: endpoints and credential variable names from the
environment only, no credential from a file and no value in any output,
`https` except on this machine, and the other provider's API host
refused. A way around any of them is in scope.
- **"What a run sends and writes"** gives each destination one bullet
and links its home instead of restating it: the model provider (what a
fact holds, how often it is sent, the `title-only` depth, the local
server), GitHub (`github.md`'s table), and the disk (`changelog.json`
without descriptions, the run record that keeps them locally).
- **Scope** gains one line for pull request text that steers the model:
a known limitation, linked to the README; it becomes in scope when it
makes Chartula send a credential, run a program or publish elsewhere.

**Verified:**
- Each rule against the code: `ChartulaConfiguration` (what the
environment is read for), `EndpointUrl` (`https` except loopback),
`ProviderHost`, `EndpointNotice` and `doctor` (variables named, values
never).
- What reaches the model against `GroundedFactsFactory` (the statement
per fact) and `ThoroughFaithfulnessChecker` (facts and rendering); what
reaches GitHub against `GitHubPullRequestReader` and
`GitHubReleaseNotesWriter`.
- Private vulnerability reporting is enabled on the repository, so the
report link works.
- Every relative link and anchor in all Markdown files of the repository
resolves (script, with a negative test).

Tests: none, documentation only.
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.

An Anthropic key is sent to an OpenAI endpoint when the provider is not set

1 participant