Skip to content

Commit

Permalink
feat/SYNC-4244_stale (#1546)
Browse files Browse the repository at this point in the history
* feat: log bad client state to stderr & metrics

Closes: SYNC-4244
  • Loading branch information
jrconlin authored May 9, 2024
1 parent fa5c9bd commit 8307955
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions syncserver/src/tokenserver/extractors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl TokenserverRequest {
.contains(&self.auth_data.client_state)
{
let error_message = "Unacceptable client-state value stale value".to_owned();
warn!("Client attempted stale value"; "uid"=> self.user.uid, "client_state"=> self.user.client_state.clone());
return Err(TokenserverError::invalid_client_state(error_message));
}

Expand Down
8 changes: 8 additions & 0 deletions tokenserver-common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ impl ReportableError for TokenserverError {
TokenType::BrowserId => Some("request.error.browser_id".to_owned()),
TokenType::Oauth => Some("request.error.oauth".to_owned()),
}
} else if matches!(
self,
TokenserverError {
status: "invalid-client-state",
..
}
) {
Some("request.error.invalid_client_state".to_owned())
} else {
None
}
Expand Down
2 changes: 2 additions & 0 deletions tokenserver-db/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
extern crate diesel;
#[macro_use]
extern crate diesel_migrations;
#[macro_use]
extern crate slog_scope;

mod error;
pub mod mock;
Expand Down
8 changes: 6 additions & 2 deletions tokenserver-db/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ impl TokenserverDb {
let raw_user = raw_users[0].clone();

// Collect any old client states that differ from the current client state
let old_client_states = {
let old_client_states: Vec<String> = {
raw_users[1..]
.iter()
.map(|user| user.client_state.clone())
Expand Down Expand Up @@ -463,7 +463,11 @@ impl TokenserverDb {
// The most up-to-date user doesn't have a node and is retired. This is an internal
// service error for compatibility reasons (the legacy Tokenserver returned an
// internal service error in this situation).
(_, None) => Err(DbError::internal("Tokenserver user retired".to_owned())),
(_, None) => {
let uid = raw_user.uid;
warn!("Tokenserver user retired"; "uid" => &uid);
Err(DbError::internal("Tokenserver user retired".to_owned()))
}
}
}
}
Expand Down

0 comments on commit 8307955

Please sign in to comment.