Skip to content

Security: Sanitize Lightspeed Core error responses - #3296

Merged
Jdubrick merged 4 commits into
redhat-developer:mainfrom
rajin-kichannagari:fix/sanitize-lcs-error-responses
Jun 8, 2026
Merged

Security: Sanitize Lightspeed Core error responses#3296
Jdubrick merged 4 commits into
redhat-developer:mainfrom
rajin-kichannagari:fix/sanitize-lcs-error-responses

Conversation

@rajin-kichannagari

Copy link
Copy Markdown
Contributor

Hey, I just made a Pull Request!

Fixes an information disclosure vulnerability where error responses from Lightspeed Core were leaking internal details to clients.

The issue:
When LCS returns errors, we were forwarding the full error message to clients, which could include model names, provider info, org IDs, stack traces, etc. Not great for security.

What I changed:

  • Added a sanitizeLcsError() function that logs the full error server-side but only returns a generic message to the client
  • Updated the error handling in 4 endpoints: /v1/feedback, /v1/query/interrupt, /v1/query, and /v2/conversations/:id
  • Updated tests to make sure we're not leaking internal details

Example:
Before: {"error": "Error from lightspeed-core server: Model gpt-4-0613 failed with OpenAI API error: rate limit exceeded for organization org-abc123"}

After: {"error": "Error from lightspeed-core server while processing query"}

Full error details are still logged on the server for debugging.

✔️ Checklist

  • A changeset describing the change and affected packages
  • Added or Updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)

@rhdh-gh-app

rhdh-gh-app Bot commented Jun 4, 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.0

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

1 small comment, rest looks good

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

Jdubrick commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

/ok-to-test

@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 53.98%. Comparing base (5bc0a03) to head (54d8a44).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3296   +/-   ##
=======================================
  Coverage   53.98%   53.98%           
=======================================
  Files        2401     2402    +1     
  Lines       87397    87397           
  Branches    24196    24195    -1     
=======================================
+ Hits        47179    47182    +3     
+ Misses      38670    38667    -3     
  Partials     1548     1548           
Flag Coverage Δ *Carryforward flag
adoption-insights 83.58% <ø> (ø) Carriedforward from 5bc0a03
ai-integrations 70.03% <ø> (ø) Carriedforward from 5bc0a03
app-defaults 69.60% <ø> (ø) Carriedforward from 5bc0a03
augment 46.39% <ø> (ø) Carriedforward from 5bc0a03
bulk-import 72.86% <ø> (ø) Carriedforward from 5bc0a03
cost-management 17.48% <ø> (ø) Carriedforward from 5bc0a03
dcm 59.64% <ø> (ø) Carriedforward from 5bc0a03
extensions 62.24% <ø> (ø) Carriedforward from 5bc0a03
global-floating-action-button 74.30% <ø> (ø) Carriedforward from 5bc0a03
global-header 61.63% <ø> (ø) Carriedforward from 5bc0a03
homepage 51.52% <ø> (ø) Carriedforward from 5bc0a03
install-dynamic-plugins 56.23% <ø> (ø) Carriedforward from 5bc0a03
konflux 91.01% <ø> (ø) Carriedforward from 5bc0a03
lightspeed 68.52% <93.75%> (+0.05%) ⬆️
mcp-integrations 85.46% <ø> (ø) Carriedforward from 5bc0a03
orchestrator 37.33% <ø> (ø) Carriedforward from 5bc0a03
quickstart 62.09% <ø> (ø) Carriedforward from 5bc0a03
sandbox 79.42% <ø> (ø) Carriedforward from 5bc0a03
scorecard 83.84% <ø> (ø) Carriedforward from 5bc0a03
theme 64.54% <ø> (ø) Carriedforward from 5bc0a03
translations 8.49% <ø> (ø) Carriedforward from 5bc0a03
x2a 78.79% <ø> (ø) Carriedforward from 5bc0a03

*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 5bc0a03...54d8a44. 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.

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

Overall looks good, although the sanitizeLcsError() function uses any for both errorBody and logger
parameters. We should add proper TypeScript types:

  • logger should use the LoggerService type (already imported in types.ts from
    @backstage/backend-plugin-api).
  • errorBody should have an interface that matches the LCS error response
    structure (see the test mocks for examples of the shape).
  • for the function sanitizeLcsError lets capitalize the LCS bit.

If you can also address the SonarCloud analysis and failing CI after rebasing, I can take another look.

Comment thread workspaces/lightspeed/plugins/lightspeed-backend/src/service/utils.ts Outdated
Comment thread workspaces/lightspeed/plugins/lightspeed-backend/src/service/utils.ts Outdated

@JslYoon JslYoon 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, make sure all other comments are address too before merging

@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 added 4 commits June 8, 2026 13:53
Fixes information disclosure vulnerability where LCS error details
were being forwarded directly to clients.

Changes:
- Add sanitizeLcsError() function to sanitize error responses
- Update 4 endpoints to use sanitization
- Enhance tests to verify internal details are not exposed
- Move sanitizeLCSError to utils.ts for reusability
- Fix TypeScript types (use LoggerService, add LCSErrorResponse interface)
- Capitalize LCS in function name
- Fix failing test for conversation not found
- Add unit tests for utils to improve coverage
Extract duplicated error handling pattern into a reusable helper function.
This reduces duplication from 5.6% to under 3%.
- Add try/catch to handle cases where LCS doesn't return JSON
- Type the response parameter properly instead of using any
- Add tests for both JSON and non-JSON error responses
@rajin-kichannagari
rajin-kichannagari force-pushed the fix/sanitize-lcs-error-responses branch from 3fbd276 to 54d8a44 Compare June 8, 2026 17:53
@openshift-ci openshift-ci Bot removed the lgtm label Jun 8, 2026
@sonarqubecloud

sonarqubecloud Bot commented Jun 8, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
4.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@JslYoon

JslYoon commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci openshift-ci Bot added the lgtm label Jun 8, 2026
@Jdubrick
Jdubrick merged commit 2714194 into redhat-developer:main Jun 8, 2026
65 of 66 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