Skip to content

Improve HTTP header filtering - #87172

Merged
Algunenano merged 5 commits into
ClickHouse:masterfrom
Algunenano:public_improve_http_header_validation
Sep 29, 2025
Merged

Algunenano merged 5 commits into
ClickHouse:masterfrom
Algunenano:public_improve_http_header_validation

Conversation

@Algunenano

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC) or LOGICAL_ERROR

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

The function checkHeaders is now properly validating the provided headers and reject forbidden headers. Original author: Michael Anastasakis (@michael-anastasakis)

Detailed Description

The function checkHeaders responsible for filtering forbidden headers is not properly validating the provided headers. The function does not strip the entries from whitespace or special characters.

This leads to situations where queries that are meant to fail like the ones below bypass the validation.

Expected blocked request

clickhouse-cloud :) SELECT * FROM url(
    'http://google.com',
    'RawBLOB',
    'data String',
    headers('metadata'='true')
)
SETTINGS use_hive_partitioning=0;

SELECT *
FROM url('http://google.com', 'RawBLOB', 'data String', headers('metadata' = 'true'))
SETTINGS use_hive_partitioning = 0

Query id: 87456ee7-52ef-4237-9bc9-300eac3af204


Elapsed: 0.299 sec.

Received exception from server (version 25.9.1):
Code: 36. DB::Exception: Received from eg9tlk4b42.westus3.azure.clickhouse-dev.com:9440. DB::Exception: HTTP header "metadata" is forbidden in configuration file, see <http_forbid_headers>. (BAD_ARGUMENTS)

Query that bypass the check

clickhouse-cloud :) SELECT * FROM url(
    'http://google.com',
    'RawBLOB',
    'data String',
    headers('metadata\t'='true','metadata\t'='true')
)
SETTINGS use_hive_partitioning=0;

SELECT *
FROM url('http://google.com', 'RawBLOB', 'data String', headers('metadata\t' = 'true', 'metadata\t' = 'true'))
SETTINGS use_hive_partitioning = 0

Query id: 2f6a485e-5ab0-4c6b-8e2b-4437b71acf58


Elapsed: 0.342 sec.

Received exception from server (version 25.9.1):
Code: 86. DB::Exception: Received from eg9tlk4b42.westus3.azure.clickhouse-dev.com:9440. DB::Exception: Received from c-yellow-bo-11-server-bihrwa0-0.c-yellow-bo-11-server-headless.ns-yellow-bo-11.svc.cluster.local:9000. DB::Exception: Received error from remote server http://google.com/. HTTP status code: 400 'Bad Request', body length: 1555 bytes, body: '<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 400 (Bad Request)!!1</title>
[..SNIPPET..]

@clickhouse-gh

clickhouse-gh Bot commented Sep 16, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0837b05]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_binary, ParallelReplicas, s3 storage, parallel) failure
02943_use_full_text_skip_index_with_has_any FAIL
00933_ttl_simple FAIL
00314_sample_factor_virtual_column FAIL
Exception in test runner FAIL
Killed by signal (in clickhouse-server.log or clickhouse-server.err.log) FAIL
Fatal messages (in clickhouse-server.log or clickhouse-server.err.log) FAIL
Stateless tests (amd_ubsan, parallel) failure
03040_dynamic_type_alters_2_compact_merge_tree FAIL
Stress test (arm_asan) failure
Server died FAIL
Hung check failed, possible deadlock found (see hung_check.log) FAIL
Killed by signal (in clickhouse-server.log) FAIL
Fatal message in clickhouse-server.log (see fatal_messages.txt) FAIL
Killed by signal (output files) FAIL

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-cloud labels Sep 16, 2025
@yakov-olkhovskiy yakov-olkhovskiy self-assigned this Sep 20, 2025
@Algunenano

Copy link
Copy Markdown
Member Author

@Algunenano
Algunenano added this pull request to the merge queue Sep 29, 2025
Merged via the queue into ClickHouse:master with commit 12a3df2 Sep 29, 2025
@Algunenano
Algunenano deleted the public_improve_http_header_validation branch September 29, 2025 09:37
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 29, 2025
@robot-clickhouse robot-clickhouse added pr-backports-created-cloud deprecated label, NOOP pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Sep 29, 2025
clickhouse-gh Bot added a commit that referenced this pull request Sep 29, 2025
Backport #87172 to 25.8: Improve HTTP header filtering
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 29, 2025
clickhouse-gh Bot added a commit that referenced this pull request Sep 29, 2025
Backport #87172 to 25.7: Improve HTTP header filtering
Algunenano added a commit that referenced this pull request Sep 29, 2025
Backport #87172 to 25.9: Improve HTTP header filtering
Algunenano added a commit that referenced this pull request Sep 30, 2025
Backport #87172 to 25.3: Improve HTTP header filtering
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-backports-created-cloud deprecated label, NOOP pr-critical-bugfix 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.

4 participants