Skip to content

fix: report EOF without close_notify as UnexpectedEof - #74

Merged
djc merged 1 commit into
rustls:mainfrom
ArniDagur:fix-truncation-detection
Jul 31, 2026
Merged

fix: report EOF without close_notify as UnexpectedEof#74
djc merged 1 commit into
rustls:mainfrom
ArniDagur:fix-truncation-detection

Conversation

@ArniDagur

Copy link
Copy Markdown
Contributor

A transport EOF before the peer's close_notify means the TLS stream was truncated. A TCP FIN is not authenticated, so an attacker who can inject one could silently cut a stream short. The ktls crate's current behaviour returns a clean Ok(0), silently accepting truncation.

Rustls however returns UnexpectedEof: https://github.com/rustls/rustls/blob/72d0dd69c08700816a3a4f45a2c24fab630c1e07/rustls/src/conn/mod.rs#L506-L510

I chose the error message of ktls to match rustls. See rustls/rustls#790

A transport EOF before the peer's close_notify means the TLS stream
was truncated, and a TCP FIN is not authenticated, so an attacker who
can inject one could silently cut a stream short. The `ktls` crate's
current behaviour returns a clean `Ok(0)`, silently accepting truncation.

Rustls however returns `UnexpectedEof`: https://github.com/rustls/rustls/blob/72d0dd69c08700816a3a4f45a2c24fab630c1e07/rustls/src/conn/mod.rs#L506-L510

I chose the error message of `ktls` to match `rustls`. See rustls/rustls#790

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

Makes sense, thanks.

@ArniDagur

Copy link
Copy Markdown
Contributor Author

Could you perform the merge if you think the PR looks good?

@djc

djc commented Jul 31, 2026

Copy link
Copy Markdown
Member

Could you perform the merge if you think the PR looks good?

I prefer to wait for another maintainer to do an additional round of review.

@djc
djc added this pull request to the merge queue Jul 31, 2026
Merged via the queue into rustls:main with commit d959638 Jul 31, 2026
2 checks passed
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.

3 participants