Repository navigation
fix(generators): Validate table and column options as SQL identifiers - #103
Merged
Merged
Conversation
The table and index strategy generators interpolate --source-table-name, --source-columns and --table-name verbatim into the migration's CREATE TABLE / CREATE TRIGGER SQL. A name with punctuation produced broken or surprising DDL that only surfaced when the migration ran. Both generators now check every name against a plain-identifier pattern (letters, digits, underscores, not starting with a digit) and fail with a clear Thor error before writing anything. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A security review noted that the table and index strategy generators interpolate
--source-table-name,--source-columns, and--table-nameverbatim into the generated migration'sCREATE TABLE/CREATE TRIGGERSQL. There is no realistic attacker — the input is the developer's ownrails gcommand line and the migration is written for review — but a name with punctuation produced broken or surprising DDL that only surfaced when the migration ran. Hostile-looking names should fail closed instead.What
Metka::Generators::SqlIdentifiermodule checks each option value against/\A[a-zA-Z_][a-zA-Z0-9_]*\z/.generate_migrationand raiseThor::Errornaming the offending option — Thor prints it as a clean CLI error and nothing is generated. In the index generator the check runs before the PostgreSQL skip, so bad input is reported on either adapter.Tests
exit_on_failure?is false for Rails generators, so Thor reports the error on stderr rather than raising — the tests capture stderr).🤖 Generated with Claude Code