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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# CHANGELOG.md

## unreleased
- Fixed a bug where the single-sign-on oidc code would generate an unbounded amount of cookies when receiving many unauthenticated requests in sequence.

- Fixed a bug where the single-sign-on oidc code would generate an unbounded amount of cookies when receiving many unauthenticated requests in sequence.
- Fix: invalid UTF-8 in multipart text fields now returns `400 Bad Request` instead of `500 Internal Server Error`.

## 0.43.0

Expand Down
9 changes: 8 additions & 1 deletion src/webserver/http_request_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,14 @@ async fn extract_text(
.await
.map(|bytes| bytes.data)
.map_err(|e| anyhow!("failed to read form field data: {e}"))?;
Ok(String::from_utf8(data.to_vec())?)
String::from_utf8(data.to_vec()).map_err(|e| {
anyhow!(super::ErrorWithStatus {
status: actix_web::http::StatusCode::BAD_REQUEST,
})
.context(format!(
"could not parse multipart form field as utf-8 text: {e}"
))
})
}

async fn extract_file(
Expand Down
30 changes: 30 additions & 0 deletions tests/requests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,34 @@ async fn test_variables_function() -> actix_web::Result<()> {
Ok(())
}

#[actix_web::test]
async fn test_invalid_utf8_multipart_text_field_returns_bad_request() -> actix_web::Result<()> {
let req = get_request_to("/tests/requests/variables.sql")
.await?
.insert_header(("content-type", "multipart/form-data; boundary=1234567890"))
.set_payload(
b"--1234567890\r\n\
Content-Disposition: form-data; name=\"x\"\r\n\
Content-Type: text/plain\r\n\
\r\n\
\xff\r\n\
--1234567890--\r\n"
.as_slice(),
)
.to_srv_request();
let status = match main_handler(req).await {
Ok(resp) => resp.status(),
Err(err) => err.as_response_error().status_code(),
};

assert_eq!(
status,
StatusCode::BAD_REQUEST,
"assertion error, expected 400 bad request on invalid utf8 payload, got {}",
status
);

Ok(())
}

mod webhook_hmac;
Loading