Repository navigation
[BugFix] Return 400 for an empty SQL cursor (#5983) - #5992
Merged
Swiddis merged 1 commit intoNov 30, 2026
Merged
Conversation
An empty cursor caused isLegacyCursor to call substring(0, 1) and return HTTP 500. Reject empty or blank cursors with a 400 on both /_plugins/_sql and /_plugins/_sql/close. Signed-off-by: Shubham <87247136+shuseng8@users.noreply.github.com>
shuseng8
requested review from
LantaoJin,
RyanL1997,
Swiddis,
acarbonetto,
ahkcs,
anirudha,
dai-chen,
joshuali925,
mengweieric,
noCharger,
penghuo,
ps48,
qianheng-aws,
songkant-aws,
vamsimanohar,
ykmr1224 and
yuancu
as code owners
November 26, 2026 10:52
Contributor
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
Swiddis
approved these changes
Nov 29, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5992 +/- ##
=========================================
Coverage 89.46% 89.47%
Complexity 12251 12251
=========================================
Files 980 980
Lines 41967 41967
Branches 4829 4829
=========================================
+ Hits 37545 37549 +4
+ Misses 2945 2942 -3
+ Partials 1477 1476 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Author
|
Hi @Swiddis, thanks for the approval! The remaining red checks look unrelated to this change (analytics-engine security IT / async PPL lifecycle IT failures, and codecov/project). Could you re-run the failed jobs when you get a chance? Happy to look at anything that still fails. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
A request with an empty cursor (
POST _plugins/_sqlorPOST _plugins/_sql/closewith{"cursor": ""}) returned HTTP 500 andStringIndexOutOfBoundsException. This is a bad request, so it should return 400.RestSqlAction.isLegacyCursorcalledcursor.substring(0, 1)without checking for an empty string. Both endpoints are handled byRestSqlAction, and an empty cursor never reached a meaningful legacy or v2 engine path because it crashed first.This change:
SqlRequestFactorywithIllegalArgumentException("Cursor is empty or invalid"), whichRestSqlActionalready maps to HTTP 400 on both/_plugins/_sqland/_plugins/_sql/close.isLegacyCursorskip empty cursors sosubstring(0, 1)cannot throw if an empty cursor is constructed some other way.Related Issues
Resolves #5983
Check List
SqlRequestFactoryTest(valid, empty, and blank cursors) andRestSqlActionTest(empty cursor is a 400,isLegacyCursordoes not throw on empty or null and still detects legacy vs v2 cursors).CursorITforPOST _plugins/_sqlandPOST _plugins/_sql/closewith{"cursor": ""}, asserting HTTP 400 and the error details.--signoffor-s.Tested locally with
./gradlew :legacy:spotlessCheck :integ-test:spotlessCheck :legacy:test(1534 tests, 0 failures, 26 skipped) and./gradlew :integ-test:integTest -Dtests.class="org.opensearch.sql.legacy.CursorIT" -Dtests.method="emptyCursor*" -DignorePrometheus(both new tests passed).By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.