Skip to content

Prefer URL parameter credentials over the Authorization HTTP header - #108980

Merged
alexey-milovidov merged 3 commits into
masterfrom
relax-http-auth-prefer-url-params
Jul 2, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
relax-http-auth-prefer-url-params

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jun 30, 2026 •

Copy link
Copy Markdown
Member

When an HTTP request carries credentials both in the URL query parameters (user/password) and in an HTTP Authorization header, the URL parameters now take precedence and the header is ignored, instead of the request being rejected with:

Code: 516. DB::Exception: Invalid authentication: it is not allowed to use Authorization HTTP header and authentication via parameters simultaneously. (AUTHENTICATION_FAILED)

Why. Once a browser has remembered HTTP Basic credentials for an origin, it attaches the Authorization header to every subsequent request to that origin automatically — including requests that the application has no way to add or remove headers from, such as a form submission or a download navigation. The Web UI (play.html) authenticates by putting the user name and password into the URL query parameters, so such a request would carry both the remembered header and the parameters and be rejected. This is exactly why downloading a result from the Web UI failed with error 516 once the browser had remembered credentials.

The existing Authorization: never sentinel still suppresses the header for requests that can set headers (fetch/XMLHttpRequest, used everywhere else in play.html); this change covers the requests that cannot. The no-mixing rule is unchanged for the other authentication methods (SSL certificate auth, X-ClickHouse-* headers, config credentials).

A stateless test (04490_http_auth_url_params_over_header) sends a bogus Authorization header together with correct URL-parameter credentials and asserts the query runs as the parameter user.

Closes: #108974

Changelog category (leave one):

  • Improvement

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

HTTP interface: when credentials are provided both via URL parameters (user/password) and an Authorization header, the URL parameters now take precedence instead of the request being rejected. This fixes downloading results from the Web UI (play.html) failing with AUTHENTICATION_FAILED (error 516) when the browser has remembered Basic credentials.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

🤖 Generated with Claude Code

Version info

  • Merged into: 26.7.1.408 (included in 26.7 and later)

When a request carries both credentials in the URL query parameters
(`user`/`password`) and an HTTP `Authorization` header, the parameters now take
precedence and the header is ignored, instead of the request being rejected with
"not allowed to use Authorization HTTP header and authentication via parameters
simultaneously" (`AUTHENTICATION_FAILED`).

This is needed because once a browser has remembered HTTP Basic credentials for an
origin, it attaches the `Authorization` header to every subsequent request to that
origin automatically - including requests that the application cannot add or remove
headers from, such as a form submission or a download navigation. The Web UI
(`play.html`) authenticates by putting the user name and password into the URL query
parameters, so such a request would otherwise carry both and be rejected. This made
downloading a result from the Web UI fail with error 516 once Basic credentials had
been remembered by the browser.

The `Authorization: never` sentinel still suppresses the header for requests that can
set headers (`fetch`/`XMLHttpRequest`); this change covers the requests that cannot.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b34045e]

Summary: ✅


AI Review

Summary

This PR changes HTTP authentication so URL user/password parameters take precedence over a non-never Authorization header on the default authentication path, addressing Web UI downloads after the browser has remembered Basic credentials. The current code keeps the configured-handler credential mixing check by using a separate raw has_authorization_header flag, and the added stateless plus integration tests cover the new precedence and the prior configured-credentials regression. I did not find any current blocker or major issue.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jun 30, 2026
alexey-milovidov and others added 2 commits June 30, 2026 22:55
…nd fix the style check

The previous change excluded URL query parameters from `has_http_credentials`
so they take precedence over the `Authorization` header. But that also
suppressed the header for the configured-credentials mixing check: a handler
with its own `<user>` plus URL parameters plus an `Authorization` header was no
longer rejected and instead authenticated as the configured user, contrary to
the stated contract that the no-mixing rule is unchanged for config credentials.

Introduce a separate `has_authorization_header` flag (the raw presence of a
non-`never` `Authorization` header) and use it to keep rejecting the header when
the handler has configured credentials, regardless of the query parameters. The
query-parameter precedence still applies to the default authentication path.

Also reword the comment to avoid the mixed-case `XMLHttpRequest` token, which
the C++ abbreviation style check rejected.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ader

`tests/integration/test_http_auth_config_credentials` covers a custom
`http_handlers` rule with a configured `<user>`: a plain request and a request
with URL parameters both authenticate as the configured user, while an
`Authorization` header - with or without URL parameters - is still rejected as
a mix of authentication methods.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

CI status on b34045ed7b5: 129 success, 1 failure, rest still running.

The sole failure is Stress test (amd_asan_ubsan) = Hung check failed, possible deadlock found — the chronic flake tracked in #107941. Master history confirms it is not caused by this change: 54 occurrences across 41 distinct PRs in the last 7 days (most recent 2026-06-30), and all 10 other stress variants here pass with Failures: 0/4. This PR only touches the per-request credential-precedence decision in authenticateUserByHTTP.cpp (plus tests); it cannot produce a server-side deadlock under concurrent stress that surfaces in a single ASan build only.

The failed job can be re-run once the parent CI run completes. AI Review is ✅ Approve on this head and there are no unresolved review threads.

@clickhouse-gh

clickhouse-gh Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.40% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.70% +0.10%

Changed lines: Changed C/C++ lines covered: 15/15 (100.00%) · Uncovered code

Full report · Diff report

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Follow-up on the CI status: the Stress test (amd_asan_ubsan) Hung check failed flake (#107941) that was the sole failure on b34045ed7b5 has since re-run and is now green (all 12 stress variants pass). The PR is now fully green — the only non-SUCCESS check is CH Inc sync (still PENDING, the private mirror).

Confirming the rest of the state: AI Review is ✅ Approve on this head, there are no unresolved review threads, and the branch is MERGEABLE. Merge base is ~16 hours old, so no re-merge with master is needed.

I independently re-reviewed the authentication logic in authenticateUserByHTTP.cpp: the query-parameter precedence relaxes only the Authorization-header-plus-URL-parameters case on the default path, while every other mixing rejection is preserved — including the else-branch guard (has_config_credentials && has_authorization_header) that keeps rejecting a header when the handler has its own configured credentials, even with URL parameters present. The stateless test 04490_http_auth_url_params_over_header and the four test_http_auth_config_credentials integration cases cover all of these.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Re-triaged the sole non-SUCCESS check, CH Inc sync (still PENDING): the private mirror PR clickhouse-private#62808 (head b34045ed, mergeable) is not actually still running — its single CI run (28482727498) failed at Config Workflow and dropped every downstream job. The root cause is a transient GitHub API outage, not this change or a sync conflict:

error retrieving current user: HTTP 502: 502 Bad Gateway (https://api.github.com/graphql)
ERROR: Failed to get PR data
RuntimeError: Failed to set both GH commit status and PR comment with Workflow Status, cannot proceed

The gh CLI on the private runner could not reach api.github.com (502) at ~23:33–23:35Z, so the setup job errored (exit 1) and marked all builds/tests DROPPED before anything ran. The "Handling Conflicts" text in that log is just an unrendered template — the sync PR reports mergeable: true, so there is no conflict.

I re-ran the failed private workflow; it is now in_progress. The CH Inc sync gate should turn green once it completes.

Everything else is unchanged and green: public CI is fully green (150 SUCCESS / 0 failure / 20 skipped), PR/Mergeable Check/Style check are SUCCESS, AI Review is ✅ Approve on this head, there are no unresolved review threads, and the branch is MERGEABLE. The merge base is ~1 day old and green, so no re-merge with master is needed.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Update on CH Inc sync (now failure, no longer PENDING): the private mirror run 28482727498 (attempt 2) finished with two failing integration-test shards, and all of the failing tests are unrelated to this PR's HTTP-auth change — the PR's own test_http_auth_config_credentials passed. Details:

  • test_keeper_ttl_nodes/test.py::test_many_nodes_with_different_ttls — transient ZooKeeper connection flake; passed on retry.
  • test_distributed_cache/test.py::test_idle_client_ttl — cache-TTL timing flake; passed on retry.
  • test_refreshable_mv_no_multi_read/test.py::test_refreshable_mv_attach_without_multi_read (amd_asan_ubsan, db disk, old analyzer shard) — this is exactly the flake fixed by ClickHouse/clickhouse-private#62942 ("Fix flaky test_refreshable_mv_no_multi_read in db disk mode"), which merged to private master at 22:13Z. This run's merge ref (refs/pull/62808/merge = 4b33c6bd) was cut at ~20:50Z, before that fix, so the test still failed here.

So the failure is fully explained by unrelated flakes, one of which is already fixed on private master. Note that a plain job re-run reuses the pinned stale merge commit and would not pick up #62942; clearing the gate needs a fresh re-sync that recomputes the merge against current private master. No change to this PR is required — public CI is fully green and the AI review is ✅.

@alexey-milovidov alexey-milovidov self-assigned this Jul 2, 2026
@alexey-milovidov
alexey-milovidov merged commit db67ef0 into master Jul 2, 2026
342 of 344 checks passed
@alexey-milovidov
alexey-milovidov deleted the relax-http-auth-prefer-url-params branch July 2, 2026 04:01
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 2, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…prefer-url-params

Prefer URL parameter credentials over the Authorization HTTP header
PedroTadim added a commit that referenced this pull request Oct 19, 2026
Cherry-pick of #120407 onto 26.3.
This branch still has the std::istream HTTP client API, so body_secrets and
requestCredentialSecrets go through its receiveResponse / assertResponseIsOk signatures, the
masked LOG_TRACE goes into the WriteBufferFromHTTP constructor (no WriteBufferFromHTTPRequestSender),
and the master-only cancellation exit in doWithRetries is not taken. StorageURL.cpp gets the
maskURIPassword.h include.
maskURIPassword.h has no maskURIUserinfo / findURIAuthority here, so maskURICredentials uses the
userinfo regular expression and the schema cache table a local startsWithURIScheme check.
05212 drops the bearer-token reflection case: it relies on URL parameter credentials taking
precedence over the Authorization header (#108980),
which this branch does not have.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements 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.

2 participants