Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Log HTTP request body on signature verification failure #3239

Merged
merged 8 commits into from
Jan 13, 2025
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
2 changes: 1 addition & 1 deletion rs/http_endpoints/public/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl IngressValidator {
message: "".into(),
})?
.map_err(|validation_error| {
validation_error_to_http_error(message_id, validation_error, &log)
validation_error_to_http_error(msg.as_ref(), validation_error, &log)
randombit marked this conversation as resolved.
Show resolved Hide resolved
})?;

let ingress_filter = ingress_filter.lock().unwrap().clone();
Expand Down
18 changes: 14 additions & 4 deletions rs/http_endpoints/public/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use ic_replicated_state::ReplicatedState;
use ic_types::{
crypto::threshold_sig::ThresholdSigPublicKey,
malicious_flags::MaliciousFlags,
messages::{HttpRequest, HttpRequestContent, MessageId},
messages::{HttpRequest, HttpRequestContent},
RegistryVersion, SubnetId, Time,
};
use ic_validator::{
Expand Down Expand Up @@ -246,12 +246,22 @@ impl IntoResponse for CborUserError {
}
}

pub(crate) fn validation_error_to_http_error(
message_id: MessageId,
pub(crate) fn validation_error_to_http_error<C: std::fmt::Debug + HttpRequestContent>(
request: &HttpRequest<C>,
err: RequestValidationError,
log: &ReplicaLogger,
) -> HttpError {
info!(log, "msg_id: {}, err: {}", message_id, err);
let message_id = request.id();
match err {
RequestValidationError::InvalidSignature(_) => {
info!(
log,
"msg_id: {}, err: {}, request: {:?}", message_id, err, request
)
}
_ => info!(log, "msg_id: {}, err: {}", message_id, err),
}

HttpError {
status: StatusCode::BAD_REQUEST,
message: format!("{err}"),
Expand Down
2 changes: 1 addition & 1 deletion rs/http_endpoints/public/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ pub(crate) async fn query(
{
Ok(Ok(_)) => {}
Ok(Err(err)) => {
let http_err = validation_error_to_http_error(request.id(), err, &log);
let http_err = validation_error_to_http_error(&request, err, &log);
return (http_err.status, http_err.message).into_response();
}
Err(_) => {
Expand Down
2 changes: 1 addition & 1 deletion rs/http_endpoints/public/src/read_state/canister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub(crate) async fn canister_read_state(
match validator.validate_request(&request_c, current_time(), &root_of_trust_provider) {
Ok(targets) => targets,
Err(err) => {
let http_err = validation_error_to_http_error(request.id(), err, &log);
let http_err = validation_error_to_http_error(&request, err, &log);
return (http_err.status, http_err.message).into_response();
}
};
Expand Down
Loading