Skip to content

fix(install): make the database identifier validators reject bad input - #2481

Open
elcreator wants to merge 3 commits into
evolution-cms:3.5.xfrom
elcreator:fix-installer-validators
Open

elcreator wants to merge 3 commits into
evolution-cms:3.5.xfrom
elcreator:fix-installer-validators

Conversation

@elcreator

Copy link
Copy Markdown

Summary

The web installer's identifier validators never rejected anything. validateDbName(), validateDbCollation() and validateTablePrefix() failed only when preg_match(...) === false, which happens on a regex error, not on a mismatch (0). The unchecked values reached:

  • CREATE DATABASE, where the collation went in unquoted on MySQL
  • SELECT COUNT(*) FROM {prefix}site_content in the connection test and summary
  • the generated core/config/database/connections/default.php: install.php wrote $_POST['tableprefix'] without validating it at all

The installer only runs before a site is installed, with database credentials the person running it supplies, so the practical impact is limited. The checks were still no-ops.

Changes

  • Validators require a match.
    • Database names allow [A-Za-z0-9_$-], up to 63 characters. A leading digit and $ are accepted so existing databases still upgrade.
    • Collations may contain @ (PostgreSQL sr_RS@latin) or be empty.
    • The collation error message said "Database name"; it now says "Database collation".
  • connection/databasetest.php now validates the collation, which it read raw. A rejected value is reported as the installer's red "failed!" status instead of a PHP fatal with a stack trace.
  • install.php validates the table prefix before writing it to the config.
  • Legacy assets/modules/store/installer/instprocessor.php (deprecated, no longer included; the store uses instprocessor-fast.php):
    • row ids are cast to int
    • package event names are escaped
    • an undefined $dbase. that made a DELETE invalid is removed

Not changed

validateDbUser() and validateAdminUsername() have the same === false bug. Their values only reach PDO and the ORM, not SQL text, and enforcing their current patterns would reject names in use today, such as DB users with - or . and email-style admin names. Worth a separate decision.

Test plan

  • InstallerIdentifierValidationTest (34 tests): accepts real MySQL, PostgreSQL and SQLite names and collations; rejects quote, backtick, ;, comment, path and PHP payloads; checks the call sites. 16 of these fail on 3.5.x.
  • tests/Unit/Install green.
  • Manually on a fresh SQLite installer: the database test reports "failed!" for x; DROP TABLE evo_users; -- as prefix, ../../evil as name and utf8'; -- as collation, and passes evo_ / evolution / utf8.

🤖 Generated with Claude Code

elcreator and others added 3 commits September 26, 2026 23:06
validateDbName(), validateDbCollation() and validateTablePrefix() failed
only when preg_match() returned false, which happens on a regex error, not
on a mismatch - so they accepted anything. The values reach CREATE DATABASE
(the collation unquoted on MySQL), SELECT ... FROM {prefix}site_content and
the generated connection config.

- The three validators now require a match. Database names may start with a
  digit and contain $ so existing databases still upgrade; collations may
  contain @ (sr_RS@latin) or be empty.
- The connection test validates the collation, which it read raw, and
  reports a rejected value as a failed check instead of a PHP fatal.
- install.php validates the table prefix it writes into the config.

validateDbUser() and validateAdminUsername() share the bug but only reach
PDO and the ORM; enforcing them would reject names in use today.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rocessor

instprocessor.php is deprecated and no longer included (the store uses
instprocessor-fast.php), but it still interpolated row ids and package
event names into SQL. Ids are cast to int, event names escaped, and an
undefined $dbase that made the tmplvar-templates DELETE invalid is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant