Skip to content

feat(upload): Create before upload - #5685

Merged
jjbayer merged 33 commits into
masterfrom
feat/upload-create
Mar 16, 2026
Merged

jjbayer merged 33 commits into
masterfrom
feat/upload-create

Conversation

@jjbayer

@jjbayer jjbayer commented Mar 3, 2026 •

Copy link
Copy Markdown
Member

This PR adds a new route to upload, so a user can now

  1. Either "create" or "create-with-upload" in the POST request.
  2. Additionally, an existing upload can be PATCHed.
  3. The service now only accepts Create or Upload messages, so the upstream will always receive two requests.

Once all experimental clients have switched to "create", we can remove the "create-with-upload" branch.

fixes: INGEST-802

@linear

linear Bot commented Mar 3, 2026 •

Copy link
Copy Markdown

@jjbayer
jjbayer force-pushed the feat/upload-create branch from 0329614 to 8f5c41c Compare March 10, 2026 08:47
jjbayer and others added 11 commits March 10, 2026 10:07
Move PatchPath/PatchQueryParams from endpoints to services/upload as
LocationPath/LocationQueryParams and reuse them in both the endpoint
handler and SignedLocation::try_from_str. The matchit router is kept
in a static LazyLock so it is only built once.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@jjbayer
jjbayer force-pushed the feat/upload-create branch from ec8d5ae to c47baa6 Compare March 12, 2026 07:09
@jjbayer
jjbayer marked this pull request as ready for review March 12, 2026 07:19
@jjbayer
jjbayer requested a review from a team as a code owner March 12, 2026 07:19
Comment thread relay-server/src/endpoints/upload.rs Outdated
Comment on lines +176 to +194
if content_length.is_none_or(|v| v > 0) {
let stream = body
.into_data_stream()
.map(|result| result.map_err(io::Error::other))
.boxed();
let (lower_bound, upper_bound) = match upload_length {
None => (1, config.max_upload_size()),
Some(u) => (u, u),
};
let stream = BoundedStream::new(stream, lower_bound, upper_bound);
let byte_counter = stream.byte_counter();

relay_log::trace!("Uploading");
let result = upload(&state, scoping, location, stream).await;
location = result.inspect_err(|e| {
relay_log::warn!(error = e as &dyn std::error::Error, "upload failed");
})?;
upload_offset = Some(byte_counter.get());
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This block will be removed once we remove "Creation-With-Upload".

Comment thread relay-auth/src/lib.rs
public_key
.iter()
.any(|p| self.verify(p, start_time, max_age))
.any(|p| self.verify(&[], p, start_time, max_age))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I changed the signature of verify so we can verify the integrity of the data, not just the signature itself.

Comment on lines +212 to +213
Path(upload::LocationPath { project_id, key }): Path<upload::LocationPath>,
Query(upload::LocationQueryParams { length, signature }): Query<upload::LocationQueryParams>,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There's a potential forward-compatibility issue here: Outdated external relays may parse the wrong set of query parameters, i.e. upstream Relays cannot transparently put new query parameters in its signed location.

There's an argument to be made that we should forward all query parameters, but I didn't like how that interacted with for example sentry_key=.

Comment thread relay-server/Cargo.toml
json-forensics = { workspace = true }
libc = { workspace = true }
liblzma = { workspace = true }
matchit = { workspace = true }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not a new dependency, axum already uses it.

Comment thread relay-server/Cargo.toml
serde_bytes = { workspace = true }
serde_json = { workspace = true }
serde_path_to_error = { workspace = true }
serde_urlencoded = { workspace = true }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not a new dependency, axum already uses it.

Comment thread relay-server/src/utils/stream.rs Resolved
Comment thread relay-server/src/endpoints/upload.rs Resolved
Comment thread relay-server/src/services/upload.rs Resolved

@Dav1dde Dav1dde left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As we discussed: For the forward compat we can make the middleware remove sentry_key

Comment thread relay-server/src/utils/tus.rs Resolved

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: PATCH handler omits upload size validation present in POST
    • Added the same max-upload-size guard in handle_patch so oversized signed lengths now return 413 Payload Too Large before stream processing.

Create PR

Or push these changes by commenting:

@cursor push fdfb7f6565
Preview (fdfb7f6565)
diff --git a/relay-server/src/endpoints/upload.rs b/relay-server/src/endpoints/upload.rs
--- a/relay-server/src/endpoints/upload.rs
+++ b/relay-server/src/endpoints/upload.rs
@@ -219,6 +219,9 @@
     let location = SignedLocation::from_parts(project_id, key, length, signature);
 
     let config = state.config();
+    if length.is_some_and(|len| len > config.max_upload_size()) {
+        return Err(StatusCode::PAYLOAD_TOO_LARGE.into());
+    }
 
     // There is no real "fast path" for streaming uploads. Always wait for the project config
     // to be loaded:

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

Comment thread relay-server/src/endpoints/upload.rs Resolved
Comment thread tests/integration/test_upload.py Resolved
Comment thread relay-server/src/utils/tus.rs Resolved
@jjbayer
jjbayer enabled auto-merge March 16, 2026 14:56

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

format!("/api/{project_id}/upload/").into()
match &self.kind {
RequestKind::Create { .. } => format!("/api/{project_id}/upload/"),
RequestKind::Upload { location, .. } => location.as_uri(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

PATCH path for upstream includes signature in URL path

Medium Severity

For the Upload variant, path() calls location.as_uri() which returns the signed URI including signature=... as a query parameter. This means the PATCH request sent upstream has the full signed URL as its path. When the upstream relay receives this PATCH request, the sentry_key is also appended (by the upstream relay client infra or the X-Sentry-Auth header). The RequestMeta extractor on the receiving end may parse sentry_key from query params, but the signature query param will be mixed in with sentry_key. This could cause issues depending on how the upstream parses query parameters, since the path itself already contains query params and the upstream infrastructure may append additional ones.

Fix in Cursor Fix in Web

router
});

let (path, query) = uri.split_once('?')?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Deferred-length locations fail parsing without query string

Medium Severity

try_from_str uses uri.split_once('?') which returns None when there's no query string. When length is None (deferred length from a trusted relay), Location::as_uri() returns /api/{id}/upload/{key}/ with no query params. The SignedLocation::as_uri() adds ?signature=... so the full signed URI always has a ?. However, if an upstream ever returns a location without a signature query param (e.g. a bare path), try_from_str would return None, causing an InvalidLocation error. More importantly, the LocationQueryParams struct has signature: String (not Option<String>), meaning if a query string exists but lacks signature, serde_urlencoded parsing fails silently via .ok()?.

Additional Locations (1)
Fix in Cursor Fix in Web

response
.headers_mut()
.insert(tus::UPLOAD_OFFSET, upload_offset.into());
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Redundant TUS_RESUMABLE header insertion in handle_post response

Low Severity

location.into_response() at line 195 calls SignedLocation::into_response which already includes TUS_RESUMABLE and TUS_EXTENSION via tus::response_headers(). Then lines 197–198 redundantly insert TUS_RESUMABLE again. The second insertion overwrites the first with the same value, so it's not incorrect, but it obscures the intent and the TUS_EXTENSION header from response_headers() may be unintentionally included or excluded depending on the code path.

Fix in Cursor Fix in Web

@jjbayer
jjbayer added this pull request to the merge queue Mar 16, 2026
Merged via the queue into master with commit 029a8b3 Mar 16, 2026
30 checks passed
@jjbayer
jjbayer deleted the feat/upload-create branch March 16, 2026 15:48
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