Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ changes go in their respective binding's NEXT_CHANGELOG.
### Fixed

- `Session::open` authenticates once before resolving feature flags. A failed OAuth token request now fails the open immediately instead of being sent a second time by CreateSession.
- A timed-out or reset CloudFetch download no longer writes the presigned URL's signature (`sig=`, `X-Amz-Signature`) to the log or the returned error. The request URL in those messages now ends at the path, and debug request lines stop at `?`.

---
*Note: When making changes, please add your change under the appropriate
Expand Down
12 changes: 10 additions & 2 deletions src/client/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,11 @@ impl DatabricksHttpClient {

debug!(
"{:?}: {} {} (attempt {}/{})",
request_type, method, url, attempts, max_attempts
request_type,
method,
url.as_str().split('?').next().unwrap_or_default(),
attempts,
max_attempts
);

match self.client.execute(request).await {
Expand Down Expand Up @@ -1015,7 +1019,11 @@ impl DatabricksHttpClient {
format_args!("HTTP {}", status.as_u16()),
));
}
Err(e) => {
Err(mut e) => {
// reqwest's Display prints the request URL; a presigned URL's query is its credential.
if let Some(url) = e.url_mut() {
url.set_query(None);
}
let mut causes = super::error_chain(&e)
.map(ToString::to_string)
.collect::<Vec<_>>();
Expand Down
4 changes: 2 additions & 2 deletions src/reader/cloudfetch/chunk_downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ impl ChunkDownloader {
let start = Instant::now();

debug!(
"Downloading chunk {} from {} ({} bytes expected, attempt_timeout {:?})",
link.chunk_index, link.url, link.byte_count, attempt_timeout
"Downloading chunk {} ({} bytes expected, attempt_timeout {:?})",
link.chunk_index, link.byte_count, attempt_timeout
);

// Build request with custom headers from the link
Expand Down
97 changes: 97 additions & 0 deletions tests/presigned_url_logging.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright (c) 2026 Databricks, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! A failed CloudFetch request must not print the presigned URL's query (its
//! credential) in the returned error, the retry warning or the debug request
//! line.
//!
//! This is its own test binary because it captures `tracing` output. In the
//! unit-test binary, tests that open a session install a process-global
//! subscriber, which made a thread-local capture there miss events.

use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use std::time::Duration;

use databricks_sql_kernel::client::http::{DatabricksHttpClient, HttpClientConfig};
use databricks_sql_kernel::client::retry::{build_retry_configs, RequestType, RetryConfig};

#[derive(Clone, Default)]
struct CapturedLogs(Arc<Mutex<Vec<u8>>>);

impl std::io::Write for CapturedLogs {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
self.0.lock().unwrap().extend_from_slice(buf);
Ok(buf.len())
}
fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
}

#[tokio::test]
async fn request_error_and_logs_drop_presigned_query() {
let logs = CapturedLogs::default();
let writer = logs.clone();
tracing::subscriber::set_global_default(
tracing_subscriber::fmt()
.with_max_level(tracing::Level::DEBUG)
.with_ansi(false)
.with_writer(move || writer.clone())
.finish(),
)
.expect("the only subscriber in this binary");

// Nothing listens on a port whose listener was dropped.
let address = std::net::TcpListener::bind("127.0.0.1:0")
.unwrap()
.local_addr()
.unwrap();
let retry = RetryConfig {
min_wait: Duration::from_millis(10),
max_wait: Duration::from_millis(50),
overall_timeout: Duration::from_secs(10),
max_retries: 1,
override_retryable_codes: None,
};
let client = DatabricksHttpClient::new(
HttpClientConfig::default(),
build_retry_configs(&retry, &HashMap::new()),
)
.unwrap();
let request = client
.inner()
.get(format!(
"http://{address}/results_0?sig=SECRET&X-Amz-Signature=SECRET"
))
.build()
.unwrap();

let error = client
.execute_without_auth(request, RequestType::CloudFetchDownload)
.await
.expect_err("closed port must fail");
assert!(!error.to_string().contains("SECRET"), "{error}");
assert!(
error
.message
.contains(&format!("http://{address}/results_0)")),
"{error}"
);

let logs = String::from_utf8(logs.0.lock().unwrap().clone()).unwrap();
assert!(logs.contains("before retry"), "{logs}");
assert!(logs.contains("/results_0 (attempt 2/2)"), "{logs}");
assert!(!logs.contains("SECRET"), "{logs}");
}
Loading