Skip to content

fix(security): escape reflected input in SSO, roots, SIEM, LLM chat responses (CWE-79) - #5869

Open
jonpspri wants to merge 4 commits into
IBM:mainfrom
jonpspri:fix/xss-cwe79-batch
Open

fix(security): escape reflected input in SSO, roots, SIEM, LLM chat responses (CWE-79)#5869
jonpspri wants to merge 4 commits into
IBM:mainfrom
jonpspri:fix/xss-cwe79-batch

Conversation

@jonpspri

Copy link
Copy Markdown
Collaborator

Closes #5856

Summary

Reflected cross-site scripting (CWE-79) fixes: user-controlled input was returned unescaped in several API responses. This PR escapes or sanitizes every reflection site:

  • SSO provider delete (DELETE /sso/providers/{provider_id}): provider_id escaped with html.escape in the 404 detail and success message.
  • remove_root (DELETE /roots/{uri}): uri escaped in the debug log, error log, success message, and the 404 detail (the RootServiceNotFoundError message embeds the URI).
  • SIEM admin router: destination_name escaped before reaching the service layer; ValueError/KeyError details (which can embed attacker-controlled names) escaped in 400/404 responses.
  • SIEM export service: destination_name escaped in test_destination results (ok and failure paths).
  • LLM chat router: user_id passed through SecurityValidator.sanitize_display_text in connect, chat, disconnect, and status responses; disconnect warning text sanitized as well.

Changes

  • mcpgateway/routers/sso.pyhtml.escape(provider_id) in delete endpoint detail/message.
  • mcpgateway/main.pyhtml.escape on all uri reflections in remove_root.
  • mcpgateway/routers/siem.pyhtml.escape on destination name and error details.
  • mcpgateway/services/siem_export_service.pyhtml.escape(destination_name) in test results.
  • mcpgateway/routers/llmchat_router.pySecurityValidator.sanitize_display_text on reflected user_id/warning outputs.
  • Regression tests for every site exercising attacker-controlled input (e.g. <script>alert(1)</script>), asserting the raw payload is absent and the escaped form is present. Each test fails on unmodified main and passes with the fix (verified by temporarily reverting one escape and watching its test fail).

Verification

  • pytest tests/unit/mcpgateway/routers/test_sso_router.py tests/unit/mcpgateway/test_main.py tests/unit/mcpgateway/routers/test_siem.py tests/unit/mcpgateway/services/test_siem_export_service.py tests/unit/mcpgateway/routers/test_llmchat_router.py — 546 passed.
  • make ruff bandit interrogate pylint verify — all green.

jonpspri added 4 commits July 25, 2026 09:56
…WE-79)

The provider_id path parameter was reflected unescaped in the 404 detail and success message of DELETE /sso/providers/{provider_id}. Escape it with html.escape and add regression tests exercising attacker-controlled input.

Signed-off-by: Jonathan Springer <jps@s390x.com>
… output (CWE-79)

The uri path parameter was reflected unescaped in the remove_root debug log, 404 detail (via the RootServiceNotFoundError message, which embeds the URI), error log, and success message. Escape all reflections with html.escape and add regression tests exercising attacker-controlled input.

Signed-off-by: Jonathan Springer <jps@s390x.com>
destination_name and ValueError/KeyError details (which can embed attacker-controlled names) were reflected unescaped in SIEM admin API 400/404 responses and test_destination results. Escape with html.escape at the router and service layers and add regression tests exercising attacker-controlled input.

Signed-off-by: Jonathan Springer <jps@s390x.com>
user_id was reflected unsanitized in connect, chat, disconnect, and status responses, and exception text in the disconnect warning field. Apply SecurityValidator.sanitize_display_text to all reflected outputs and add regression tests exercising attacker-controlled input.

Signed-off-by: Jonathan Springer <jps@s390x.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: XSS (CWE-79) in SSO provider delete, remove_root, SIEM, and LLM chat responses

1 participant