diff --git a/changelogs/current.yaml b/changelogs/current.yaml index 5cdabee11648a..25aef20b24812 100644 --- a/changelogs/current.yaml +++ b/changelogs/current.yaml @@ -99,6 +99,12 @@ minor_behavior_changes: Fixed a bug where the truncation-length specifier for ``DYNAMIC_METADATA():Z`` was rejected in access log format strings. The length parameter is now accepted and truncates strings and other value types to the specified length. Structured data types are not truncated. +- area: wasm + change: | + Foreign functions are executed on effective context, if such is defined. Effective context is set by wasm SDKs, but was not used + when foreign function was called. This fixes an issue where a foreign function is called from HTTP or GRPC callback and + that foreign function needs a stream context, not root context. This behavior can be reverted by + setting the runtime guard ``envoy.reloadable_features.wasm_use_effective_ctx_for_foreign_functions`` to false. bug_fixes: # *Changes expected to improve the state of the world and are unlikely to have negative effects* diff --git a/source/common/runtime/runtime_features.cc b/source/common/runtime/runtime_features.cc index 8f409ba5370e4..b9b23b1f51a16 100644 --- a/source/common/runtime/runtime_features.cc +++ b/source/common/runtime/runtime_features.cc @@ -87,6 +87,7 @@ RUNTIME_GUARD(envoy_reloadable_features_use_migration_in_quiche); RUNTIME_GUARD(envoy_reloadable_features_use_response_decoder_handle); RUNTIME_GUARD(envoy_reloadable_features_validate_connect); RUNTIME_GUARD(envoy_reloadable_features_validate_upstream_headers); +RUNTIME_GUARD(envoy_reloadable_features_wasm_use_effective_ctx_for_foreign_functions); RUNTIME_GUARD(envoy_reloadable_features_websocket_allow_4xx_5xx_through_filter_chain); RUNTIME_GUARD(envoy_reloadable_features_websocket_enable_timeout_on_upgrade_response); RUNTIME_GUARD(envoy_reloadable_features_xds_failover_to_primary_enabled); diff --git a/source/extensions/common/wasm/foreign.cc b/source/extensions/common/wasm/foreign.cc index 64cdd64e985fa..c428ac1c7dcc0 100644 --- a/source/extensions/common/wasm/foreign.cc +++ b/source/extensions/common/wasm/foreign.cc @@ -210,7 +210,11 @@ RegisterForeignFunction registerSetEnvoyFilterStateForeignFunction( const std::function&) -> WasmResult { envoy::source::extensions::common::wasm::SetEnvoyFilterStateArguments args; if (args.ParseFromString(arguments)) { - auto context = static_cast(proxy_wasm::current_context_); + auto context = static_cast( + Runtime::runtimeFeatureEnabled( + "envoy.reloadable_features.wasm_use_effective_ctx_for_foreign_functions") + ? proxy_wasm::contextOrEffectiveContext() + : proxy_wasm::current_context_); return context->setEnvoyFilterState(args.path(), args.value(), toFilterStateLifeSpan(args.span())); } @@ -220,7 +224,11 @@ RegisterForeignFunction registerSetEnvoyFilterStateForeignFunction( RegisterForeignFunction registerClearRouteCacheForeignFunction( "clear_route_cache", [](WasmBase&, std::string_view, const std::function&) -> WasmResult { - auto context = static_cast(proxy_wasm::current_context_); + auto context = static_cast( + Runtime::runtimeFeatureEnabled( + "envoy.reloadable_features.wasm_use_effective_ctx_for_foreign_functions") + ? proxy_wasm::contextOrEffectiveContext() + : proxy_wasm::current_context_); context->clearRouteCache(); return WasmResult::Ok; });