Skip to content

Clamp non-positive page and per_page params to their defaults - #2240

Merged
moveson merged 2 commits into
masterfrom
oveson/claude/clamp-page-param
Aug 24, 2026
Merged

Clamp non-positive page and per_page params to their defaults#2240
moveson merged 2 commits into
masterfrom
oveson/claude/clamp-page-param

Conversation

@moveson

Copy link
Copy Markdown
Collaborator

Summary

Fixes the ~34/day production 500s from SQL-injection scanner bots probing the page param (Scout error group 91205, 7,400+ occurrences: ActionView::Template::Error: expected :page >= 1; got -11).

The injection payloads accomplish nothing — to_i reduces -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 — and BasePresenter#per_page, which had the identical gap

A 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

  • New specs in prepared_params_spec and a new base_presenter_spec (via a minimal concrete subclass, since BasePresenter is abstract) — 78 examples, 0 failures across both files, plus the course best efforts display spec.
  • rubocop clean on touched files.

🤖 Generated with Claude Code

movesonand others added 2 commits August 24, 2026 09:42
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>
@moveson
moveson merged commit 0763e2d into masterAug 24, 2026
7 checks passed
@moveson
moveson deleted the oveson/claude/clamp-page-param branch August 24, 2026 15:48
Sign up for freeto 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

@moveson