#30048·protobuf

[C++] Redacted TextFormat output exposes Any payload when its descriptor is unavailable

Author: kpavlov00Created Sep 21, 2026Updated Sep 25, 2026
Labelsbugc++text format

With both TextFormat::Printer::SetExpandAny(true) and SetRedactDebugString(true), an unresolved google.protobuf.Any is printed with its original wire bytes in value. Those bytes can contain fields marked debug_redact = true in the producer's schema. Printable strings remain visible in the output.

The same type URL and payload bytes are redacted correctly when the payload descriptor is available. Losing descriptor availability changes the result from redacted fields to exposed payload bytes, while PrintToString() still returns true.

What version of protobuf and what language are you using?

  • Language: C++.
  • Reproduced by compiling unmodified upstream v36.2, C++ runtime version 7.36.2.
  • Also inspected the same fallback in main at ec2ff447a4ca27b45a35ac26950d8072b6bdd8a2. Main was source-reviewed, not built for this report.

What operating system and compiler are you using?

macOS 26.6.2, arm64; Apple Clang 21.0.0 (clang-2100.3.34.2); C++20; CMake 4.4.3; Abseil 20260817.0.

What did you do?

The producer's payload schema is:

proto
syntax = "proto3";
package demo;

message Secret {
  string token = 1 [debug_redact = true];
}
  1. Construct this trusted schema in a separate descriptor pool and set token to the artificial test value "secret".
  2. Pack the payload into a generated google::protobuf::Any. Its descriptor pool does not contain demo.Secret.
  3. Create another Any with identical serialized bytes in a pool that does contain demo.Secret.
  4. Print both messages with SetExpandAny(true) and SetRedactDebugString(true).

The standalone reproduction below includes two controls: printing the payload directly and printing the Any with an available descriptor. Both redact the token. Only the Any with the unavailable descriptor exposes it. It uses no custom finder and requires no protoc invocation.

What did you expect to see?

With redaction enabled, an opaque Any payload should be suppressed when its type cannot be resolved. For example, printing its type URL and replacing its entire value with a redaction marker would preserve useful diagnostics without exposing unknown payload fields.

The consumer cannot discover per-field annotations without the payload descriptor, so a conservative fallback would need to redact the opaque value as a whole.

What did you see instead?

The test prints the following and exits with status 1 because the final output contains the test secret. The goo.gle/... debug marker can vary between runs.

Direct payload:
goo.gle/debugproto 
token: [REDACTED]
Resolved Any:
goo.gle/debugproto 
[type.googleapis.com/demo.Secret] {
  token: [REDACTED]
}
Unresolved Any:
goo.gle/debugproto 
type_url: "type.googleapis.com/demo.Secret"
value: "\n\006secret"

Stderr also includes:

WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
W0000 00:00:1790017883.461159 1509562 text_format.cc:2545] Can't print proto content: proto type type.googleapis.com/demo.Secret not found
FAIL: unresolved Any exposes the secret with redaction enabled
Standalone reproduction: repro.cc
cpp
#include <cstdlib>
#include <iostream>
#include <memory>
#include <stdexcept>
#include <string>

#include <google/protobuf/any.pb.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/message.h>
#include <google/protobuf/text_format.h>

namespace gp = google::protobuf;

void Check(bool condition, const char* description) {
  if (!condition) throw std::runtime_error(description);
}

std::string PrintRedacted(const gp::Message& message) {
  gp::TextFormat::Printer printer;
  printer.SetExpandAny(true);
  printer.SetRedactDebugString(true);
  std::string output;
  Check(printer.PrintToString(message, &output), "PrintToString failed");
  return output;
}

int main() {
  constexpr char kSecret[] = "secret";
  constexpr char kTypeUrl[] = "type.googleapis.com/demo.Secret";

  // Model a producer schema that is absent from the consumer's descriptor pool.
  gp::DescriptorPool producer_pool;
  gp::FileDescriptorProto any_schema;
  gp::Any::descriptor()->file()->CopyTo(&any_schema);
  Check(producer_pool.BuildFile(any_schema) != nullptr, "Any schema failed");

  gp::FileDescriptorProto schema;
  schema.set_name("secret.proto");
  schema.set_package("demo");
  schema.set_syntax("proto3");
  auto* message_schema = schema.add_message_type();
  message_schema->set_name("Secret");
  auto* field_schema = message_schema->add_field();
  field_schema->set_name("token");
  field_schema->set_number(1);
  field_schema->set_label(gp::FieldDescriptorProto::LABEL_OPTIONAL);
  field_schema->set_type(gp::FieldDescriptorProto::TYPE_STRING);
  field_schema->mutable_options()->set_debug_redact(true);
  const auto* file = producer_pool.BuildFile(schema);
  Check(file != nullptr, "Secret schema failed");

  gp::DynamicMessageFactory factory;
  const auto* secret_descriptor = file->message_type(0);
  std::unique_ptr<gp::Message> payload(factory.GetPrototype(secret_descriptor)->New());
  payload->GetReflection()->SetString(payload.get(), secret_descriptor->field(0), kSecret);

  gp::Any unresolved;
  Check(unresolved.PackFrom(*payload), "PackFrom failed");
  Check(unresolved.type_url() == kTypeUrl, "Unexpected type URL");
  Check(unresolved.GetDescriptor()->file()->pool()->FindMessageTypeByName("demo.Secret") == nullptr,
        "Consumer unexpectedly has the payload descriptor");

  // Same type URL and payload bytes; only descriptor availability changes.
  const auto* any_descriptor = producer_pool.FindMessageTypeByName("google.protobuf.Any");
  std::unique_ptr<gp::Message> resolved(factory.GetPrototype(any_descriptor)->New());
  Check(resolved->ParseFromString(unresolved.SerializeAsString()), "Any parse failed");

  const auto direct_output = PrintRedacted(*payload);
  const auto resolved_output = PrintRedacted(*resolved);
  const auto unresolved_output = PrintRedacted(unresolved);

  std::cout << "Direct payload:\n" << direct_output
            << "Resolved Any:\n" << resolved_output
            << "Unresolved Any:\n" << unresolved_output;
  Check(direct_output.find(kSecret) == std::string::npos, "Direct payload was not redacted");
  Check(resolved_output.find(kSecret) == std::string::npos, "Resolved Any was not redacted");

  if (unresolved_output.find(kSecret) != std::string::npos) {
    std::cerr << "FAIL: unresolved Any exposes the secret with redaction enabled\n";
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}
CMakeLists.txt and build commands

Save this file next to repro.cc:

cmake
cmake_minimum_required(VERSION 3.16)
project(any_redaction_repro LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(NOT DEFINED PROTOBUF_SOURCE_DIR)
    message(FATAL_ERROR "Set PROTOBUF_SOURCE_DIR to a protobuf source checkout")
endif()

add_subdirectory("${PROTOBUF_SOURCE_DIR}" protobuf-build)
add_executable(any_redaction_repro repro.cc)
target_link_libraries(any_redaction_repro PRIVATE protobuf::libprotobuf)
bash
curl -fL https://github.com/protocolbuffers/protobuf/archive/refs/tags/v36.2.tar.gz -o protobuf-v36.2.tar.gz
tar -xzf protobuf-v36.2.tar.gz
cmake -S . -B build \
  -DPROTOBUF_SOURCE_DIR="$PWD/protobuf-36.2" \
  -DCMAKE_BUILD_TYPE=Release \
  -Dprotobuf_BUILD_TESTS=OFF \
  -Dprotobuf_BUILD_PROTOC_BINARIES=OFF \
  -Dprotobuf_BUILD_LIBUPB=OFF \
  -Dprotobuf_INSTALL=OFF
cmake --build build --target any_redaction_repro --parallel 8
./build/any_redaction_repro

For my local build I additionally passed -DCMAKE_PREFIX_PATH=/opt/homebrew/opt/abseil -Dprotobuf_LOCAL_DEPENDENCIES_ONLY=ON to use the installed Abseil package.

Relevant implementation

In v36.2:

Anything else we should know?

This can affect a service or generic logging component that receives an Any payload whose schema is available to the producer but is absent from the component's descriptor pool. Escaping the wire bytes preserves their content; ordinary text secrets can remain directly readable.

Annotating the enclosing Any field itself with debug_redact = true and enabling redaction avoids this particular exposure by hiding the entire field. That does not help callers printing a standalone Any or relying on annotations in the payload schema.

I am reporting this as a serialization/debug-output hardening issue. The current security policy directs out-of-threat-model reports to public issues and places serialization/in-memory handling outside the CVE threat model.

Source: protocolbuffers/protobuf