Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KTOR-8015 CIO: Do not accept CR as line delimiter in requests #4668

Merged
merged 4 commits into from
Feb 19, 2025

Conversation

osipxd
Copy link
Member

@osipxd osipxd commented Feb 12, 2025

Subsystem
Server (CIO)

Motivation
KTOR-8015 Server accepts \r without a following \n as a valid line terminator in chunked transfer encoding

Solution
Add a parameter lineEnding to readUTF8Line to make it possible to ensure that a proper line ending is used.

@osipxd osipxd self-assigned this Feb 12, 2025
Comment on lines 492 to 496
private fun LineEndingMode.assertIncludes(other: LineEndingMode) {
if (other !in this) {
throw EOFException("Unexpected line ending $other, while expected $this")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think EOF is technically correct since it's malformed data but the input hasn't ended, maybe just an IOException would do.

Could there be scenarios here where you'd simply want to ignore the partial line ending?

Copy link
Member Author

@osipxd osipxd Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think EOF is technically correct

Changed to IOException

Could there be scenarios here where you'd simply want to ignore the partial line ending?

That is how Netty works. It just ignores everything until the LF line ending. It makes a server more tolerant to malformed requests. The question is, do we want to make it tolerant?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to throw an exception as Jetty and Tomcat do it. Also, a user says that the behavior of Google Load Balancer (in Netty it's the same: parse input as one request with two chunks) is incorrect for them

@osipxd osipxd force-pushed the osipxd/kmp-engine-test-base branch 3 times, most recently from 8a50989 to 4231ba6 Compare February 13, 2025 10:56
@osipxd osipxd changed the title KTOR-8015 CIO: Do not accept CR as line delimiter in chunked requests KTOR-8015 CIO: Do not accept CR as line delimiter in requests Feb 13, 2025
@osipxd osipxd force-pushed the osipxd/kmp-engine-test-base branch 3 times, most recently from 9e166eb to 148dc2c Compare February 13, 2025 12:05
@osipxd osipxd requested a review from marychatte February 13, 2025 12:08
@osipxd osipxd force-pushed the osipxd/kmp-engine-test-base branch 2 times, most recently from ef09f08 to 7dd274a Compare February 18, 2025 15:20
@osipxd osipxd marked this pull request as ready for review February 18, 2025 15:20
Copy link
Member

@marychatte marychatte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@osipxd osipxd force-pushed the osipxd/kmp-engine-test-base branch from 7dd274a to 2b2dd06 Compare February 19, 2025 10:08
@osipxd osipxd enabled auto-merge (squash) February 19, 2025 10:08
@osipxd osipxd force-pushed the osipxd/kmp-engine-test-base branch from 2b2dd06 to 4287289 Compare February 19, 2025 10:21
@osipxd osipxd force-pushed the osipxd/kmp-engine-test-base branch from 4287289 to 0be88f5 Compare February 19, 2025 15:36
@osipxd osipxd merged commit 274b09a into main Feb 19, 2025
14 of 17 checks passed
@osipxd osipxd deleted the osipxd/kmp-engine-test-base branch February 19, 2025 16:26
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