pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/meshery/meshery/pull/20965

" rel="stylesheet" href="https://github.githubassets.com/assets/pull-requests-be6017ec12798e73.css" /> [Server] fix: handle negative pagination page size by SuryanshGarg04 · Pull Request #20965 · meshery/meshery · GitHub
Skip to content

[Server] fix: handle negative pagination page size - #20965

Open
SuryanshGarg04 wants to merge 6 commits into
meshery:masterfrom
SuryanshGarg04:fix/negative-pagesize-pagination
Open

[Server] fix: handle negative pagination page size#20965
SuryanshGarg04 wants to merge 6 commits into
meshery:masterfrom
SuryanshGarg04:fix/negative-pagesize-pagination

Conversation

@SuryanshGarg04

@SuryanshGarg04 SuryanshGarg04 commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #20964

This PR fixes the handling of negative pageSize values in the shared getPaginationParams() helper.

While testing the connection definitions endpoint, I found that a negative page size such as:

GET /api/meshmodels/connections?pagesize=-1

was parsed successfully by strconv.Atoi() and passed downstream as limit = -1.

The existing pagination validation only handled limit == 0:

if limit == 0 {
    limit = defaultPageSize
}

When the negative value reached GORM as Limit(-1), GORM removed the limit condition, causing the complete result set to be returned. The response also reported "pageSize": -1.

This change normalizes non-positive numeric page sizes to defaultPageSize:

if limit <= 0 {
    limit = defaultPageSize
}

The special pageSize=all behavior remains unchanged because it bypasses this normalization block and continues to use limit = 0.

The helper supports both the canonical pageSize parameter and the legacy pagesize spelling, so regression coverage includes both.

Current Behavior

Before the fix:

REQUEST:
GET /api/meshmodels/connections?pagesize=-1

HTTP: 200

{
  "page": 0,
  "pageSize": -1,
  "totalCount": 3,
  "returnedDefinitions": 3
}

A negative page size removes the query limit and the API reports an invalid negative pageSize.

Expected Behavior

Negative numeric page sizes should fall back to the default page size, consistent with zero and malformed page-size values.

After the fix:

REQUEST:
GET /api/meshmodels/connections?pagesize=-1

HTTP: 200

{
  "page": 0,
  "pageSize": 25,
  "totalCount": 26,
  "returnedDefinitions": 25
}

The number of connection definitions in my local environment increased between the before and after runs. The relevant values here are the reported pageSize and the number of returned definitions relative to the requested page size.

No Regression

Positive page sizes continue to work as expected:

REQUEST:
GET /api/meshmodels/connections?pagesize=1

HTTP: 200

{
  "page": 0,
  "pageSize": 1,
  "totalCount": 26,
  "returnedDefinitions": 1
}

The existing unlimited behavior is also preserved:

REQUEST:
GET /api/meshmodels/connections?pagesize=all

HTTP: 200

{
  "page": 0,
  "pageSize": 26,
  "totalCount": 26,
  "returnedDefinitions": 26
}

Tests

Added table-driven regression coverage for:

  • canonical pageSize=-1
  • legacy pagesize=-1
  • pageSize=0
  • malformed pageSize=abc
  • positive pageSize=1
  • pageSize=all

Test result:

=== RUN   TestGetPaginationParams
=== RUN   TestGetPaginationParams/negative_canonical_pageSize_defaults
=== RUN   TestGetPaginationParams/negative_legacy_pagesize_defaults
=== RUN   TestGetPaginationParams/zero_pageSize_defaults
=== RUN   TestGetPaginationParams/malformed_pageSize_defaults
=== RUN   TestGetPaginationParams/positive_pageSize_preserved
=== RUN   TestGetPaginationParams/all_preserves_unlimited_behavior
--- PASS: TestGetPaginationParams (0.00s)
PASS
ok      github.com/meshery/meshery/server/handlers      1.194s

Notes

The fix is made in the shared pagination helper rather than in the connection definitions handler, so invalid negative page sizes are normalized at the point where pagination parameters are parsed.

No changes are made to MeshKit's ConnectionFilter behavior or to the existing pageSize=all semantics.

Summary by CodeRabbit

  • Bug Fixes

    • Invalid pagination pageSize values (including zero and negative/ non-positive inputs) now consistently fall back to the default page size.
    • Positive pageSize and pageSize=all (unlimited) behavior remain unchanged.
  • Tests

    • Added unit test coverage for pagination pageSize handling across valid, invalid (malformed/negative), zero, and unlimited inputs.

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3f8c46d6-8a4b-4717-be7c-3b4aa30779d6

📥 Commits

Reviewing files that changed from the base of the PR and between c06c3bf and 4de9640.

📒 Files selected for processing (1)
  • server/handlers/utils_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/handlers/utils_test.go

📝 Walkthrough

Walkthrough

getPaginationParams now replaces non-positive numeric page sizes with the default page size. A table-driven test covers negative, zero, malformed, positive, and all page-size inputs.

Changes

Pagination validation

Layer / File(s) Summary
Validate and test page size
server/handlers/utils.go, server/handlers/utils_test.go
Non-positive parsed page sizes now use defaultPageSize, while positive values and pageSize=all retain their existing behavior. Table-driven tests verify these cases.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing negative pagination page sizes.
Linked Issues check ✅ Passed The helper now falls back for zero or negative pageSize values, and tests cover the linked issue's cases.
Out of Scope Changes check ✅ Passed The PR only changes pagination validation and adds focused regression tests, with no unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@KumarNirupam1 KumarNirupam1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this small fix
lgtm

@ritzorama ritzorama left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is the negative pagination size occurring?

@SuryanshGarg04

SuryanshGarg04 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

@ritzorama I traced where the negative value could come from. It isn't generated by the normal UI or CLI flow. The case I reproduced was through a direct API request, for example GET /api/meshmodels/connections?pagesize=-1.

Since getPaginationParams() only handled limit == 0, -1 was passed through to GORM, where Limit(-1) removes the query limit. So this is mainly API side input hardening to make sure negative page sizes fall back to the default instead of changing the query behavior.

@reaper8055 reaper8055 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@github-actions

Copy link
Copy Markdown
Contributor

Commit SHA: 77cf98d78908660378ec3b8096ce9027f0a6bf02

END-TO-END TESTS

  • Testing started at: July 27th 2026, 10:38:36 am

📦 Test Result Summary

  • ✅ 64 passed
  • ❌ 0 failed
  • ⚠️ 0 flaked
  • ⏩ 6 skipped

Duration: 3 minutes and 12 seconds

Overall Result: 👍 All tests passed.

[Show/Hide] Test Result Details
Test Provider Browser Test Case Tags Result
1 Local chromium-local-provider Aggregation Charts are displayed
2 Local chromium-local-provider alias resolution relationship
3 Local chromium-local-provider alias resolution relationship
4 Local chromium-local-provider alias resolution relationship
5 Local chromium-local-provider alias resolution relationship
6 Local chromium-local-provider alias resolution relationship
7 Local chromium-local-provider alias resolution relationship
8 Local chromium-local-provider alias resolution relationship
9 Local chromium-local-provider alias resolution relationship
10 Local chromium-local-provider alias resolution relationship
11 Local chromium-local-provider Charts (Grafana) page loads
12 Local chromium-local-provider config patching correctness relationship
13 Local chromium-local-provider config patching correctness relationship
14 Local chromium-local-provider config patching correctness relationship
15 Local chromium-local-provider config patching correctness relationship
16 Local chromium-local-provider config patching correctness relationship
17 Local chromium-local-provider config patching correctness relationship
18 Local chromium-local-provider config patching correctness relationship
19 Local chromium-local-provider config patching correctness relationship
20 Local chromium-local-provider config patching correctness relationship
21 Local chromium-local-provider Configure Existing Istio adapter through Mesh Adapter URL from Management page unstable ⚠️
22 Local chromium-local-provider Connect to Meshery Istio Adapter and configure it
23 Local chromium-local-provider Create a Model
24 Local chromium-local-provider Delete Kubernetes cluster connections
25 Local chromium-local-provider evaluation idempotency relationship
26 Local chromium-local-provider evaluation idempotency relationship
27 Local chromium-local-provider evaluation idempotency relationship
28 Local chromium-local-provider evaluation idempotency relationship
29 Local chromium-local-provider evaluation idempotency relationship
30 Local chromium-local-provider evaluation idempotency relationship
31 Local chromium-local-provider evaluation idempotency relationship
32 Local chromium-local-provider evaluation idempotency relationship
33 Local chromium-local-provider evaluation idempotency relationship
34 Local chromium-local-provider Import a Model via CSV Import
35 Local chromium-local-provider Import a Model via File Import
36 Local chromium-local-provider Import a Model via Url Import
37 Local chromium-local-provider Logout from current user session
38 Local chromium-local-provider Metrics (Prometheus) page loads
39 Local chromium-local-provider Performance dashboard controls
40 Local chromium-local-provider Ping Istio Adapter unstable ⚠️
41 Local chromium-local-provider Search a Model and Export it
42 Local chromium-local-provider should edit design in Design Configurator
43 Local chromium-local-provider should identify relationships for All Relationships relationship
44 Local chromium-local-provider should identify relationships for Container-Hierarchical-Parent-Alias-Relationship relationship
45 Local chromium-local-provider should identify relationships for deployment-configmap-reference-relationship relationship
46 Local chromium-local-provider should identify relationships for Hierarchical-Parent-Namespace-Relationship relationship
47 Local chromium-local-provider should identify relationships for meshery-design relationship
48 Local chromium-local-provider should identify relationships for pv-pvc-edge-non-binding-reference-relationship relationship
49 Local chromium-local-provider should identify relationships for Service-To-Deployment-Network relationship
50 Local chromium-local-provider should verify Design Configurator page elements
51 Local chromium-local-provider structural integrity relationship
52 Local chromium-local-provider structural integrity relationship
53 Local chromium-local-provider structural integrity relationship
54 Local chromium-local-provider structural integrity relationship
55 Local chromium-local-provider structural integrity relationship
56 Local chromium-local-provider structural integrity relationship
57 Local chromium-local-provider structural integrity relationship
58 Local chromium-local-provider structural integrity relationship
59 Local chromium-local-provider structural integrity relationship
60 Local chromium-local-provider Test if Left Navigation Panel is displayed
61 Local chromium-local-provider Test if Notification button is displayed
62 Local chromium-local-provider Test if Profile button is displayed
63 Local chromium-local-provider Toggle "Send Anonymous Performance Results"
64 Local chromium-local-provider Toggle "Send Anonymous Usage Statistics"
65 Local chromium-local-provider Verify extension nav items use top-level layout
66 Local chromium-local-provider Verify Meshery Adapter for Istio Section
67 Local chromium-local-provider Verify Meshery Catalog Section Details
68 Local chromium-local-provider Verify Meshery Design Embed Details
69 Local chromium-local-provider Verify Meshery Docker Extension Details
70 Local chromium-local-provider Verify Performance Analysis Details
71 Local chromium-local-provider Verify that UI components are displayed
72 Local local-setup authenticate as Local provider

🔗 Relationship Tests

[Show/Hide] Relationship Test Details (18 tests)
Kind Type SubType From To Model Design Name Status
edge binding permission ClusterRole ServiceAccount kubernetes Understanding Relationships
edge binding permission Role ServiceAccount kubernetes Understanding Relationships
edge non-binding network Service Deployment kubernetes service-to-deployment-network
edge non-binding network Service Deployment kubernetes meshery-design-fixture.json
edge non-binding reference ClusterRoleBinding ClusterRole kubernetes meshery-design-fixture.json
hierarchical parent alias Container Deployment kubernetes container-hierarchical-parent-alias-relationship
hierarchical parent alias Container Deployment kubernetes deployment-configmap-reference-relationship
hierarchical parent alias Container Deployment kubernetes service-to-deployment-network
hierarchical parent alias Container Deployment kubernetes meshery-design-fixture.json
hierarchical parent alias Container Deployment kubernetes Understanding Relationships
hierarchical parent alias Container Pod kubernetes container-hierarchical-parent-alias-relationship
hierarchical parent inventory * Namespace kubernetes hierarchical-parent-namespace-relationship
hierarchical parent inventory * Namespace kubernetes service-to-deployment-network
hierarchical parent inventory * Namespace kubernetes pv-pvc-edge-non-binding-reference-relationship
hierarchical parent inventory * Namespace kubernetes Understanding Relationships
hierarchical sibling matchlabels ClusterRole ClusterRole kubernetes meshery-design-fixture.json
hierarchical sibling matchlabels Deployment Deployment kubernetes meshery-design-fixture.json
hierarchical sibling matchlabels Service Service kubernetes meshery-design-fixture.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Server] Negative pagesize bypasses pagination limit across API handlers

4 participants

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy