Skip to content

Commit

Permalink
fix possible crash of admin /config_dump (envoyproxy#28849)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: wbpcode <[email protected]>
  • Loading branch information
code authored Aug 7, 2023
1 parent 84d0109 commit 35684d7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
10 changes: 9 additions & 1 deletion source/common/protobuf/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,15 @@ bool redactOpaque(Protobuf::Message* message, bool ancestor_is_sensitive,
message_factory.GetPrototype(concrete_descriptor)->New());

// Finally we can unpack, redact, and repack the opaque message using the provided callbacks.
unpack(typed_message.get(), reflection, value_field_descriptor);

// Note: the content of opaque types may contain illegal content that mismatches the type_url
// which may cause unpacking to fail. We catch the exception here to avoid crashing Envoy.
TRY_ASSERT_MAIN_THREAD { unpack(typed_message.get(), reflection, value_field_descriptor); }
END_TRY CATCH(const EnvoyException& e, {
ENVOY_LOG_MISC(warn, "Could not unpack {} with type URL {}: {}", opaque_type_name, type_url,
e.what());
return false;
});
redact(typed_message.get(), ancestor_is_sensitive);
repack(typed_message.get(), reflection, value_field_descriptor);
return true;
Expand Down
16 changes: 16 additions & 0 deletions test/common/protobuf/utility_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,22 @@ type_url: type.googleapis.com/envoy.unknown.Message
EXPECT_TRUE(TestUtility::protoEqual(expected, actual));
}

TYPED_TEST(TypedStructUtilityTest, RedactTypedStructWithErrorContent) {
envoy::test::Sensitive actual;
TestUtility::loadFromYaml(R"EOF(
insensitive_typed_struct:
type_url: type.googleapis.com/envoy.test.Sensitive
value:
# The target field is string but value here is int.
insensitive_string: 123
# The target field is int but value here is string.
insensitive_int: "abc"
)EOF",
actual);

EXPECT_NO_THROW(MessageUtil::redact(actual));
}

TYPED_TEST(TypedStructUtilityTest, RedactEmptyTypeUrlTypedStruct) {
TypeParam actual;
TypeParam expected = actual;
Expand Down

0 comments on commit 35684d7

Please sign in to comment.