ClickHouse / ClickHouse/ClickHouse

Auto-escape special XML characters for from_env/from_zk substitutions

Open
#78,835 0 comments 6 reactions 0 assignees View on GitHub
comp-config external unfinished code
Dominant language
C++
Stars
49.9k
Forks
9k
Avg merge
21h 32m
Merged PRs (30d)
515

Description

### Company or project name

_No response_

### Describe the unexpected behaviour

When using `from_env` or `from_zk` in configuration files, environment variables containing XML special characters (`&`, `<`, `>`, etc.) cause parsing failures. ClickHouse builds a temporary XML snippet like `...env_value...`, which breaks unless values are manually escaped or wrapped in ``.

### How to reproduce

Set an environment variable with XML-reserved characters, e.g. export `MY_ENV_VAR="&<>!"`.

In your config, use ``.

Start ClickHouse.

Observe the parsing error (Invalid token in line 1 column X).

### Expected behavior

ClickHouse should automatically escape special characters, ensuring valid XML is passed to the parser without requiring manual entity replacement or CDATA.

### Error message and/or stacktrace

```
Processing configuration file '/etc/clickhouse-server/config.xml'.
Merging configuration file '/etc/clickhouse-server/config.d/test.xml'.
Poco::Exception. Code: 1000, e.code() = 0, Exception: Failed to preprocess config '/etc/clickhouse-server/config.xml': SAXParseException: Invalid token in line 1 column 12, Stack trace (when copying this message, always include the lines below):

0. DB::ConfigProcessor::processConfig(bool*, zkutil::ZooKeeperNodeCache*, std::shared_ptr const&, bool) @ 0x0000000014664288
1. DB::ConfigProcessor::loadConfig(bool, bool) @ 0x0000000014664af7
2. BaseDaemon::initialize(Poco::Util::Application&) @ 0x000000000e07c0b9
3. DB::Server::initialize(Poco::Util::Application&) @ 0x000000000dfcce1b
4. Poco::Util::Application::run() @ 0x000000001748045a
5. DB::Server::run() @ 0x000000000dfccb30
6. mainEntryClickHouseServer(int, char**) @ 0x000000000dfc9ab3
7. main @ 0x0000000008baa8e1
8. ? @ 0x00007f1ddca111ca
9. ? @ 0x00007f1ddca1128b
10. _start @ 0x000000000677702e
(version 25.1.6.34 (official build))
```

### Additional context

W/A: Manually replace special characters with valid XML entities or use CDATA in environment variables.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.