Skip to content

fix(core): ssl_ca TLS insertion breaks database.php via commented PostgreSQL block - #475

Merged
ostefano merged 2 commits into
MISP:masterfrom
alesnav:fix/database-tls-ssl-ca-commented-postgres-block
Oct 23, 2026
Merged

ostefano merged 2 commits into
MISP:masterfrom
alesnav:fix/database-tls-ssl-ca-commented-postgres-block

Conversation

@alesnav

@alesnav alesnav commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Problem

When starting misp-core with MYSQL_TLS=true and MYSQL_TLS_CA set (external DB over TLS, e.g. Azure MySQL Flexible / AWS RDS), the container crashes in a loop:

Error: syntax error, unexpected single-quoted string "ssl_ca", expecting "function"

Root cause

core/files/init_misp.sh → update_database_tls_config(). When the TLS key does not yet exist in database.php, it is inserted with:

sed -E "/public[[:space:]]+\$default[[:space:]]*=[[:space:]]*\[/a\
    '${key}' => '${value}',"

The address /public\s+\$default\s*=\s*\[/ is not anchored, and app/Config/database.default.php ships two matching lines:

35:    public $default = [          // active MySQL config
54:    // public $default = [       // commented-out PostgreSQL example

So the a\ (append) runs on both, inserting 'ssl_ca' => '...' inside the commented PostgreSQL block but outside the //, producing invalid PHP and the crash above.

Fix

Anchor the sed address to the start of the line (^[[:space:]]*public) so only the active, non-commented $default block matches:

sed -E "/^[[:space:]]*public[[:space:]]+\$default[[:space:]]*=[[:space:]]*\[/a\
    '${key}' => '${value}',"

One-character-class change, no behaviour change for the normal (single, non-commented) case.

Verification

Tested against the real database.default.php from misp-core:v2.5.50 with php -l:

ssl_ca insertions php -l
before (unanchored) 2 (one inside the commented block) ❌ Errors parsing
after (anchored) 1 (active block only) ✅ No syntax errors detected

Reproduces on misp-core 2.5.x with MYSQL_TLS=true + MYSQL_TLS_CA pointing at an externally managed MySQL. Same applies to ssl_cert / ssl_key.

update_database_tls_config inserts the TLS key (ssl_ca/ssl_cert/ssl_key)
after every line matching `public $default = [`. database.default.php ships
TWO such lines: the active MySQL one and a COMMENTED-OUT PostgreSQL example
(`// public $default = [`). The unanchored sed address matches both, so the
key is also inserted inside the commented block but OUTSIDE the `//`,
producing invalid PHP:

  Error: syntax error, unexpected single-quoted string "ssl_ca", expecting "function"

Anchor the address to the start of line (`^[[:space:]]*public`) so only the
active, non-commented $default block is matched. Verified with `php -l`:
before = 2 insertions + parse error; after = 1 insertion + no syntax errors.

Reproduces with MYSQL_TLS=true + MYSQL_TLS_CA set against an external DB
(e.g. Azure MySQL Flexible) on misp-core 2.5.x.
@ostefano

Copy link
Copy Markdown
Collaborator

Please rebase

@alesnav

alesnav commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

branch updated

@ostefano
ostefano merged commit 779bc19 into MISP:master Oct 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants