Skip to content

fix(core): sanitize sse message#16686

Merged
kamilmysliwiec merged 1 commit intomasterfrom
fix/sanitize-sse-message
Apr 3, 2026
Merged

fix(core): sanitize sse message#16686
kamilmysliwiec merged 1 commit intomasterfrom
fix/sanitize-sse-message

Conversation

@kamilmysliwiec
Copy link
Copy Markdown
Member

@kamilmysliwiec kamilmysliwiec commented Apr 3, 2026

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe: Improves SSE stream security

What is the current behavior?

SseStream._transform()](https://github.com/nestjs/nest/blob/dea5279ef8fcb568de158003e4281759a2cd7675/packages/core/router/sse-stream.ts) interpolates message.type and message.id directly into Server-Sent Events text protocol output without sanitizing newline characters (\r, \n). Since the SSE protocol treats both \r and \n as field delimiters and \n\n as event boundaries, an attacker who can influence these fields through upstream data sources can inject arbitrary SSE events, spoof event types, and corrupt reconnection state. Spring Framework's own security patch (6e97587) validates these same fields (id, event) for the same reason.

Reported by [email protected]

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@kamilmysliwiec kamilmysliwiec added scope: core security Pull requests that address a security vulnerability labels Apr 3, 2026
@kamilmysliwiec kamilmysliwiec merged commit 83558ae into master Apr 3, 2026
2 checks passed
@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build fda38abe-1b95-436a-bef7-a5ecd1f6a067

Details

  • 5 of 5 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.002%) to 89.905%

Totals Coverage Status
Change from base Build 019374eb-f21e-4e67-ac6f-2680dbdd9734: 0.002%
Covered Lines: 7606
Relevant Lines: 8460

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: core security Pull requests that address a security vulnerability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants