Skip to content

Add some error chaining to log more on auth failure #2258

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

Merged
merged 3 commits into from
Mar 12, 2020
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
7 changes: 4 additions & 3 deletions src/controllers/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ impl<'a> UserAuthenticationExt for dyn Request + 'a {
user_id: token.user_id,
token_id: Some(token.id),
})
// Convert a NotFound (or other database error) into Unauthorized
.map_err(|_| Box::new(Unauthorized) as Box<dyn AppError>)
.chain_error(|| internal("invalid token"))
.chain_error(|| Box::new(Unauthorized) as Box<dyn AppError>)
} else {
// Unable to authenticate the user
Err(Box::new(Unauthorized))
Err(internal("no cookie session or auth header found"))
.chain_error(|| Box::new(Unauthorized) as Box<dyn AppError>)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/middleware/block_traffic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ impl Handler for BlockTraffic {
.iter()
.any(|value| self.blocked_values.iter().any(|v| v == value));
if has_blocked_value {
let cause = format!("blocked due to contents of header {}", self.header_name);
super::log_request::add_custom_metadata(req, "cause", cause);
let body = format!(
"We are unable to process your request at this time. \
This usually means that you are in violation of our crawler \
Expand Down
1 change: 1 addition & 0 deletions src/middleware/require_user_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl Handler for RequireUserAgent {
let has_user_agent = request_header(req, "User-Agent") != "";
let is_download = req.path().ends_with("download");
if !has_user_agent && !is_download {
super::log_request::add_custom_metadata(req, "cause", "no user agent");
let body = format!(
include_str!("no_user_agent_message.txt"),
request_header(req, "X-Request-Id"),
Expand Down