Skip to content

return error instead of panicking on host stream type mismatch - #14733

Merged
alexcrichton merged 6 commits into
bytecodealliance:mainfrom
alexcrichton:stream-type-mismatch
Oct 14, 2026
Merged

alexcrichton merged 6 commits into
bytecodealliance:mainfrom
alexcrichton:stream-type-mismatch

Conversation

@alexcrichton

Copy link
Copy Markdown
Member

Previously, UntypedWriteBuffer::get_mut panicked on type mismatch, which created a hazard for embedders which might receive their own stream back from the guest using a different Rust-level item type despite having the same component-model-level item type. Now we return an error instead.

Part of GHSA-63h4-6cx9-pjfj

Previously, `UntypedWriteBuffer::get_mut` panicked on type mismatch, which
created a hazard for embedders which might receive their own stream back from
the guest using a different Rust-level item type despite having the same
component-model-level item type.  Now we return an error instead.
@alexcrichton
alexcrichton requested a review from a team as a code owner October 14, 2026 15:24
@alexcrichton
alexcrichton requested review from cfallin and removed request for a team October 14, 2026 15:24
@cfallin

cfallin commented Oct 14, 2026

Copy link
Copy Markdown
Member

(merge conflict at the moment)

@alexcrichton
alexcrichton added this pull request to the merge queue Oct 14, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 14, 2026
@alexcrichton
alexcrichton added this pull request to the merge queue Oct 14, 2026
Merged via the queue into bytecodealliance:main with commit afde5b4 Oct 14, 2026
53 checks passed
@alexcrichton
alexcrichton deleted the stream-type-mismatch branch October 14, 2026 21:09
pchickey pushed a commit to pchickey/wasmtime that referenced this pull request Oct 19, 2026
This commit fixes an issue where a `StreamAny` can be used to re-type a
future or stream in a manner that can cause a panic within Wasmtime in
certain host situations. The fix here is to unconditionally perform a
type-check when lowering a future or stream into a guest. This is
already required for `{Stream,Future}Any`, and it's additionally
required in this issue when the `T` in `StreamReader<T>` contains a
`StreamAny`, for example. This technically makes the static type-check
of `StreamReader<u32>` redundant, but it seems best to fully close this
hole since bytecodealliance#14733 was not a complete fix for this class of issues.
pchickey pushed a commit to pchickey/wasmtime that referenced this pull request Oct 19, 2026
This commit fixes an issue where a `StreamAny` can be used to re-type a
future or stream in a manner that can cause a panic within Wasmtime in
certain host situations. The fix here is to unconditionally perform a
type-check when lowering a future or stream into a guest. This is
already required for `{Stream,Future}Any`, and it's additionally
required in this issue when the `T` in `StreamReader<T>` contains a
`StreamAny`, for example. This technically makes the static type-check
of `StreamReader<u32>` redundant, but it seems best to fully close this
hole since bytecodealliance#14733 was not a complete fix for this class of issues.
pchickey added a commit that referenced this pull request Oct 19, 2026
* [release-48] wasi-http: Prohibit duplicate content length headers

Setting more than one value for content-length is now rejected with
HeaderError::InvalidSyntax in p2 and p3.

Fixes GHSA-r8xh-cgf7-392j

(cherry picked from commit f843085)

* [release-48] wasmtime-wasi-http p3: apply forbidden header check to trailers

in a backwards-compatible manner by introducing a new
WasiHttpHooks::forbidden_header_filter method. Embedders which customized
WasiHttpHooks::is_forbidden_header must switch to using this new method in
order to block trailers which are not the DEFAULT_FORBIDDEN_HEADERS.

Fixes GHSA-jxcf-8qw5-5c33

* [release-48] wasi-http p3: correctly enforce content-length for response bodies

The prior implementation did not enforce that this was valid when
splicing an existing body into a new response, which made it possible to
perform response splitting attacks when responding to a
non-spec-compliant client.

Fixes GHSA-9prg-84vf-g5fc

* Cranelift/aarch64: fix `br_table`s with very large target count.

Previously, the `JTSequence` macro-instruction contained a conditional
branch for the default (selector greater than table size) case. This
default branch on aarch64 has a +/- 1MiB range. The `JTSequence` also
contains the entire table of 32-bit offsets for each `br_table`
target. As a result of these two facts, a branch may have an
out-of-bounds target and silently wrap the offset, resulting in an
incorrect branch target.

This PR fixes the sequence to instead use the offset table for the
default case too. The conditional branch is converted into a
conditional-select that clamps the index to the last table
entry (which we fill with the default target) if out-of-bounds.

* Review feedback.

* Review feedback.

* 48.0.7: release notes

* Centralize type-checks of futures/streams

This commit fixes an issue where a `StreamAny` can be used to re-type a
future or stream in a manner that can cause a panic within Wasmtime in
certain host situations. The fix here is to unconditionally perform a
type-check when lowering a future or stream into a guest. This is
already required for `{Stream,Future}Any`, and it's additionally
required in this issue when the `T` in `StreamReader<T>` contains a
`StreamAny`, for example. This technically makes the static type-check
of `StreamReader<u32>` redundant, but it seems best to fully close this
hole since #14733 was not a complete fix for this class of issues.

* release notes: release date, separator

---------

Co-authored-by: Chris Fallin <chris@cfallin.org>
Co-authored-by: Alex Crichton <alex@alexcrichton.com>
pchickey added a commit that referenced this pull request Oct 19, 2026
* [release-49] wasi-http: Prohibit duplicate content length headers

Setting more than one value for content-length is now rejected with
HeaderError::InvalidSyntax in p2 and p3.

Fixes GHSA-r8xh-cgf7-392j

(cherry picked from commit f843085)

* [release-49] wasmtime-wasi-http p3: apply forbidden header check to trailers

in a backwards-compatible manner by introducing a new
WasiHttpHooks::forbidden_header_filter method. Embedders which customized
WasiHttpHooks::is_forbidden_header must switch to using this new method in
order to block trailers which are not the DEFAULT_FORBIDDEN_HEADERS.

Fixes GHSA-jxcf-8qw5-5c33

* [release-49] wasi-http p3: correctly enforce content-length for response bodies

The prior implementation did not enforce that this was valid when
splicing an existing body into a new response, which made it possible to
perform response splitting attacks when responding to a
non-spec-compliant client.

Fixes GHSA-9prg-84vf-g5fc

* Cranelift/aarch64: fix `br_table`s with very large target count.

Previously, the `JTSequence` macro-instruction contained a conditional
branch for the default (selector greater than table size) case. This
default branch on aarch64 has a +/- 1MiB range. The `JTSequence` also
contains the entire table of 32-bit offsets for each `br_table`
target. As a result of these two facts, a branch may have an
out-of-bounds target and silently wrap the offset, resulting in an
incorrect branch target.

This PR fixes the sequence to instead use the offset table for the
default case too. The conditional branch is converted into a
conditional-select that clamps the index to the last table
entry (which we fill with the default target) if out-of-bounds.

* Review feedback.

* Review feedback.

* 49.0.4: release notes

* Centralize type-checks of futures/streams

This commit fixes an issue where a `StreamAny` can be used to re-type a
future or stream in a manner that can cause a panic within Wasmtime in
certain host situations. The fix here is to unconditionally perform a
type-check when lowering a future or stream into a guest. This is
already required for `{Stream,Future}Any`, and it's additionally
required in this issue when the `T` in `StreamReader<T>` contains a
`StreamAny`, for example. This technically makes the static type-check
of `StreamReader<u32>` redundant, but it seems best to fully close this
hole since #14733 was not a complete fix for this class of issues.

* release notes: release date, separator

---------

Co-authored-by: Chris Fallin <chris@cfallin.org>
Co-authored-by: Alex Crichton <alex@alexcrichton.com>
pchickey added a commit that referenced this pull request Oct 19, 2026
* [release-50] wasi-http: Prohibit duplicate content length headers

Setting more than one value for content-length is now rejected with
HeaderError::InvalidSyntax in p2 and p3.

Fixes GHSA-r8xh-cgf7-392j

(cherry picked from commit f843085)

* [release-50] wasmtime-wasi-http p3: apply forbidden header check to trailers

by changing the WasiHttpHooks::is_forbidden_header method to
WasiHttpHooks::forbidden_header_filter, which is a boxed (arced) closure
instead of a direct method. Embedders which customized
WasiHttpHooks::is_forbidden_header must switch to using this new method
in order to block trailers which are not the DEFAULT_FORBIDDEN_HEADERS.

Fixes GHSA-jxcf-8qw5-5c33

* [release-50] wasi-http p3: correctly enforce content-length for response bodies

The prior implementation did not enforce that this was valid when
splicing an existing body into a new response, which made it possible to
perform response splitting attacks when responding to a
non-spec-compliant client.

Fixes GHSA-9prg-84vf-g5fc

* Cranelift/aarch64: fix `br_table`s with very large target count.

Previously, the `JTSequence` macro-instruction contained a conditional
branch for the default (selector greater than table size) case. This
default branch on aarch64 has a +/- 1MiB range. The `JTSequence` also
contains the entire table of 32-bit offsets for each `br_table`
target. As a result of these two facts, a branch may have an
out-of-bounds target and silently wrap the offset, resulting in an
incorrect branch target.

This PR fixes the sequence to instead use the offset table for the
default case too. The conditional branch is converted into a
conditional-select that clamps the index to the last table
entry (which we fill with the default target) if out-of-bounds.

* Review feedback.

* Review feedback.

* Centralize type-checks of futures/streams

This commit fixes an issue where a `StreamAny` can be used to re-type a
future or stream in a manner that can cause a panic within Wasmtime in
certain host situations. The fix here is to unconditionally perform a
type-check when lowering a future or stream into a guest. This is
already required for `{Stream,Future}Any`, and it's additionally
required in this issue when the `T` in `StreamReader<T>` contains a
`StreamAny`, for example. This technically makes the static type-check
of `StreamReader<u32>` redundant, but it seems best to fully close this
hole since #14733 was not a complete fix for this class of issues.

* update release notes with PRs where these landed on main

---------

Co-authored-by: Chris Fallin <chris@cfallin.org>
Co-authored-by: Alex Crichton <alex@alexcrichton.com>
jrandolf pushed a commit to jrandolf/wasmtime that referenced this pull request Oct 19, 2026
This commit fixes an issue where a `StreamAny` can be used to re-type a
future or stream in a manner that can cause a panic within Wasmtime in
certain host situations. The fix here is to unconditionally perform a
type-check when lowering a future or stream into a guest. This is
already required for `{Stream,Future}Any`, and it's additionally
required in this issue when the `T` in `StreamReader<T>` contains a
`StreamAny`, for example. This technically makes the static type-check
of `StreamReader<u32>` redundant, but it seems best to fully close this
hole since bytecodealliance#14733 was not a complete fix for this class of issues.
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