Uh oh!
There was an error while loading. Please reload this page.
Clamp non-positive page and per_page params to their defaults - #2240
Merged
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The page guards in PreparedParams and BasePresenter handled zero but not negatives, so SQL-injection scanner probes like page=-11'... (which to_i reduces to -11) flowed into pagy, raised mid-render, and 500ed (~34 times/day on the course best efforts page). Any value below 1 now falls back to the first page (or default per_page), so bots get a 200 and Scout stays quiet. Resolves#2236 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Uh oh!
There was an error while loading. Please reload this page.
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 freeto 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
Fixes the ~34/day production 500s from SQL-injection scanner bots probing the
pageparam (Scout error group 91205, 7,400+ occurrences:ActionView::Template::Error: expected :page >= 1; got -11).The injection payloads accomplish nothing —
to_ireduces-11' UNION ALL SELECT...to-11— but both page guards handled zero without handling negatives, so the value flowed into pagy, which raises on a non-positive page mid-render:PreparedParams#page(result.zero?→result < 1)BasePresenter#page— the path the course best efforts page actually uses — andBasePresenter#per_page, which had the identical gapA bot asking for page -11 now gets page 1 (a 200), matching the existing zero-value behavior, and the Scout error group goes quiet.
Written spec-first: the six negative-input examples (negative integer, negative string, and the verbatim injection probe, against both classes) were committed failing, then the three one-line guards.
Testing
prepared_params_specand a newbase_presenter_spec(via a minimal concrete subclass, sinceBasePresenteris abstract) — 78 examples, 0 failures across both files, plus the course best efforts display spec.🤖 Generated with Claude Code