Skip to content

Fixes #35037: Reject negative search pagination before it reaches the search engine - #35039

Merged
mohityadav766 merged 2 commits into
mainfrom
fix/search-negative-from-validation
Oct 9, 2026
Merged

mohityadav766 merged 2 commits into
mainfrom
fix/search-negative-from-validation

Conversation

@mohityadav766

Copy link
Copy Markdown
Member

Describe your changes:

Fixes #35037

/v1/search/query, /v1/search/nlq/query and /v1/search/fieldQuery passed from and size to Elasticsearch/OpenSearch without checking them. A negative value, such as from=-25&size=25 (seen in the field), was only rejected by the engine:

Changes:

  • SearchResource: from and size on those three endpoints now carry @Min(0), as limit/offset already do in other resources. Jersey rejects the request before the resource method runs, so neither the response cache nor the engine is touched. The response is 400 [query param from must be greater than or equal to 0].
  • /v1/search/preview: the request body's from/size are checked explicitly, returning 400 from must be greater than or equal to 0. I didn't add @Valid to the body, because it would also start validating the whole nested SearchSettings.
  • Negative values are rejected, not clamped to 0. Clamping would hide the caller's paging bug and serve page 1 to a client that asked for page 0.
  • /v1/search/export and /v1/search/export/async are unchanged, because they already ignore from <= 0.

Type of change:

  • Bug fix

High-level design:

N/A — small change.

Tests:

Use cases covered

  • GET /v1/search/query?from=-25&size=25 returns 400 naming from, without querying the engine.
  • These also return 400:
    • a negative size on /v1/search/query
    • a negative from on /v1/search/nlq/query
    • a negative from or size on /v1/search/fieldQuery
  • A negative from or size in the /v1/search/preview body returns 400. A from sent as null is still treated as absent.
  • Ordinary pagination is unaffected, including size=0 for count-only queries.

Unit tests

  • I added unit tests for the new/changed logic.
  • Files added/updated: openmetadata-service/src/test/java/org/openmetadata/service/resources/search/SearchResourceTest.java (new). It checks that the preview guard rejects a negative from or size without calling SearchRepository.
  • Coverage %: JaCoCo, SearchResourceTest only, on the lines this PR changes in SearchResource:
    • Lines: 4/5 executable. The one reported as missed is the size check call. The test does execute it, but JaCoCo doesn't count a line whose call exits by throwing.
    • Branches: 4/4.
    • The @Min annotations have no executable lines; the ITs below cover them.
  • plan_local_java_tests.py also selects SearchRepositoryBehaviorTest (142/142) and SearchStatsResourceTest (9/9). Both pass.

Backend integration tests

  • I added integration tests in openmetadata-integration-tests/ for new/changed API endpoints.
  • Files added/updated: openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/SearchResourceIT.java
    • testSearchWithNegativeOffset now asserts the boundary message. It used to pass on any error, including the engine's own rejection.
    • New: testNegativePaginationIsRejectedAsBadRequest (4 cases) and testPreviewSearchWithNegativeOffsetIsRejectedAsBadRequest.
  • Local runs against main at f0d254f6fe:
  • plan_local_java_tests.py also selects 72 other search-area and smoke IT classes, which I did not run locally. No other test sends a negative from/size.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

  1. Checked the IT server's request log for the negative-pagination calls. Each returned 400 in 1–15 ms.
  2. The same log has no parameter cannot be negative engine error, so the engine was never queried.

UI screen recording / screenshots:

Not applicable.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed.
  • For UI changes: I attached a screen recording and/or screenshots above.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • I have added a test that covers the exact scenario we are fixing.

🤖 Generated with Claude Code

… engine

/v1/search/query, /v1/search/nlq/query and /v1/search/fieldQuery handed
from/size to Elasticsearch/OpenSearch unchecked, so a negative value was
only caught by the engine: a 500 with a server-side stack trace on 2.0.x,
and still a 500 on main for the NLQ and field-query endpoints.

Bound both parameters with @min(0) so Jersey answers 400 before the
resource runs (no cache lookup, no engine call), and check the
/v1/search/preview request body the same way. Negative values are rejected
rather than clamped, so a caller's paging bug stays visible instead of
quietly serving page 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mohityadav766
mohityadav766 requested a review from a team as a code owner October 9, 2026 14:43
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Oct 9, 2026
@Collection(name = "search")
@LatencyPhase
public class SearchResource {
private static final String MUST_BE_NON_NEGATIVE = "must be greater than or equal to 0";

@gitar-bot gitar-bot Bot Oct 9, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Quality: Reject-not-clamp pagination rule lives only in the PR description

This PR sets a new API contract for /v1/search/query, /nlq/query, /fieldQuery and /preview: a negative from/size is now rejected with a 400. Clients and the UI have to agree with that contract, which makes it a decision-record trigger. The reasoning is only in the description: "Negative values are rejected, not clamped to 0. Clamping would hide the caller's paging bug and serve page 1 to a client that asked for page 0." The description also says /v1/search/export and /export/async deliberately keep ignoring from <= 0. Neither rule is written down anywhere in the tree, and nothing in docs/decisions/ covers search pagination. The repo squash-merges, so the next contributor can't see why. They could "helpfully" clamp instead, or make export consistent and break it, and nothing in the tree would stop them. Per ADR:2026-10-08-a-decision-is-recorded-in-the-tree-not-in-the-pr-body, add a record. Suggested wording: "Search endpoints that paginate reject a negative from or size with 400 at the resource boundary and never clamp it to 0, and size=0 stays valid for count-only queries. The export endpoints are the exception: they ignore from <= 0." If you think no lasting rule survives this change, say so and this can be closed.

Add a decision record stating the pagination rule:

# docs/decisions/2026-10-xx-search-pagination-rejects-negative-values.md
- **Status:** Accepted
## Decision
Search endpoints that paginate (`/v1/search/query`, `/nlq/query`, `/fieldQuery`, `/preview`)
reject a negative `from` or `size` with 400 before the cache or engine is touched; they never
clamp to 0, because clamping hides the caller's paging bug. `size=0` stays valid (count-only).
`/v1/search/export*` ignore `from <= 0`.

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Oct 9, 2026

Copy link
Copy Markdown
Code Review ⚠️ Changes requested 0 closed / 1 findings

🟡 Medium risk · Validating negative pagination before search could alter error responses for clients, replacing engine errors with 400s across query, NLQ, field, and preview endpoints.

Adds @Min(0) validation to from and size on /v1/search/query, /nlq/query and /fieldQuery, and an explicit check on the /preview body, so negative pagination returns 400 before reaching the search engine.

Changes are blocked on one open finding: the reject-not-clamp pagination rule and the export exception exist only in the PR description, so they should be recorded in the tree under docs/decisions/ before merge.

⚠️ Quality: Reject-not-clamp pagination rule lives only in the PR description

📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/search/SearchResource.java:110 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/search/SearchResource.java:170-176 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/search/SearchResource.java:554-555 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/search/SearchResource.java:579-583 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/search/SearchResource.java:616-622 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/search/SearchResource.java:753-758

This PR sets a new API contract for /v1/search/query, /nlq/query, /fieldQuery and /preview: a negative from/size is now rejected with a 400. Clients and the UI have to agree with that contract, which makes it a decision-record trigger. The reasoning is only in the description: "Negative values are rejected, not clamped to 0. Clamping would hide the caller's paging bug and serve page 1 to a client that asked for page 0." The description also says /v1/search/export and /export/async deliberately keep ignoring from <= 0. Neither rule is written down anywhere in the tree, and nothing in docs/decisions/ covers search pagination. The repo squash-merges, so the next contributor can't see why. They could "helpfully" clamp instead, or make export consistent and break it, and nothing in the tree would stop them. Per ADR:2026-10-08-a-decision-is-recorded-in-the-tree-not-in-the-pr-body, add a record. Suggested wording: "Search endpoints that paginate reject a negative from or size with 400 at the resource boundary and never clamp it to 0, and size=0 stays valid for count-only queries. The export endpoints are the exception: they ignore from <= 0." If you think no lasting rule survives this change, say so and this can be closed.

Add a decision record stating the pagination rule
# docs/decisions/2026-10-xx-search-pagination-rejects-negative-values.md
- **Status:** Accepted
## Decision
Search endpoints that paginate (`/v1/search/query`, `/nlq/query`, `/fieldQuery`, `/preview`)
reject a negative `from` or `size` with 400 before the cache or engine is touched; they never
clamp to 0, because clamping hides the caller's paging bug. `size=0` stays valid (count-only).
`/v1/search/export*` ignore `from <= 0`.
🤖 Prompt for agents
Code Review: Adds `@Min(0)` validation to `from` and `size` on `/v1/search/query`, `/nlq/query` and `/fieldQuery`, and an explicit check on the `/preview` body, so negative pagination returns 400 before reaching the search engine.
  
  Changes are blocked on one open finding: the reject-not-clamp pagination rule and the export exception exist only in the PR description, so they should be recorded in the tree under `docs/decisions/` before merge.

1. ⚠️ Quality: Reject-not-clamp pagination rule lives only in the PR description
   Files: openmetadata-service/src/main/java/org/openmetadata/service/resources/search/SearchResource.java:110, openmetadata-service/src/main/java/org/openmetadata/service/resources/search/SearchResource.java:170-176, openmetadata-service/src/main/java/org/openmetadata/service/resources/search/SearchResource.java:554-555, openmetadata-service/src/main/java/org/openmetadata/service/resources/search/SearchResource.java:579-583, openmetadata-service/src/main/java/org/openmetadata/service/resources/search/SearchResource.java:616-622, openmetadata-service/src/main/java/org/openmetadata/service/resources/search/SearchResource.java:753-758

   This PR sets a new API contract for `/v1/search/query`, `/nlq/query`, `/fieldQuery` and `/preview`: a negative `from`/`size` is now rejected with a 400. Clients and the UI have to agree with that contract, which makes it a decision-record trigger. The reasoning is only in the description: "Negative values are rejected, not clamped to 0. Clamping would hide the caller's paging bug and serve page 1 to a client that asked for page 0." The description also says `/v1/search/export` and `/export/async` deliberately keep ignoring `from <= 0`. Neither rule is written down anywhere in the tree, and nothing in `docs/decisions/` covers search pagination. The repo squash-merges, so the next contributor can't see why. They could "helpfully" clamp instead, or make export consistent and break it, and nothing in the tree would stop them. Per [ADR:2026-10-08-a-decision-is-recorded-in-the-tree-not-in-the-pr-body](docs/decisions/2026-10-08-a-decision-is-recorded-in-the-tree-not-in-the-pr-body.md), add a record. Suggested wording: "Search endpoints that paginate reject a negative `from` or `size` with 400 at the resource boundary and never clamp it to 0, and `size=0` stays valid for count-only queries. The export endpoints are the exception: they ignore `from <= 0`." If you think no lasting rule survives this change, say so and this can be closed.

   Fix (Add a decision record stating the pagination rule):
   # docs/decisions/2026-10-xx-search-pagination-rejects-negative-values.md
   - **Status:** Accepted
   ## Decision
   Search endpoints that paginate (`/v1/search/query`, `/nlq/query`, `/fieldQuery`, `/preview`)
   reject a negative `from` or `size` with 400 before the cache or engine is touched; they never
   clamp to 0, because clamping hides the caller's paging bug. `size=0` stays valid (count-only).
   `/v1/search/export*` ignore `from <= 0`.

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@mohityadav766
mohityadav766 added this pull request to the merge queue Oct 9, 2026
@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

Merged via the queue into main with commit 893cd1b Oct 9, 2026
75 checks passed
@mohityadav766
mohityadav766 deleted the fix/search-negative-from-validation branch October 9, 2026 18:29
TeddyCr pushed a commit to TeddyCr/OpenMetadata that referenced this pull request Oct 9, 2026
…ta#35040)

Clamp zero and negative page numbers in regular and natural-language UI searches to the first page, preserving valid pagination and count-only requests.

Add Jest regression coverage for the request offsets and a Playwright regression for a Queries-tab URL with queryFrom=0&pageSize=25.

Refs open-metadata#35037. Backend request validation is handled separately in open-metadata#35039.
mohityadav766 added a commit that referenced this pull request Oct 13, 2026
…ted failures logged as errors [2.0] (#35302)

* Fixes #35037: reject negative search pagination before it reaches the engine [2.0]

Backport of #35039 and #35040. A negative from or size on the search
endpoints is rejected with a 400 that names the parameter instead of failing
in the search engine as a 500, and the UI no longer sends a negative offset.

SearchResourceIT conflicted: 2.0 has neither the httpGetSearch helper nor the
400 mapping the old negative-offset test expected, so the new tests and
helpers were added by hand.

(cherry picked from commit 893cd1b)
(cherry picked from commit e3914c5)

* Fixes #35293: serve glossary CSV documentation for glossary-term import [2.0]

The bulk import page asks /v1/csv/documentation/{entityType} for the type it
imports into. For a glossary term that is glossaryTerm, which has no
documentation file, so every request returned a 500 and was logged twice at
ERROR. Glossary-term import already goes through GlossaryCsv, so glossaryTerm
now gets the glossary's documentation. A type with no documentation returns a
404, and the FATAL log before the rethrow is gone.

* Apply a workflow approval when the approver is not a reviewer [2.0]

Anyone the task policy lets resolve an approval task, such as an admin or an
owner, could approve a glossary term without being one of its reviewers. The
workflow then set the status as that user, the reviewer check rejected it, and
the failure was only logged: the task closed as Approved while the term stayed
In Review.

As on main since #34541, a status change the governance workflow makes, as or
impersonating governance-bot, skips the reviewer check: the approval task
already decided who may approve. Direct edits are still checked.
SetGlossaryTermStatusImpl now writes impersonating governance-bot like the
other workflow nodes, so its changes are recognised too.

* Skip deleted alert recipients without logging an error [2.0]

An alert can name a user or team that is deleted later. Every event for that
alert logged the lookup failure at ERROR with a stack trace, although there is
simply no one left to notify. A missing recipient is now skipped at DEBUG, as
main does since #33967; any other lookup failure is still logged as an error.

* Mock the 2.0 API client in the backported pagination test

The pagination tests from #35040 mock ./axiosClient, which only exists on
main. On 2.0 searchAPI imports its client from ./index, so the mock could not
resolve and all 12 new cases failed. Mock ./index like the rest of the file.

* Verify the impersonated status patch in BatchModeNodesTest

#35239 brought this test to 2.0 while this branch made SetGlossaryTermStatusImpl
patch impersonating governance-bot, so the test still expected the plain
four-argument patch. It now checks the same call main's copy of the test does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Negative from/size on search endpoints reach the search engine and fail as a server error

2 participants