Skip to content

Validate Couchbase request lengths before serialization - #3770

Open
songgaoye wants to merge 1 commit into
apache:masterfrom
songgaoye:fix/couchbase-request-lengths
Open

songgaoye wants to merge 1 commit into
apache:masterfrom
songgaoye:fix/couchbase-request-lengths

Conversation

@songgaoye

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: resolve

Problem Summary:

Couchbase request builders can narrow key, bucket, and body lengths to the
protocol's 16-bit and 32-bit fields while appending the full input. Oversized
inputs can produce malformed frames and desynchronize the connection.

What is changed and the side effects?

Changed:

  • Validate key, bucket, body, and SASL authentication payload lengths before
    serialization.
  • Reject oversized collection-aware requests before looking up collection
    metadata.
  • Return a length-specific error from the high-level request path.
  • Add tests for protocol length boundaries and for preserving the request
    buffer and pipeline count after rejection.

Side effects:

  • Performance effects: Adds constant-time length checks before request
    construction. The impact has not been benchmarked.

  • Breaking backward compatibility: Requests exceeding protocol length limits
    now fail instead of producing malformed frames.


Check List:

  • Built brpc_couchbase_unittest and passed all 8 CouchbaseUnitTest tests.
  • Added length-boundary and oversized-request regression tests.
  • Couchbase server integration tests were not run.
  • Please follow Contributor Covenant Code of Conduct.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Deterministic error and status information is not propagated for oversized bucket and credential failures, leaving callers with empty messages and potentially uninitialized status codes.

2 open issues
What changed in this PR

This PR hardens Couchbase binary request serialization by rejecting inputs that exceed the protocol's fixed-width key and body length fields before malformed frames can be produced.

Changes:

  • Added shared validation for request and SASL authentication lengths.
  • Applied validation across request builders, collection-aware operations, authentication, and high-level requests.
  • Added boundary and regression tests for oversized inputs and rejection-state preservation.
File Description
test/​brpc_couchbase_unittest.cpp Adds protocol-boundary and oversized-request regression tests, including buffer and pipeline preservation checks.
src/​brpc/​policy/​couchbase_protocol.h Defines shared length-validation helpers for Couchbase requests and SASL payloads.
src/​brpc/​policy/​couchbase_authenticator.cpp Rejects oversized SASL authentication payloads before serialization.
src/​brpc/​couchbase.cpp Integrates length validation across bucket, key, value, body, collection, counter, authentication, and high-level request paths.

Review effort: Lite

Comment thread src/brpc/couchbase.cpp
Comment on lines +461 to +463
if (!ValidCouchbaseRequestLengths(bucket_name.size(), 0, 0, 0)) {
return false;
}
Comment thread src/brpc/couchbase.cpp
Comment on lines +575 to +577
if (!policy::ValidCouchbaseAuthLengths(username.size(), password.size())) {
return false;
}
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