Repository navigation
Fix Arrow Flight Basic authentication for clients sending unpadded Base64 - #115085
Conversation
…se64 The Go Flight client (used, for example, by the ADBC Flight SQL driver with the plain username/password options, which call AuthenticateBasicToken) sends the credentials in the 'authorization: Basic <credentials>' header with the Base64 not padded with '='. Poco::Base64Decoder requires padding by default and throws Poco::DataFormatException, which escaped AuthMiddlewareFactory::StartCall (it only caught DB::Exception) into gRPC, so such clients received a meaningless 'UNKNOWN: Unexpected error in RPC handling' status instead of authenticating successfully. Decode the credentials with the BASE64_NO_PADDING option, which accepts both padded and unpadded input, convert a failed decode into a proper AUTHENTICATION_FAILED exception, and catch the remaining exception types in StartCall so they are returned as proper Flight error statuses. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [f8c83b4] Summary: ✅
AI ReviewSummaryThis PR fixes the main Arrow Flight regression by accepting unpadded Base64 in Findings
Final VerdictStatus: Minimum required action: reject colonless decoded LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 27/32 (84.38%) · Uncovered code |
When an `authorization` header is present, reject it unless it is a supported `Basic` or `Bearer` header. This prevents malformed schemes from falling through to default authentication.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 10 s compile time in total, 7 of them have a recent master baseline. |
…ic-auth-nopadding
| std::string credentials; | ||
| try | ||
| { | ||
| credentials = base64Decode(std::string(auth_str.substr(basic_prefix.size())), /* url_encoding = */ false, /* no_padding = */ true); |
There was a problem hiding this comment.
This now fails cleanly when the Base64 itself is invalid, but a decoded Basic payload without the required : separator still authenticates instead of failing closed. For example, authorization: Basic ZGVmYXVsdA decodes to default; the npos branch below turns that into { "default", "" }, so a malformed header logs in as the default user rather than returning Unauthenticated.
Since this PR's contract is "malformed authorization headers become proper authentication errors", I think the no-: case needs to throw AUTHENTICATION_FAILED as well, with a regression test alongside test_basic_auth_malformed_base64.
There was a problem hiding this comment.
🕵 Addressed in #115347: colonless decoded Basic credentials now return Unauthenticated, with a focused integration regression test.
The Arrow Flight server rejected clients that send the
authorization: Basic <credentials>header with the Base64-encoded credentials not padded with=. The Go Flight client does exactly that — for example, the ADBC Flight SQL driver with the plainusername/passwordoptions performs theAuthenticateBasicTokenhandshake this way, so connecting to ClickHouse failed with a meaningless error:The cause:
Poco::Base64Decoderrequires padding by default and throwsPoco::DataFormatException, which escapedAuthMiddlewareFactory::StartCall(it only caughtDB::Exception) into gRPC, which converted it to the genericUNKNOWNstatus above.The fix:
BASE64_NO_PADDINGoption, which accepts both padded and unpadded input, so Go-based Flight clients (including ADBC) can authenticate.AUTHENTICATION_FAILEDexception, reported to the client as anUnauthenticatedFlight error with a clear message.StartCallso no exception can escape into gRPC and produce the meaninglessUnexpected error in RPC handlingstatus.Verified end-to-end with
adbc_driver_flightsql1.12.0: connecting with plainusername/passwordand running a query now works, while padded Basic credentials, Bearer tokens, and wrong-password errors behave as before.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Arrow Flight server: accept
Basicauthentication credentials encoded in Base64 without padding, as sent by Go-based Flight clients such as the ADBC Flight SQL driver, and return a proper authentication error instead of a genericUnexpected error in RPC handlingwhen theauthorizationheader is malformed.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/115085]
Version info
26.8.1.1649(included in26.8and later)