Skip to content

Apply http_forbid_headers to credentials sent in the Authorization header - #128998

Closed
kolsha wants to merge 11 commits into
masterfrom
url-userinfo-forbidden-authorization
Closed

kolsha wants to merge 11 commits into
masterfrom
url-userinfo-forbidden-authorization

Conversation

@kolsha

@kolsha kolsha commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Credentials from the userinfo of a URL (http://user:password@host/) and from the CREDENTIALS of an HTTP dictionary are sent as Basic credentials in the Authorization header. When <http_forbid_headers> forbade Authorization, only an explicit headers('Authorization' = ...) was rejected, while these credentials were still sent.

This adds HTTPHeaderFilter::checkBasicCredentials and HTTPHeaderFilter::checkURIUserInfo, which validate a synthetic Authorization header the same way as explicit headers. They are applied to every URL option read by url, urlCluster and the URL engine (a forbidden failover option fails the read instead of being skipped), to url wildcards from index pages, to HTTP dictionaries created by DDL, to the URL of each format_avro_schema_registry_url schema registry request, and to web disks defined in a query (checked before an existing disk with the same definition is reused, and for a cache or encrypted disk over an existing one).

Stored definitions keep loading: a stored wildcard URL table (startup, short ATTACH, replicated replay) is not refused, while RESTORE is checked like a new definition. urlCluster is checked on the workers, under their own configuration, when they read.

The first commit adds the tests, the second contains the fix (the unit test needs the fix to compile).

🤖 Generated with Claude Code

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 the Authorization header, credentials in a URL (http://user:password@host/) used by url, urlCluster, the URL engine, web disks and format_avro_schema_registry_url, and CREDENTIALS of HTTP dictionaries created by DDL, are now rejected instead of being sent in this header.


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

kolsha and others added 2 commits November 3, 2026 14:20
…_forbid_headers

Add an integration test with `Authorization` forbidden in `http_forbid_headers`. It checks that `url`, `urlCluster`, the `URL` engine, the `|` failover syntax, `url` wildcards from index pages, the `HTTP` dictionary source with `CREDENTIALS`, `format_avro_schema_registry_url` and a `web` disk defined in a query reject credentials that would be sent in the `Authorization` header, and that no request with them reaches the server.

Also add unit test cases for `HTTPHeaderFilter::checkBasicCredentials` and `HTTPHeaderFilter::checkURIUserInfo`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…on header

The userinfo of a URL (`http://user:password@host/`) and the `CREDENTIALS` of an `HTTP` dictionary are sent as Basic credentials in the `Authorization` header, but this header was not checked against `http_forbid_headers`. Forbidding `Authorization` rejected only an explicit `headers('Authorization' = ...)`.

Add `HTTPHeaderFilter::checkBasicCredentials` and `HTTPHeaderFilter::checkURIUserInfo`, which run a synthetic `Authorization` header through `checkHeaders`, and call them where such credentials are used: for every URL option read by `url`, `urlCluster` and the `URL` engine (outside of the failover handling, so that a forbidden option fails the read instead of being skipped), for `url` wildcards from index pages, for the `HTTP` dictionary source created by DDL, for `format_avro_schema_registry_url` and for a `web` disk defined in a query.

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

clickhouse-gh Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4b59a24]

Summary: ❌

job_name test_name status info comment
La Casa Del Dolor (amd_debug) FAIL
Logical error: CreationTID of part A (table B) is set to unexpected value C, it's a bug. Current transaction: D (STID: 4605-4c8e) FAIL cidb

AI Review

Summary

The PR applies http_forbid_headers to implicit Basic authentication from URL userinfo and DDL-defined HTTP dictionary credentials. Reviewed head 4b59a24e89bb46dcf2374ccb4adc55e2dcecd336 and all prior discussion. No new code defect was identified; the existing request for independent web disk regression coverage remains unresolved.

Missing context / blind spots
  • ⚠️ The current head's integration results are not yet available in the Praktika report. No local runtime tests were run; a completed targeted integration run would establish whether the added cases pass.
Findings

⚠️ Majors

  • ReadBufferFromWebServer.cpp:123 and WebObjectStorage.cpp:437: The policy must prevent authenticated metadata probes and file reads independently of directory listing. All added forbidden-wildcard cases fail earlier in MetadataStorageFromIndexPages::tryListDirectory; no added case directly exercises a web disk. Removing both guards would therefore leave the new tests passing while permitting forbidden authentication through registered disks and wrappers. This remains the existing unresolved finding; no duplicate inline comment was posted.
Tests
  • ⚠️ Add focused regressions for the metadata-probe and file-read paths using a credential-bearing web disk registered before forbidding Authorization through config reload. Each case should first demonstrate successful authenticated requests, then assert rejection and zero authenticated requests. Keep metadata available for the file-read case so an earlier listing or probe cannot mask a missing file-read guard. Reuse an existing integration cluster.
Final Verdict

⚠️ Request changes — Add the two independent web disk guard regressions and obtain passing targeted integration results.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 3, 2026
Comment thread src/Formats/FormatFactory.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... label Nov 3, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 4b59a24e8 with master 5fdd3cea3 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 86abc2f7f; 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.

Compile time of recompiled translation units

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

Job report

kolsha and others added 2 commits November 3, 2026 20:33
…st `http_forbid_headers`

Add a case where `format_avro_schema_registry_url` has no authority and so no userinfo, while the URL of the schema request resolved from its path has one. The error is expected when the schema is fetched.

Add a case where a `web` disk with a userinfo in its endpoint is created while `Authorization` is allowed, and a `CREATE TABLE` with the same definition reuses it after `SYSTEM RELOAD CONFIG` forbids `Authorization` again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d `web` disk

`ConfluentSchemaRegistry` resolves the URL of a request from the path of `format_avro_schema_registry_url`, so for a URL without an authority, such as `http:http://user:password@host/`, the request URL has a userinfo that the URL checked in `getFormatSettings` has not. Check the URL of each request in `ConfluentSchemaRegistry::applyAuth`, with the filter of the global context, as the format has no context. The remote host filter is not added there: for a base URL with a host, the appended path starts with `/`, so the request URL keeps the host and the userinfo of the base URL.

The endpoint of a `web` disk was checked in the object storage factory, which `Context::getOrCreateDisk` does not call for an existing disk, so a definition equal to that of a disk loaded from existing metadata, or created before `Authorization` was forbidden, was not checked. Move the check to `validateResolvedWebDiskEndpoints`, called in `getOrCreateCustomDisk` before the disk is looked up for every definition not loaded from existing metadata, as for the `Enforce` level of the remote host filter check. It reads the endpoint with `getWebObjectStorageEndpoint`, extracted from the factory.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kolsha and others added 4 commits November 4, 2026 09:39
…ttp_forbid_headers`

Add a case where a `web` disk with a userinfo in its endpoint is created while `Authorization` is allowed, and a new `cache` disk that names it is defined after `SYSTEM RELOAD CONFIG` forbids `Authorization` again. The definition is expected to fail with the forbidden header error before the `cache` disk is created, so that no table reads the endpoint through it.

The creation of a `web` disk without a table is moved to a helper shared with the case of a reused `web` disk, and each case creates its own disk.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…he` or `encrypted` disk

A `cache` or `encrypted` disk names the disk it wraps with the `disk` key and uses that disk as it is, so a new `cache` disk over a `web` disk created before `Authorization` was forbidden, or loaded from existing metadata, sent the userinfo of its endpoint in the `Authorization` header. `validateResolvedWebDiskEndpoints` checked only the endpoints of the definition itself.

For a definition not loaded from existing metadata, look up the disk named by `disk` and, if it was created from user SQL, follow it through `encrypted` and `cache` layers to its `web` object storage and check the userinfo of its URLs. As in `getCustomDiskServerIdentity`, the walk stops at a disk from the server configuration, whose endpoint is not user input.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… against `http_forbid_headers`

Replace the `format_avro_schema_registry_url` case, which read another format, by a read of `AvroConfluent` that requests the schema, and expect the error when the schema is fetched, for a URL with a userinfo as for a URL without an authority.

Add a case where a `URL` table with a wildcard and a userinfo in its URL is created while `Authorization` is allowed. After `SYSTEM RELOAD CONFIG` forbids `Authorization` again, a short `ATTACH` of its stored definition is expected to succeed, and a fresh `CREATE TABLE` with the same definition to fail with the forbidden header error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ldcard `URL` tables

Remove the check of the userinfo of `format_avro_schema_registry_url` from `getFormatSettings`, which builds the settings of every format, so that a query that requests no schema is not refused for it. The userinfo is still checked for the URL of each request in `ConfluentSchemaRegistry::applyAuth`.

A `URL` table with a wildcard is served by `StorageWebConfiguration`, whose `check` refused a userinfo forbidden by `http_forbid_headers` for any definition, so a stored one, for example on server startup or a short `ATTACH`, could not load. Add `StorageWebConfiguration::check_userinfo` and clear it in `registerStorageURL` for a replayed definition that is not restored from a backup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Storages/StorageURL.cpp Resolved
…ntials

The checks of the previous commits were made when an object was defined, and every
new path to the same request was a new bypass, e.g. a stored wildcard `URL` table.
Observe the requests themselves: the index-page server of `test_storage_url` counts
the requests that carry `Authorization`, and every case has a positive control with
the header allowed. A stored wildcard `URL` table still attaches, but its reads are
refused, and the userinfo of a redirect `Location` is not sent.

The cases move from their own module to `test_storage_url`, which already has the
server, the cluster for `urlCluster` and `http_forbid_headers`. The unit test is
dropped in favour of the integration test.
…ets them

Checking the userinfo when a table, disk or wrapper is defined missed every path
that reaches the same request without that definition: stored wildcard `URL`
tables, `MergeTree` tables on a `web` disk after a restart, and consumers of an
existing disk by name. `setCredentialsFromURL` is the only place where a userinfo
becomes credentials, right before each request, so it now takes the
`HTTPHeaderFilter` and refuses a userinfo with a username when `Authorization` is
forbidden. Stored objects keep loading, and each request is refused before it is
sent, also after `SYSTEM RELOAD CONFIG`. A forbidden failover option fails the
operation instead of being skipped.

This replaces the definition-time checks of `web` disks, the disk wrapper walk and
the `check_userinfo` flag. The Avro schema registry keeps its check in `applyAuth`,
without a branch for a missing global context, which every program parsing formats
creates.
setCredentialsFromURL(credentials, uri);
/// credentials — happens in `nextImpl`, long after `initialize` returns. Outside of the `try` below: an option
/// whose credentials <http_forbid_headers> forbids must fail the read, not fall through to the next one.
setCredentialsFromURL(credentials, uri, context->getHTTPHeaderFilter());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Exercise the independent web disk request guards

The new forbidden-wildcard cases throw from MetadataStorageFromIndexPages::tryListDirectory before either WebObjectStorage::tryGetObjectMetadata or ReadBufferFromWebServer::initialize runs. None of the other added cases uses a web disk. Consequently, removing the credential checks from both of those methods would leave all added tests passing, although disks already registered or referenced through wrappers could send the forbidden Authorization header again.

Please add focused regressions that reach the metadata probe and file-read paths independently, using a credential-bearing disk registered while the header is allowed and reused after the configuration reload. Include successful authenticated requests as positive controls and assert zero authenticated requests when the header is forbidden. For the file-read case, keep the metadata available so an earlier listing/probe rejection cannot hide missing enforcement here. These cases can reuse an existing integration cluster.

`{a|b}` in the authority is expanded only by a wildcard read from index pages, so a
plain `url` read failed to parse the URI before any request. Failover options of a
plain read are separated by `|`.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=128998&sha=e02da536bf27299a8da36b440acc0dbc8dd602ff&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20flaky%29
PR: #128998
@kolsha kolsha closed this Nov 11, 2026
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-ClickHouse__ClickHouse that referenced this pull request Nov 11, 2026
…` 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]>
@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

comp-networking The connection layer under the protocols, on the server and on the client side: socket read / wri... pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant