Skip to content

Drop chunk extensions containing NUL, not only CR or LF - #1344

Open
pjfanning wants to merge 1 commit into
apache:mainfrom
pjfanning:fix/chunk-extension-nul
Open

pjfanning wants to merge 1 commit into
apache:mainfrom
pjfanning:fix/chunk-extension-nul

Conversation

@pjfanning

Copy link
Copy Markdown
Member

Motivation

RenderSupport.renderChunk writes a chunk extension raw into the chunk-size line and drops it if it contains CR or LF — but not NUL. Since #1260 the header and trailer renderers drop all three via Rendering.isIllegalHeaderChar, so a NUL in an application-supplied chunk extension was the one rendering path where it still reached the wire.

Found while reviewing the threat model in #1295, which had to narrow P2 so its NUL claim excludes chunk extensions.

Modification

  • renderChunk checks the extension with Rendering.isIllegalHeaderChar, the same predicate as the header and trailer paths.
  • ResponseRendererSpec: a NUL case beside the existing CRLF one.

Result

A chunk extension containing CR, LF or NUL is dropped. renderChunk is shared, so this covers both server responses and client requests. Once this merges, the threat model's P2 can claim NUL for chunk extensions again.

Tests

  • sbt "http-core / Test / testOnly ...ResponseRendererSpec -- -z NUL": failed before the fix (rendered 7;ok\0bad)
  • sbt "http-core / Test / testOnly ...ResponseRendererSpec ...RequestRendererSpec": 63 passed
  • scalafmt --mode diff-ref=upstream/main: no changes
  • MiMa not run: body-only change to a private[http] method, no binary shape change

References

Refs #1256, #1260, #1295

Motivation:
renderChunk writes a chunk extension raw into the chunk-size line and
drops it if it contains CR or LF, but not NUL. Since apache#1260 the header
and trailer renderers drop all three via Rendering.isIllegalHeaderChar,
so a NUL in an application-supplied chunk extension was the one place
it still reached the wire. Review of the threat model in apache#1295 found
the gap: P2 had to be narrowed to exclude chunk extensions from its
NUL claim.

Modification:
Check the extension with Rendering.isIllegalHeaderChar, the predicate
the header and trailer paths use. Add a ResponseRendererSpec case
beside the existing CRLF one.

Result:
A chunk extension containing CR, LF or NUL is dropped on both the
server response and client request paths, which share renderChunk.

Tests:
- sbt "http-core / Test / testOnly ...ResponseRendererSpec -- -z NUL": failed before the fix (rendered "7;ok\0bad")
- sbt "http-core / Test / testOnly ...ResponseRendererSpec ...RequestRendererSpec": 63 passed
- scalafmt --mode diff-ref=upstream/main: no changes

References:
Refs apache#1256, apache#1260, apache#1295
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.

1 participant