Skip to content

[BugFix] Return 400 for an empty SQL cursor (#5983) - #5992

Merged
Swiddis merged 1 commit into
opensearch-project:mainfrom
shuseng8:fix/5983-empty-cursor-400
Nov 30, 2026
Merged

Swiddis merged 1 commit into
opensearch-project:mainfrom
shuseng8:fix/5983-empty-cursor-400

Conversation

@shuseng8

Copy link
Copy Markdown
Contributor

Description

A request with an empty cursor (POST _plugins/_sql or POST _plugins/_sql/close with {"cursor": ""}) returned HTTP 500 and StringIndexOutOfBoundsException. This is a bad request, so it should return 400.

RestSqlAction.isLegacyCursor called cursor.substring(0, 1) without checking for an empty string. Both endpoints are handled by RestSqlAction, and an empty cursor never reached a meaningful legacy or v2 engine path because it crashed first.

This change:

  • Rejects an empty or blank cursor in SqlRequestFactory with IllegalArgumentException("Cursor is empty or invalid"), which RestSqlAction already maps to HTTP 400 on both /_plugins/_sql and /_plugins/_sql/close.
  • Makes isLegacyCursor skip empty cursors so substring(0, 1) cannot throw if an empty cursor is constructed some other way.

Related Issues

Resolves #5983

Check List

  • New functionality includes testing.
    • Unit tests in SqlRequestFactoryTest (valid, empty, and blank cursors) and RestSqlActionTest (empty cursor is a 400, isLegacyCursor does not throw on empty or null and still detects legacy vs v2 cursors).
    • Integration tests in CursorIT for POST _plugins/_sql and POST _plugins/_sql/close with {"cursor": ""}, asserting HTTP 400 and the error details.
  • New functionality has been documented.
    • New functionality has javadoc added.
    • New functionality has a user manual doc added.
  • New PPL command checklist all confirmed.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff or -s.
  • Public documentation issue/PR created.

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.

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>
@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ No major issues detected

@Swiddis Swiddis added the bugFix label Nov 29, 2026

@Swiddis Swiddis left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm assuming actions pass (link checker and analytics engine ok) -- will check tomorrow that they did

@codecov

codecov Bot commented Nov 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.47%. Comparing base (c7e2cea) to head (b9826ee).

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     
Flag Coverage Δ
integration 69.91% <ø> (+<0.01%) ⬆️
unit 76.84% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@shuseng8

Copy link
Copy Markdown
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.

@Swiddis
Swiddis merged commit 1d432cb into opensearch-project:main Nov 30, 2026
48 of 51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] SQL returns 500 StringIndexOutOfBoundsException for an empty cursor

2 participants