Skip to content

Enable CORS in clickhouse-local by default - #115045

Merged
alexey-milovidov merged 1 commit into
masterfrom
clickhouse-local-cors
Aug 17, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
clickhouse-local-cors

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 16, 2026 •

Copy link
Copy Markdown
Member

clickhouse-local can serve HTTP after SYSTEM START LISTEN HTTP, but it normally runs without a config file, so it had no http_options_response section and answered the CORS preflight with a bare 204 carrying no Access-Control-* headers. A browser therefore refuses every cross-origin request to it - including the Web UI opened from a file:// URL, whose origin is null.

Now clickhouse-local sets the same default http_options_response headers that the clickhouse-server configuration ships (Access-Control-Allow-Origin: * and friends). A configuration file with its own http_options_response section still replaces them entirely, and the headers are sent only for requests that carry an Origin, exactly as in clickhouse-server.

Note the implication, which is now documented next to the existing security warning for the listeners: while an HTTP listener is open, any web page you visit can query the local instance over the loopback address and read the results.

Changelog category (leave one):

  • Improvement

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

clickhouse-local now answers CORS preflight requests with the same permissive headers as clickhouse-server, so the HTTP interface opened by SYSTEM START LISTEN HTTP can be used from a browser out of the box, including the Web UI opened from a file:// URL.

Version info

  • Merged into: 26.8.1.1522 (included in 26.8 and later)

`clickhouse-local` can serve HTTP after `SYSTEM START LISTEN HTTP`, but it
normally runs without a config file, so it had no `http_options_response`
section and answered the CORS preflight with a bare `204` carrying no
`Access-Control-*` headers. A browser therefore refuses every cross-origin
request to it - including the web UI opened from a `file://` URL, whose
origin is `null`.

Set the same default `http_options_response` headers that the
`clickhouse-server` configuration ships. A configuration file with its own
`http_options_response` section still replaces them entirely.

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

clickhouse-gh Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7c82bdc]

Summary: ✅


AI Review

Summary

This PR makes clickhouse-local inject the default http_options_response CORS headers so SYSTEM START LISTEN HTTP works from browser clients, and it documents the security implication. The main behavior change is reasonable, but I found one real config-surface regression and one gap in the new regression test, so I would not merge it as-is.

PR Metadata
  • Changelog category: Improvement matches the user-facing behavior change.
  • Changelog entry: required for Improvement, present, and specific enough for the actual change.
Findings

⚠️ Majors

  • [programs/local/LocalServer.cpp:1790] The new defaulting logic only notices a real http_options_response section. clickhouse-local also accepts extra config through the post--- surface, and argsToConfig stores http_options_response.header[...] as flat keys without creating the parent node. In that case this branch still runs and overwrites the operator's custom CORS header with the permissive default *, so an attempt to tighten CORS from the CLI is silently ignored.
    Suggested fix: before inserting defaults, also detect existing keys with the http_options_response. prefix, or materialize the parent node when importing those CLI config keys.
Tests
  • ⚠️ [tests/queries/0_stateless/04908_clickhouse_local_http_cors.sh:39-43] The new test proves only Access-Control-Allow-Origin, but the promised browser path also depends on the preflight allowing the requested Authorization header (and POST). As written, the test would still pass if Access-Control-Allow-Headers lost Authorization, and the file:// web UI would still fail.
Final Verdict

Request changes.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.80% 86.80% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.10% 79.10% +0.00%

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

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Aug 16, 2026
Comment thread programs/local/LocalServer.cpp Resolved
@nikitamikhaylov nikitamikhaylov self-assigned this Aug 16, 2026
Comment thread programs/local/LocalServer.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 7c82bdc59 with master 4706e4ed8 (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
Binary Master PR Δ
programs/clickhouse-stripped 694.66 MiB 691.65 MiB -3.01 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

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

Job report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 17, 2026
Merged via the queue into master with commit d4655dd Aug 17, 2026
181 checks passed
@alexey-milovidov
alexey-milovidov deleted the clickhouse-local-cors branch August 17, 2026 04:06
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 17, 2026
@mintlify

mintlify Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
ClickHouse-docs 🔴 Failed – Aug 17, 2026, 5:18 PM

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.

3 participants