Skip to content

feat: Add input size validation for queries and attachments #3359

Merged
rajin-kichannagari merged 9 commits into
redhat-developer:mainfrom
rajin-kichannagari:fix/input-size-limits-rhidp-13062
Jun 15, 2026
Merged

feat: Add input size validation for queries and attachments #3359
rajin-kichannagari merged 9 commits into
redhat-developer:mainfrom
rajin-kichannagari:fix/input-size-limits-rhidp-13062

Conversation

@rajin-kichannagari

@rajin-kichannagari rajin-kichannagari commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Implement backend validation to prevent users from submitting arbitrarily large queries or attachments that could consume backend memory and LCS resources.

Changes:

  • Add size limit constants: MAX_QUERY_LENGTH (32K), MAX_ATTACHMENT_SIZE_BYTES (20MB), MAX_TOTAL_ATTACHMENTS_SIZE_BYTES (50MB)
  • Extend validateCompletionsRequest middleware with query length and attachment size validation
  • Add attachments field to QueryRequestBody interface
  • Add query length validation to notebooks query endpoint
  • Add comprehensive test coverage for all validation scenarios

Checklist

  • Added or Updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)

Note: Changeset not applicable for security fix. Frontend changes may be needed in a follow-up issue to communicate limits to users.

…062)

Implement backend validation to prevent users from submitting arbitrarily
large queries or attachments that could consume backend memory and LCS
resources.

Changes:
- Add size limit constants: MAX_QUERY_LENGTH (32K), MAX_ATTACHMENT_SIZE_BYTES (20MB), MAX_TOTAL_ATTACHMENTS_SIZE_BYTES (50MB)
- Extend validateCompletionsRequest middleware with query length and attachment size validation
- Add attachments field to QueryRequestBody interface
- Add query length validation to notebooks query endpoint
- Add comprehensive test coverage for all validation scenarios

Addresses security vulnerability identified in Red Hat Product Security
threat model (dated Mar 15, 2026).

Co-Authored-By: Rajin Kichannagari <rkichann@redhat.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Resolved conflicts:
- validation.ts: Kept our size validation imports alongside upstream changes
- validation.test.ts: Removed isAllowedProxyPath tests (function moved in upstream refactor), kept our new validateCompletionsRequest tests for RHIDP-13062
@rhdh-gh-app

rhdh-gh-app Bot commented Jun 10, 2026

Copy link
Copy Markdown

Changed Packages

Package Name Package Path Changeset Bump Current Version
@red-hat-developer-hub/backstage-plugin-lightspeed-backend workspaces/lightspeed/plugins/lightspeed-backend patch v2.9.1

@rajin-kichannagari rajin-kichannagari changed the title feat: Add input size validation for queries and attachments (RHIDP-13062) feat: Add input size validation for queries and attachments Jun 10, 2026
@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.77419% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 54.01%. Comparing base (0496a27) to head (f99bd64).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3359      +/-   ##
==========================================
- Coverage   54.01%   54.01%   -0.01%     
==========================================
  Files        2409     2404       -5     
  Lines       87705    87541     -164     
  Branches    24287    24250      -37     
==========================================
- Hits        47373    47284      -89     
+ Misses      40054    40020      -34     
+ Partials      278      237      -41     
Flag Coverage Δ *Carryforward flag
adoption-insights 83.58% <ø> (ø) Carriedforward from 97dd8f1
ai-integrations 70.03% <ø> (ø) Carriedforward from 97dd8f1
app-defaults 69.60% <ø> (ø) Carriedforward from 97dd8f1
augment 46.39% <ø> (ø) Carriedforward from 97dd8f1
bulk-import 72.80% <ø> (+0.10%) ⬆️ Carriedforward from 97dd8f1
cost-management 17.48% <ø> (ø) Carriedforward from 97dd8f1
dcm 59.68% <ø> (-0.59%) ⬇️ Carriedforward from 97dd8f1
extensions 62.17% <ø> (ø) Carriedforward from 97dd8f1
global-floating-action-button 74.30% <ø> (ø) Carriedforward from 97dd8f1
global-header 61.63% <ø> (ø) Carriedforward from 97dd8f1
homepage 52.30% <ø> (-0.38%) ⬇️ Carriedforward from 97dd8f1
install-dynamic-plugins 56.23% <ø> (ø) Carriedforward from 97dd8f1
konflux 91.01% <ø> (ø) Carriedforward from 97dd8f1
lightspeed 68.62% <96.77%> (+0.15%) ⬆️
mcp-integrations 85.46% <ø> (ø) Carriedforward from 97dd8f1
orchestrator 37.33% <ø> (ø) Carriedforward from 97dd8f1
quickstart 62.09% <ø> (ø) Carriedforward from 97dd8f1
sandbox 79.56% <ø> (ø) Carriedforward from 97dd8f1
scorecard 83.86% <ø> (-0.08%) ⬇️ Carriedforward from 97dd8f1
theme 64.54% <ø> (+0.09%) ⬆️ Carriedforward from 97dd8f1
translations 8.49% <ø> (ø) Carriedforward from 97dd8f1
x2a 78.79% <ø> (ø) Carriedforward from 97dd8f1

*This pull request uses carry forward flags. Click here to find out more.


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0496a27...f99bd64. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Jdubrick Jdubrick 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.

I believe we will need to update the express.json(..) portion when defining the routers to override the allowable body limit, or else it will default to whatever Express' default is. Adding an integration test to test this might be beneficial too, since right now we just unit test the validation itself

Notebook: https://github.com/redhat-developer/rhdh-plugins/blob/main/workspaces/lightspeed/plugins/lightspeed-backend/src/service/notebooks/notebooksRouters.ts#L70
Lightspeed: https://github.com/redhat-developer/rhdh-plugins/blob/main/workspaces/lightspeed/plugins/lightspeed-backend/src/service/router.ts#L108

@Jdubrick

Copy link
Copy Markdown
Contributor

I also want to ping @karthikjeeyar to verify if there will need to be any follow up UI changes to display to users when their attachments / body was too large?

@HusneShabbir HusneShabbir 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.

Configure express.json() middleware with explicit 60mb limit to handle
large query payloads with attachments (up to 50MB total attachment size).
This ensures the body parser limit aligns with the validation constraints.

Tested: Verified 60MB limit accommodates maximum valid requests (50MB
attachments + 32K query) while providing a safety ceiling.

Addresses reviewer feedback on PR redhat-developer#3359.

Co-Authored-By: Rajin Kichannagari <rkichann@redhat.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Rajin Kichannagari and others added 2 commits June 15, 2026 12:06
Adds integration tests that exercise the full request pipeline via
supertest, verifying that oversized queries are rejected with 400
before reaching the LCS proxy.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

@Jdubrick Jdubrick 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.

One comment about how we should handle the allocation of the updated body size, otherwise looks good

Comment thread workspaces/lightspeed/plugins/lightspeed-backend/src/service/router.ts Outdated
@Jdubrick

Copy link
Copy Markdown
Contributor

Can we add a changeset too @rajin-kichannagari ? Since there is a possibility someone sending a query with the new changes might hit the limit, we should document it in the changes

Rajin Kichannagari and others added 3 commits June 15, 2026 13:39
…eset

- Move express.json({ limit }) from router-level to route-level on /v1/query endpoints
- Add EXPRESS_JSON_BODY_LIMIT constant to constant.ts
- Add changeset for input validation changes
- Remove internal ticket references from code comments

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Extract attachment validation into validateAttachments helper
- Extract notebooks query validation into validateNotebooksQuery helper
- Use for-of loop instead of indexed for loop
- Consolidate type assertions in tests via callValidate helper

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@Jdubrick Jdubrick 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

@rajin-kichannagari rajin-kichannagari merged commit 6c4b038 into redhat-developer:main Jun 15, 2026
76 checks passed
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.

3 participants