fix(upload): Forward-compatible query params#6076
Conversation
| impl<'de> Deserialize<'de> for UploadParams { | ||
| fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
| where | ||
| D: serde::Deserializer<'de>, | ||
| { | ||
| struct UploadParamsVisitor; | ||
|
|
||
| impl<'de> serde::de::Visitor<'de> for UploadParamsVisitor { | ||
| type Value = UploadParams; | ||
|
|
||
| fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| formatter.write_str("upload query parameters") | ||
| } | ||
|
|
||
| fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> | ||
| where | ||
| A: serde::de::MapAccess<'de>, | ||
| { | ||
| let mut upload_params = BTreeMap::new(); | ||
|
|
||
| while let Some(key) = map.next_key::<&str>()? { | ||
| if key.starts_with("upload_") { | ||
| upload_params.insert(key.to_owned(), map.next_value()?); | ||
| } else { | ||
| map.next_value::<serde::de::IgnoredAny>()?; | ||
| } | ||
| } | ||
|
|
||
| Ok(UploadParams(upload_params)) | ||
| } | ||
| } | ||
|
|
||
| deserializer.deserialize_map(UploadParamsVisitor) | ||
| } |
There was a problem hiding this comment.
I added this custom parser to skip over query params that do not start with upload_ (e.g. sentry_key).
Co-authored-by: Sebastian Zivota <loewenheim@users.noreply.github.com>
Co-authored-by: elramen <158566966+elramen@users.noreply.github.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 521fa81. Configure here.
| RequestKind::Upload { location, .. } => location | ||
| .try_to_uri() | ||
| .expect("upload location should be serializable"), |
There was a problem hiding this comment.
Bug: The path() method uses .expect() on the result of try_to_uri(), which can fail during serialization. This creates an unnecessary panic path instead of propagating the error.
Severity: LOW
Suggested Fix
The UpstreamRequest::path() trait method should be changed to return a Result<Cow<'_, str>, Error>. This would allow propagating the serialization error from try_to_uri() up to the caller in SharedClient::build_request(), where it can be handled gracefully instead of causing a panic.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: relay-server/src/services/upload.rs#L771-L773
Potential issue: The `UploadRequest::path()` method calls `.expect()` on the result of
`try_to_uri()`, which performs URL-encoded serialization that can fail. This pull
request intentionally made `try_to_uri()` fallible by changing its signature to return a
`Result<String, Error>`, but this specific call site was not updated to handle the error
case. A panic here occurs within a synchronous `build_request` context, which will crash
the async task and could lead to a server crash. While serialization of the involved
types is unlikely to fail in practice, using `.expect()` introduces an avoidable panic
path and is inconsistent with the PR's goal of improved error handling.

For the sake of forward-compatibility, add an "other" variant to the location query params enum. Instead of denylisting certain keys, like
sentry_key, prefix all upload-relevant keys withupload_such that only those get picked up by the upload service.Fixes: INGEST-807