Skip to content

Build occurrence pagination links from page and items only - #99

Merged
fractaledmind merged 1 commit into
fractaledmind:mainfrom
bruno-costanzo:fix-pagination-url-params
Oct 13, 2026
Merged

fractaledmind merged 1 commit into
fractaledmind:mainfrom
bruno-costanzo:fix-pagination-url-params

Conversation

@bruno-costanzo

Copy link
Copy Markdown
Contributor

The occurrence pagination links on the error page are built with url_for(params.to_unsafe_hash.merge(page: ...)). That passes every request param to url_for, and url_for reads some keys as URL options, not as query params: script_name, original_script_name, host, protocol, port, anchor, etc.

So a crafted link to an error page changes where the First / Previous / Next / Last links go:

GET /solid_errors/1?items=1&original_script_name=javascript:alert(document.domain)//
→ <a href="javascript:alert(document.domain)///solid_errors/1?items=1&amp;page=2" aria-label="Next">

GET /solid_errors/1?items=1&host=evil.example
→ <a href="http://evil.example/solid_errors/1?items=1&amp;page=2" aria-label="Next">

A user who opens such a link and clicks a pagination link runs the script in the app's origin, or goes to another host. This is the same class of issue as Kaminari's CVE-2020-11082.

Fix

The page only reads page and items, so the links are now built from those two values only:

url_for(page: next_page, items: params[:items])

When there is no items param, the link has only page, the same as before.

Tests

There were no request tests yet, so this mounts the engine in the dummy app and adds test/controllers/solid_errors/errors_controller_test.rb:

  • pagination links keep the items param
  • pagination links use the default page size without an items param
  • pagination links ignore script_name, original_script_name, host, protocol, port and anchor from the request

Without the fix, the last test fails with https://evil.example:6666javascript:alert(1)//javascript:alert(1)//1?items=1&page=2#x. The first two pass with and without the fix. bundle exec rake (tests + standard) passes.

The links merged every request param into url_for. url_for reads keys
like script_name, original_script_name, host and protocol as URL
options, so a crafted link to an error page could make the pagination
links point to another host or to a javascript: URL.
@fractaledmind
fractaledmind merged commit 0c040d9 into fractaledmind:main Oct 13, 2026
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.

2 participants