Skip to content

Conversation

@dereuromark
Copy link
Member

@dereuromark dereuromark commented Jan 19, 2026

Summary

This PR addresses several release readiness issues identified in the 5.x branch:

First commit fixes:

  • Seed dependency cycle detection: Added proper cycle detection to orderSeedsByDependencies() to prevent infinite recursion when seeds have circular dependencies. Now throws a RuntimeException with a clear message showing the cycle path.

  • Column unsigned option: Added 'unsigned' to valid column options for API consistency. Previously only 'signed' was valid, requiring users to call setUnsigned() directly.

  • SQL injection fix: Replaced unsafe addslashes() with proper driver escaping (schemaValue()) for column comments in MysqlAdapter::getRenameColumnInstructions().

  • DumpCommand fix: Fixed non-existent $io->error() method call (should be $io->err()).

  • SQL Server documentation: Documented check constraints as unsupported for SQL Server adapter with improved error messages guiding users to use raw SQL via $this->execute().

Second commit fixes (from deep dive analysis):

  • Safer deserialization: Restricted unserialize() in BakeMigrationDiffCommand to only allow safe CakePHP schema classes, mitigating potential RCE.

  • strpos() logic bug: Fixed strpos() returning false when match is at position 0 by using str_contains() instead.

  • Path traversal prevention: Added validation for --source option to prevent directory traversal attacks.

  • Uninitialized property: Initialized $command property in Migrations.php to prevent access errors.

  • Strict comparison: Fixed weak equality (!=) to strict equality (!==) in Table::saveData() for array key comparison.

  • Copy-paste bug: Fixed Migrator::shouldDropTables() which was using $messages['down'] instead of $messages['missing'].

  • Production-safe error handling: Replaced assert() calls with explicit RuntimeException in BaseSeed since assertions can be disabled in production.

Test plan

  • PHPStan passes with no errors
  • PHPCS passes with no errors
  • All existing tests pass (CI running)
  • Manual testing of seed circular dependency detection
  • Manual testing of column unsigned option via setOptions()

- Add cycle detection to seed dependency ordering to prevent infinite
  recursion when seeds have circular dependencies
- Add 'unsigned' to valid column options for API consistency with 'signed'
- Fix SQL injection vulnerability in MysqlAdapter by replacing addslashes()
  with proper driver escaping for column comments
- Fix non-existent $io->error() method call in DumpCommand (should be err())
- Document SQL Server check constraints as unsupported with improved error
  messages guiding users to use raw SQL
- Restrict unserialize() to safe CakePHP schema classes only
- Fix strpos() logic bug by using str_contains()
- Validate --source option to prevent path traversal
- Initialize $command property to prevent uninitialized access
- Fix weak equality (!=) to strict (!==) in Table::saveData()
- Fix copy-paste bug in Migrator (was using 'down' instead of 'missing')
- Replace assert() with explicit RuntimeException in BaseSeed
TableSchema contains nested Column, Index, Constraint and other
schema objects that also need to be allowed for deserialization.
@dereuromark dereuromark merged commit a6f66aa into 5.x Jan 20, 2026
14 checks passed
@dereuromark dereuromark deleted the fix/release-readiness-issues branch January 20, 2026 04:20
dereuromark added a commit that referenced this pull request Jan 20, 2026
This backports several important bug fixes from recent 5.x PRs:

**From PR #1001 (Fix release readiness issues for 5.x):**

- Fix copy-paste bug in Migrator::shouldDropTables() using $messages['down']
  instead of $messages['missing']
- Fix uninitialized $command property in Migrations.php
- Fix weak equality in Table::saveData() (use !== instead of !=)
- Replace assert() with explicit RuntimeException in BaseSeed for
  production safety
- Fix DumpCommand using non-existent $io->error() method (should be $io->err())
- Replace unsafe addslashes() with proper driver escaping (schemaValue())
  for column comments in MysqlAdapter::getRenameColumnInstructions()

**From PR #1002 (Quote database names in PostgreSQL and SQL Server adapters):**

- PostgresAdapter: Quote database name and charset in createDatabase()
- PostgresAdapter: Quote database name in dropDatabase()
- SqlserverAdapter: Use quoteSchemaName() instead of manual brackets in
  createDatabase() and dropDatabase()
- SqlserverAdapter: Fix SQL injection vulnerability in dropDatabase()

**From PR #1003 (Improve SQL quoting and fix docblock issues):**

- SqlserverAdapter: Use quoteString() for sp_rename parameters in
  getRenameTableInstructions() and getRenameColumnInstructions()
- PostgresAdapter/SqlserverAdapter: Use quoteColumnName() for foreign key
  column definitions instead of hard-coded double quotes
markstory pushed a commit that referenced this pull request Jan 21, 2026
This backports several important bug fixes from recent 5.x PRs:

**From PR #1001 (Fix release readiness issues for 5.x):**

- Fix copy-paste bug in Migrator::shouldDropTables() using $messages['down']
  instead of $messages['missing']
- Fix uninitialized $command property in Migrations.php
- Fix weak equality in Table::saveData() (use !== instead of !=)
- Replace assert() with explicit RuntimeException in BaseSeed for
  production safety
- Fix DumpCommand using non-existent $io->error() method (should be $io->err())
- Replace unsafe addslashes() with proper driver escaping (schemaValue())
  for column comments in MysqlAdapter::getRenameColumnInstructions()

**From PR #1002 (Quote database names in PostgreSQL and SQL Server adapters):**

- PostgresAdapter: Quote database name and charset in createDatabase()
- PostgresAdapter: Quote database name in dropDatabase()
- SqlserverAdapter: Use quoteSchemaName() instead of manual brackets in
  createDatabase() and dropDatabase()
- SqlserverAdapter: Fix SQL injection vulnerability in dropDatabase()

**From PR #1003 (Improve SQL quoting and fix docblock issues):**

- SqlserverAdapter: Use quoteString() for sp_rename parameters in
  getRenameTableInstructions() and getRenameColumnInstructions()
- PostgresAdapter/SqlserverAdapter: Use quoteColumnName() for foreign key
  column definitions instead of hard-coded double quotes
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.

3 participants