Validate post_type and collection titles to prevent ERB injection in generated views - #80
Merged
Merged
Conversation
Titles are interpolated directly into generated ERB view code (e.g. the link_to line appended to the shared nav partial by bunko:add), so a title containing double quotes, ERB delimiters, or newlines could corrupt or inject code into generated templates. Fix at the source: Bunko::Configuration now raises ArgumentError for titles containing double quotes, <% or %>, or newlines/carriage returns. Validation runs after the customizer block in both #post_type and #collection, so titles set via the block form are covered as well as titles passed as keyword arguments or auto-generated from names. Safe titles (apostrophes, ampersands, unicode, typographic quotes) are unaffected. Closes #60 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CAFZmU5SJSERBVyedpsYQW
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.
Summary
Closes #60
Post type and collection titles are interpolated directly into generated ERB view code — most notably the
link_to "#{title}", #{path_helper}line thatbunko:addappends to the shared nav partial (lib/tasks/bunko/add.rake). A title containing", ERB delimiters, or newlines could corrupt or inject code into the generated templates.Per the issue, this fixes the problem at the source:
Bunko::Configurationnow validates titles and raisesArgumentErrorfor titles containing:")<%or%>)Implementation
validate_title!method toBunko::Configuration, following the existingArgumentErrorstyle and message tone used for name validation.#post_typeand#collection, after the customizer block executes, so all three code paths are covered: auto-generated titles,title:keyword arguments, and titles set via thePostTypeCustomizer/CollectionCustomizerblock form (block values override params, so validating after the block catches the final value).<,>,%characters all still work.Tests
Added
test/configuration/title_validation_test.rb(26 tests) covering:",<%,%>,\n, and\rin titles — for bothpost_typeandcollection, via keyword argument and via the customizer blockTest results
bundle exec rake(Ruby 4.0.2): 389 runs, 1389 assertions, 0 failures, 0 errors, 1 skip (skip is pre-existing)bundle exec standardrb: clean, exit 0🤖 Generated with Claude Code
https://claude.ai/code/session_01CAFZmU5SJSERBVyedpsYQW
Generated by Claude Code