Skip to content

Bug: Facet loaders accept non-positive and unbounded pagination values #1331

@pranjal2004838

Description

@pranjal2004838

Summary

The facet route loaders currently accept any integer for page and page_size, including non-positive values (0, negative) and very large values, without bounds checks before server-side fetches.

Affected code

  • src/routes/facets/[facet]/+page.ts
  • src/routes/facets/[facet]/[value]/+page.ts
  • src/lib/utils.ts (requireInt only checks parseability, not bounds)

Why this matters

  • Non-positive values create invalid pagination behavior.
  • Very large page_size can trigger oversized upstream requests and increase latency/memory usage.
  • This is a server-side entry point, so malformed query params can be repeatedly abused.

Reproduction

  1. Open a facet URL with invalid params, for example:
    • /facets/categories?page=0&page_size=0
    • /facets/categories?page=-5&page_size=100000
  2. Observe that the loader accepts these values and forwards them to getFacet/getFacetValue.

Expected behavior

  • Reject invalid values with 400 when:
    • page < 1
    • page_size < 1
  • Enforce an upper bound for page_size (for example 100 or 200) and reject/clamp values above the cap.

Suggested fix

  • Add a shared validator for positive bounded integers (or extend requireInt with min/max).
  • Apply the same validation in both facet loaders to keep behavior consistent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions