Mitigation Strategy: Limit Maximum Page Number
-
Description:
- Identify Pagination Controllers: Locate all controller actions that use
will_paginate
to display paginated results (search for.paginate
). - Define a Constant: Create a constant (e.g.,
MAX_PAGE
) to store the maximum allowed page number. - Implement the Check: Before calling
.paginate
, retrieve and convert thepage
parameter (params[:page]
) to an integer. - Enforce the Limit:
- If
page <= 0
, setpage = 1
. - If
page > MAX_PAGE
, setpage = MAX_PAGE
.
- If
- Pass the Sanitized Value: Pass the sanitized
page
value to the.paginate
method. - Test: Test with edge cases (page 0, 1,
MAX_PAGE
,MAX_PAGE + 1
).
- Identify Pagination Controllers: Locate all controller actions that use
-
Threats Mitigated:
- Excessive Page Number Requests (Denial of Service / Performance Degradation): Severity: High.
- Information Disclosure (Leaking Total Count - Indirectly): Severity: Low.
-
Impact:
- Excessive Page Number Requests: Risk significantly reduced.
- Information Disclosure: Risk slightly reduced.
-
Currently Implemented:
- Example: Implemented in
app/controllers/products_controller.rb
(index
action).MAX_PAGE
inapp/controllers/application_controller.rb
.
- Example: Implemented in
-
Missing Implementation:
- Example: Missing in
app/controllers/admin/users_controller.rb
(index
action).
- Example: Missing in
Mitigation Strategy: Validate per_page
Parameter
-
Description:
- Identify Pagination Controllers: Locate controller actions using
.paginate
. - Define a Constant: Create a constant (e.g.,
MAX_PER_PAGE
). - Implement the Check: Before calling
.paginate
, retrieve and convertparams[:per_page]
to an integer. - Enforce the Limit:
- If
per_page <= 0
, setper_page
to a default (e.g., 20). - If
per_page > MAX_PER_PAGE
, setper_page = MAX_PER_PAGE
.
- If
- Pass the Sanitized Value: Pass the sanitized
per_page
to.paginate
. - Test: Test with various
per_page
values, including edge cases.
- Identify Pagination Controllers: Locate controller actions using
-
Threats Mitigated:
- Excessive Data Retrieval (Denial of Service / Performance Degradation): Severity: High.
-
Impact:
- Excessive Data Retrieval: Risk significantly reduced.
-
Currently Implemented:
- Example: Implemented in
app/controllers/products_controller.rb
andapp/controllers/articles_controller.rb
.MAX_PER_PAGE
inconfig/initializers/pagination.rb
.
- Example: Implemented in
-
Missing Implementation:
- Example: Missing in
app/controllers/search_controller.rb
.
- Example: Missing in
Mitigation Strategy: Disable Total Count Calculation (if not needed)
-
Description:
- Identify Pagination Views: Locate views where
will_paginate
's helper is used. - Analyze UI Requirements: Determine if the exact total count is essential.
- Customize the Renderer: Create a custom renderer for
will_paginate
that doesn't include the total count. Inherit fromWillPaginate::ActionView::LinkRenderer
and override methods liketotal_pages
andhtml_container
. - Configure
will_paginate
: In your view, use the:renderer
option with thewill_paginate
helper to specify your custom renderer. - Test: Verify pagination links display correctly without the total count.
- Identify Pagination Views: Locate views where
-
Threats Mitigated:
- Information Disclosure (Leaking Total Count): Severity: Medium.
-
Impact:
- Information Disclosure: Risk eliminated (if the total count is not needed). Performance improvement.
-
Currently Implemented:
- Example: Implemented for the "Recent Activity" feed (
app/views/dashboard/index.html.erb
). Custom renderer:app/helpers/custom_pagination_renderer.rb
.
- Example: Implemented for the "Recent Activity" feed (
-
Missing Implementation:
- Example: Missing in
app/views/products/index.html.erb
.
- Example: Missing in
Mitigation Strategy: Provide a Custom count
Option (for complex queries)
-
Description:
- Identify Complex Queries: Identify controller actions using
will_paginate
with complex ActiveRecord queries. - Analyze Query Performance: Use database profiling tools to examine the performance of the
COUNT(*)
query. - Implement Custom Count Logic: If the default
COUNT(*)
is inefficient, create a custom method (model or helper) for a more efficient count. This might involve:- Optimized SQL.
- Cached count (if appropriate).
- Different counting technique.
- Pass the
count
Option: In thepaginate
method call, use the:count
option:- String with custom SQL.
- Symbol of the custom method.
- Test: Test pagination with the custom count logic.
- Identify Complex Queries: Identify controller actions using
-
Threats Mitigated:
- Unexpected Behavior with Complex Queries (Incorrect Pagination / Errors): Severity: Medium.
- Performance Issues with Complex Queries (Denial of Service - Indirectly): Severity: Low.
-
Impact:
- Unexpected Behavior: Risk significantly reduced.
- Performance Issues: Risk reduced.
-
Currently Implemented:
- Example: Implemented in
app/controllers/reports_controller.rb
(sales_report
action). Custom method:Report.sales_report_count
.
- Example: Implemented in
-
Missing Implementation:
- Example: Potentially needed in
app/controllers/admin/audit_logs_controller.rb
. Needs investigation.
- Example: Potentially needed in