Skip to content

Apply http_forbid_headers to Basic credentials sent in the Authorization header - #129850

Merged
kolsha merged 8 commits into
ClickHouse:masterfrom
groeneai:url-userinfo-forbid-authorization
Nov 11, 2026
Merged

kolsha merged 8 commits into
ClickHouse:masterfrom
groeneai:url-userinfo-forbid-authorization

Conversation

@groeneai

@groeneai groeneai commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #128998

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

When http_forbid_headers forbids Authorization, Basic credentials that would be sent in that header are now refused too: the userinfo of url, urlCluster and URL table URLs (including url wildcards and web disks), credentials of HTTP dictionaries created by DDL, the userinfo of format_avro_schema_registry_url, and user/password of the Elasticsearch engine. Before, only an explicit Authorization header was refused.

Description

On 26.8.18.2, 26.9.19.9 and 26.10.2.103, with <http_forbid_headers><header>Authorization</header></http_forbid_headers>, url(..., headers('Authorization' = ...)) is refused, but url('http://user:password@host/...') still sends Authorization: Basic ...: the credentials parsed from the userinfo are turned into that header in ReadWriteBufferFromHTTP::prepareRequest, after the explicit headers and never through HTTPHeaderFilter.

This adopts the request-time design of @ kolsha's draft #128998: HTTPHeaderFilter::checkBasicCredentials / checkURIUserInfo check a synthetic Authorization header with the existing filter, in setCredentialsFromURL (every URL-userinfo sender), each request of a DDL HTTP dictionary, and each schema registry request. A forbidden failover option fails the read instead of being skipped. Credentials with an empty username send nothing and are not refused, except by the schema registry, which sends any userinfo. Stored URL and Elasticsearch tables stay attached after the header is forbidden, and a loaded HTTP dictionary is refused on its next update; only requests are refused. Admin-only senders (interserver credentials, XML dictionaries) are unchanged.

Added on top of #128998: the HTTP dictionary is checked per request instead of when its source is created, the initiator of urlCluster checks every URL before a worker gets it (a worker checks it under its own configuration, which can differ), the same check for Elasticsearch user/password, and tests for the web disk read, web_index metadata and AvroConfluent output paths. This PR supersedes the draft #128998.

Validation: integration tests in test_storage_url, test_disk_over_web_server and test_storage_elasticsearch; the 16 forbidden-header cases fail on master and pass with the fix, the empty-username and redirect cases pass on both.


Workflow [PR]
Sync PR [sync-upstream/pr/129850]

Version info

  • Merged into: 26.11.1.1926-master (included in 26.11 and later)
  • Backported to: 26.10.7.4, 26.9.32.11, 26.8.40.11, 26.3.67.17

groeneai and others added 5 commits November 6, 2026 17:42
…` header

When `http_forbid_headers` forbids `Authorization`, an explicit
`url(..., headers('Authorization' = ...))` is refused, but Basic credentials
from the userinfo of a URL (`http://user:password@host/`) were still sent in
that header: `setCredentialsFromURL` builds `HTTPBasicCredentials`, and
`ReadWriteBufferFromHTTP::prepareRequest` synthesizes `Authorization` from them
after the explicit headers, never through `HTTPHeaderFilter`.

Check a synthetic `Authorization` header with the existing filter where each
sender gets its Basic credentials, at request time:

- `HTTPHeaderFilter::checkBasicCredentials` (no-op for an empty username,
  which sends nothing) and `checkURIUserInfo` (for `ConfluentSchemaRegistry`,
  which authenticates on any non-empty userinfo).
- `setCredentialsFromURL` takes the filter and checks there, which covers
  `url`, `urlCluster` workers, the `URL` engine, url wildcards from index
  pages, `web` disks and schema inference. Its four callers moved the call out
  of their failover `try`, so a forbidden option fails the read instead of
  being skipped.
- `HTTP` dictionaries created by DDL (`credentials(user, password)`), and
  every schema registry request of `AvroConfluent` input and output.

Request time rather than definition time, so stored definitions keep loading
(startup, `ATTACH`, replicated replay, `RESTORE`) after an administrator adds
`Authorization` to the list; only their requests are refused. Admin-defined
senders that do not go through these paths (interserver credentials of
`DataPartsExchange`, XML-config dictionaries) are unchanged.

Based on the draft ClickHouse#128998 by
@ kolsha (its final request-time design, unchanged), plus a test for the
`AvroConfluent` output path.

Co-authored-by: Nikolai Ovchinnikov <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`ElasticsearchConfiguration::validate` checks the `Authorization` header of
`bearer_token` and `api_key` against `http_forbid_headers`, but
`authorizationHeaders` is empty for `user` + `password`, which
`ElasticsearchClient` sends as Basic credentials in `Authorization`. Check
them in the client constructor, i.e. per read, so a stored table still loads
after the header is forbidden and only its reads are refused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eb disk guards

A loaded `HTTP` dictionary keeps its source: a periodic update clones it
(`ExternalLoader` calls `clone`, and `HTTPDictionarySource::isModified` is
always true), and `DIRECT` and cache layouts call `loadIds`/`loadKeys` on the
retained source. So the check at source construction let an already loaded
DDL dictionary keep sending its Basic credentials after `SYSTEM RELOAD CONFIG`
added `Authorization` to `http_forbid_headers`. Check them in `loadAll`,
`loadUpdatedAll`, `loadIds` and `loadKeys` instead; the check at construction
is removed, since a `DIRECT` dictionary sends no request when it is created.

Tests:
- a loaded dictionary with `LIFETIME(MIN 1 MAX 1)` is refused on its next update;
- a `web` disk whose `.index` is fetched without credentials reads its data
  through `ReadBufferFromWebServer` with the userinfo, and a `web_index` disk
  probes `format_version.txt` with a HEAD request before any listing, so both
  guards are reached on their own (every other test hits the listing guard first).

Also drop the request-counter assertion of the `AvroConfluent` output test, which
could not fail: the mock server does not handle POST, so the registration
request was never counted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The initiator of `urlCluster` checked only the host and the explicit headers,
then handed each URL to the workers, which check its userinfo under their own
`http_forbid_headers`. A worker whose configuration does not forbid
`Authorization` therefore still sent the Basic credentials although the
initiator refuses an explicit `Authorization` header. The task callback now
calls `setCredentialsFromURL` for each failover option of every URL before a
worker gets it, parsing the options as the worker does.

Test: `test_cluster_node2` has `node2`, whose configuration does not forbid the
header, as its only worker; the userinfo is in the second failover option, so
checking only the whole URL is not enough.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop comments that narrate the new code's design; restore master's wording of the comments the PR only moved or rephrased; shorten the API comments to one line each.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (click to expand)
  • ❌ A loaded DDL HTTP dictionary kept sending its credentials after Authorization was forbidden by a config reload (its source is cloned across updates) - fixed: checked per request.
  • ⚠️ The web disk read and web_index metadata guards had no test of their own - added.
  • ❌ urlCluster checked the userinfo only on the workers, under their own configuration, while the initiator already refuses an explicit Authorization header - fixed: the initiator checks every failover option of every URL before a worker gets it; tested with a worker whose configuration does not forbid the header.
  • 💡 The Elasticsearch engine is experimental; it is the same bug in a sibling sender, so it is fixed here too.

@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Server with <http_forbid_headers><header>Authorization</header></http_forbid_headers>: SELECT * FROM url('http://api_user:<password>@127.0.0.1:<http>/?query=SELECT%20currentUser()', 'LineAsString', 'v String') returns api_user on master (and on official 26.8.18.2, 26.9.19.9, 26.10.2.103) while the explicit headers('Authorization' = ...) form is refused with Code: 36.
b Root cause explained? Basic credentials are kept apart from the header list and turned into Authorization by credentials.authenticate(request) in ReadWriteBufferFromHTTP::prepareRequest, after the explicit headers, so HTTPHeaderFilter never sees that header. The HTTP dictionary, the Avro schema registry and the Elasticsearch engine build such credentials themselves.
c Fix matches root cause? Yes. A synthetic Authorization header goes through the existing checkHeaders where each sender gets its credentials, at request time.
d Test intent preserved / new tests added? Integration tests: 4 url shapes (plain, failover, urlCluster, wildcard), urlCluster whose worker (node2) does not forbid the header, stored wildcard table, DDL HTTP dictionary (new and already loaded, refused on its next periodic update), Avro registry fetch (2 URL forms) and register, web disk data read (test_disk_over_web_server), web_index disk metadata HEAD, Elasticsearch user/password; plus non-regression cases for an empty username and a redirect Location with userinfo. No existing test case changed; node5 of test_disk_over_web_server loads one more config with a placeholder header.
e Both directions demonstrated? Yes. The 14 forbidden cases fail on master and pass with the fix; the 2 non-regression cases pass on both. The loaded-dictionary, web read and web_index HEAD cases each also fail when only their own guard is removed, and the urlCluster worker case fails when the initiator checks only the whole URL instead of each failover option. Full test_storage_url (79), test_disk_over_web_server (8) and test_storage_elasticsearch (22) pass; the new cases pass 5/5 repeated.
f Fix is general across code paths? All senders of Basic credentials built from query input: the 4 callers of setCredentialsFromURL (url/URL/urlCluster/schema inference, index-page listing, web object metadata, ReadBufferFromWebServer), the urlCluster initiator (each failover option of every URL it hands to a worker, since a worker checks under its own configuration), DDL HTTP dictionaries (checked in loadAll/loadUpdatedAll/loadIds/loadKeys, since a loaded source is kept across updates), Avro registry fetch and register, Elasticsearch. Admin-only senders (interserver credentials, XML dictionaries) stay unchanged on purpose.
g Fix generalizes across inputs (params/datatypes/wrappers)? Userinfo user, user:, user:password, percent-encoded, :password (empty username sends nothing and is not refused); header, lower-case header and header_regexp configs behave exactly as for an explicit Authorization header. No data types involved.
h Backward compatible? (maintainer-approved exception only) No settings or formats change. Only servers whose http_forbid_headers matches Authorization see a difference, and only at request time: stored tables and dictionaries still load after the header is forbidden.
i Invariants and contracts preserved? setCredentialsFromURL still clears and fills the credentials, then throws if they are forbidden; every caller calls it before building a buffer and outside its failover try, so no request is sent with refused credentials and a forbidden option is not skipped silently.

Session id: cron:clickhouse-impl-slot-5:20261106-222600

@clickhouse-gh

clickhouse-gh Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fcc692d]

Summary: ✅


AI Review

Summary

PR #129850 applies http_forbid_headers to Basic credentials that generate an Authorization header across URL readers, web disks, DDL HTTP dictionaries, the Avro schema registry, and Elasticsearch. Reviewed head fcc692dbb459ffc0b5cad908c79db9581887e312, including all prior discussion and the added regression coverage. No actionable findings.

Missing context / blind spots
  • ⚠️ No local build or integration tests were run. Runtime confidence relies on the submitted regression tests and the validation reported in the PR discussion; the latest fetched Praktika report contains no failures but no individual integration-test results.
Final Verdict

Status: ✅ Approve.

@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

cc @kolsha @Algunenano, could you review this and add the can be tested label so CI runs? It refuses the Basic credentials that URL userinfo, DDL HTTP dictionaries, the Avro schema registry and Elasticsearch send in the Authorization header when http_forbid_headers forbids that header, building on the draft #128998, which this PR supersedes.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... can be tested Allows running workflows for external contributors labels Nov 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing fcc692dbb with master 2170ef336 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse-keeper ×1.11 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 9.1 s 18.2 s +9.2 s (+101%)
Compile time of recompiled translation units

59 translation units recompiled, 472 s compile time in total, 59 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×1.05 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +19.2 s (+4%) in total before that adjustment.

Job report

@groeneai

groeneai commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 224d61d

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 05515_global_subquery_projection_where not from this PR (it changes only the http_forbid_headers checks of outbound credentials): master regression from #129425, UNKNOWN_IDENTIFIER for the GLOBAL IN temporary table when the projection query is analyzed with parallel replicas; fails in this lane on master and on other PRs #129836 (mine, open)
Mergeable Check, PR praktika rollups of the row above #129836 (same as above)
Sync - CH Inc sync (private, not actionable by me)

No job was dropped. The FAIL rows of the two Bugfix validation (integration tests) jobs are the new tests failing on master, as intended; both jobs passed. The only other CIDB FAIL rows on this head are Config Workflow / Pre Hooks and Finish Workflow / Post Hooks of the run before the can be tested label.

Session id: cron:our-pr-ci-monitor:20261107-033004

@kolsha

kolsha commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

@groeneai merge recent master in

@kolsha kolsha self-assigned this Nov 10, 2026
@kolsha
kolsha enabled auto-merge November 10, 2026 11:15
groeneai and others added 2 commits November 10, 2026 15:29
Since ClickHouse#123950 (merged with master in 21e71b8), `SELECT sum(id)` over the
web disk table is answered from the per-part `basic` statistics. The statistics
are loaded by the first query and kept in memory, so the query after
`http_forbid_headers` forbids `Authorization` sent no HTTP request and
`test_userinfo_with_forbidden_authorization` failed with "Client expected to be
failed but succeeded".

A filter disables that optimization, so every query reads `id` from the web
server again. The query needs no new setting, so the test stays the same on
release branches that do not have `use_statistics_for_sum_avg_aggregation`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The existing failover case puts the credentialed option last, so it cannot
tell a refused read from one that skips the forbidden option: with no later
option, both end with the same error. With a usable second option, a read
that moved on to it would succeed. Cover both the `url()` failover loop and
the listing loop of a `url()` wildcard.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
auto-merge was automatically disabled November 10, 2026 16:15

Head branch was pushed to by a user without write access

@groeneai

Copy link
Copy Markdown
Collaborator Author

Thanks for merging master, and sorry for the slow reply. The merge brought in #123950, which answers sum(id) from the part statistics, so after Authorization was forbidden test_userinfo_with_forbidden_authorization sent no HTTP request and failed in 6 integration jobs.

  • bed90ca: the test query has a filter now, so it reads the column from the web server each time (5/5 locally with this PR's CI binary, fails on master).
  • fcc692d: two more forbidden cases with a usable second failover option, for url() and for a url() wildcard, so a read that skipped the forbidden option would fail them.

My push turned auto-merge off (I have no write access to the repo), so it needs to be enabled again.

@kolsha
kolsha added this pull request to the merge queue Nov 11, 2026
Merged via the queue into ClickHouse:master with commit ce8fe58 Nov 11, 2026
187 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 11, 2026
@nikitamikhaylov nikitamikhaylov added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Nov 11, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 11, 2026
@groeneai groeneai mentioned this pull request Nov 12, 2026
1 task done
kolsha pushed a commit that referenced this pull request Nov 18, 2026
The new tests of #129850 call it to check the refusal, but it came to
master's test file with #126184, which is not on 26.10, so those cases
fail with `NameError`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kolsha added a commit that referenced this pull request Nov 18, 2026
Carry the port of the cherry-pick as a tree onto the rebuilt `backport/26.3/129850` branch: the release branch was rewritten, so the earlier port cannot be pushed as is without bringing the old history back.

This branch has no `web` disk, no index pages listing and no `Elasticsearch`, so the change is ported instead of cherry-picked. Deviations from the original change, all approved:
- `StorageURLSource::setCredentials` is rewritten to call `checkBasicCredentials`; the check runs before the `try` in `getFirstAvailableURIAndReadBuffer`, and the initiator of `urlCluster` checks all failover options.
- The schema registry check is in `SchemaRegistry::fetchSchema` in `AvroRowInputFormat.cpp`.
- `checkAndNormalizeHeaders` is called instead of `checkHeaders`.
- `HTTPDictionarySource` keeps the `created_from_ddl` field of `Configuration` from #101768, which the original change relies on.
- The changes of the `web` disk, `test_disk_over_web_server`, `Elasticsearch` and `web_index` are dropped, they do not exist on this branch.
- `test_storage_url` gets 11 ported test cases, and `configs/conf.xml` a placeholder `http_forbid_headers`.
kolsha added a commit that referenced this pull request Nov 18, 2026
Carry the conflict resolution of the cherry-pick as a tree onto the rebuilt `backport/26.9/129850` branch: the release branch was rewritten, so the earlier resolution cannot be pushed as is without bringing the old history back.

Deviations from the original change, all approved:
- `HTTPDictionarySource` keeps the `created_from_ddl` field of `Configuration` from #101768, which the original change relies on.
- The `Elasticsearch` hunk and the `test_storage_elasticsearch` changes are dropped, the engine does not exist on this branch.
- `checkAndNormalizeHeaders` is called instead of `checkHeaders`.
- `test_storage_url` gets the helper `server_part_of_error` for the error assertions.
- The redirect fixture of `index_pages_server.py` puts userinfo into `Location` as on master (from #126184), so that `test_url_redirect_userinfo_is_not_sent_with_forbidden_authorization` exercises the redirect with credentials. The masking of the URL in the error of `rejectOriginChangingRedirect` from #126184 is not ported: it is not part of this change, and the branch keeps its existing behavior.
kolsha added a commit that referenced this pull request Nov 18, 2026
Carry the conflict resolution of the cherry-pick as a tree onto the rebuilt `backport/26.8/129850` branch: the release branch was rewritten, so the earlier resolution cannot be pushed as is without bringing the old history back.

Deviations from the original change, all approved:
- `HTTPDictionarySource` keeps the `created_from_ddl` field of `Configuration` from #101768, which the original change relies on.
- The `Elasticsearch` hunk and the `test_storage_elasticsearch` changes are dropped, the engine does not exist on this branch.
- `checkAndNormalizeHeaders` is called instead of `checkHeaders`.
- `test_storage_url` gets the helper `server_part_of_error` for the error assertions.
- The tests use the setting name `allow_experimental_url_wildcard_from_index_pages`, as it is named on this branch.
- The redirect fixture of `index_pages_server.py` puts userinfo into `Location` as on master (from #126184), so that `test_url_redirect_userinfo_is_not_sent_with_forbidden_authorization` exercises the redirect with credentials. The masking of the URL in the error of `rejectOriginChangingRedirect` from #126184 is not ported: it is not part of this change, and the branch keeps its existing behavior.
robot-ch-test-poll3 added a commit that referenced this pull request Nov 18, 2026
Cherry pick #129850 to 26.3: Apply `http_forbid_headers` to Basic credentials sent in the `Authorization` header
robot-clickhouse added a commit that referenced this pull request Nov 18, 2026
…tials sent in the `Authorization` header
robot-ch-test-poll3 added a commit that referenced this pull request Nov 18, 2026
Cherry pick #129850 to 26.8: Apply `http_forbid_headers` to Basic credentials sent in the `Authorization` header
robot-clickhouse added a commit that referenced this pull request Nov 18, 2026
…tials sent in the `Authorization` header
robot-ch-test-poll3 added a commit that referenced this pull request Nov 18, 2026
Cherry pick #129850 to 26.9: Apply `http_forbid_headers` to Basic credentials sent in the `Authorization` header
robot-clickhouse added a commit that referenced this pull request Nov 18, 2026
…tials sent in the `Authorization` header
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 18, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 18, 2026
Backport #129850 to 26.10: Apply `http_forbid_headers` to Basic credentials sent in the `Authorization` header
kolsha added a commit that referenced this pull request Nov 18, 2026
Backport #129850 to 26.3: Apply `http_forbid_headers` to Basic credentials sent in the `Authorization` header
kolsha added a commit that referenced this pull request Nov 18, 2026
Backport #129850 to 26.8: Apply `http_forbid_headers` to Basic credentials sent in the `Authorization` header
kolsha added a commit that referenced this pull request Nov 18, 2026
Backport #129850 to 26.9: Apply `http_forbid_headers` to Basic credentials sent in the `Authorization` header
@clickhouse-gh clickhouse-gh Bot added comp-networking The connection layer under the protocols, on the server and on the client side: socket read / wri... and removed comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-networking The connection layer under the protocols, on the server and on the client side: socket read / wri... pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants