Skip to content

Conversation

@sumitkmr2
Copy link
Contributor

@sumitkmr2 sumitkmr2 commented Nov 20, 2025

Commit Message: Add response scrubber to the filter.
Additional Description:

  • Changes in filter_config.cc and filter.cc and respective tests for the response flow.
  • Also added a couple of tests to increase coverage for request flow as well.
  • Now, this filter has 100% line coverage.
    Risk Level: None.
    Testing: UTs are added. Integration tests will be added in a separate PR once IT setup PR ([ProtoApiScrubber] Add Integration Tests #42121) gets submitted.
    Docs Changes: None.
    Release Notes: None.
    Platform Specific Features:
    [Optional Runtime guard:]
    [Optional Fixes #Issue]
    [Optional Fixes commit #PR or SHA]
    [Optional Deprecated:]
    [Optional API Considerations:]

Signed-off-by: Sumit Kumar <sumitkmr@google.com>
@repokitteh-read-only
Copy link

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #42145 was opened by sumitkmr2.

see: more, trace.

Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
@sumitkmr2 sumitkmr2 marked this pull request as ready for review November 20, 2025 13:54
@sumitkmr2 sumitkmr2 requested a review from adisuissa as a code owner November 20, 2025 13:54
// vice-versa.
GrpcFieldExtraction::MessageConverterPtr request_msg_converter_{nullptr};

// Response message converter which converts Envoy Buffer data to StreamMessage (for scrubbing)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High-level comment:
looking at the request vs response related fields, it seems that there are the same group of objects needed for each of these. Using a generic struct with the relevant fields that is initialized differently for each of them may reduce the copy-paste between the two.
(not AI for this PR, just high-level observation to take into account).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes sense. I'll add that in the backlog for now, will pick it up once the current lined-up items are complete for the filter.

if (stream_message->message() == nullptr) {
// Expect end_stream=true when the MessageConverter signals an stream end.
ASSERT(end_stream);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style-nit: please remove empty lines that don't split logical code segments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


auto buf_convert_status =
response_msg_converter_->convertBackToBuffer(std::move(stream_message));
RELEASE_ASSERT(buf_convert_status.ok(), "failed to convert message back to envoy buffer");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure I had reservations about this RELEASE_ASSERT in the request path.
I'm worried this will create an attack vector that may crash the proxy.
If this is needed, can you add a comment before these lines describing why the release-assert is necessary here (say compared to sending local reply)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you are right. Although, the message converter is designed to be very robust, it is still possible that it can fail due to a bug introduced later. I've replaced release_assert() with rejectResponse which sends a local reply with appropriate error details. I'll make the change for request path in a separate PR.


using ProtoApiScrubberResponsePassThroughTest = ProtoApiScrubberFilterTest;

TEST_F(ProtoApiScrubberResponsePassThroughTest, UnaryResponseSingleBuffer) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add one-liner comments describing these tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Copy link
Contributor Author

@sumitkmr2 sumitkmr2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed comments, thanks!

// vice-versa.
GrpcFieldExtraction::MessageConverterPtr request_msg_converter_{nullptr};

// Response message converter which converts Envoy Buffer data to StreamMessage (for scrubbing)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes sense. I'll add that in the backlog for now, will pick it up once the current lined-up items are complete for the filter.

if (stream_message->message() == nullptr) {
// Expect end_stream=true when the MessageConverter signals an stream end.
ASSERT(end_stream);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


using ProtoApiScrubberResponsePassThroughTest = ProtoApiScrubberFilterTest;

TEST_F(ProtoApiScrubberResponsePassThroughTest, UnaryResponseSingleBuffer) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


auto buf_convert_status =
response_msg_converter_->convertBackToBuffer(std::move(stream_message));
RELEASE_ASSERT(buf_convert_status.ok(), "failed to convert message back to envoy buffer");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you are right. Although, the message converter is designed to be very robust, it is still possible that it can fail due to a bug introduced later. I've replaced release_assert() with rejectResponse which sends a local reply with appropriate error details. I'll make the change for request path in a separate PR.

Copy link
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@adisuissa adisuissa merged commit 716a496 into envoyproxy:main Nov 24, 2025
24 checks passed
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.

2 participants