fix(auth): use unwrap_or_default for SystemTime operations#57
Closed
echobt wants to merge 1 commit intodocs/standardize-timeout-documentationfrom
Closed
fix(auth): use unwrap_or_default for SystemTime operations#57echobt wants to merge 1 commit intodocs/standardize-timeout-documentationfrom
echobt wants to merge 1 commit intodocs/standardize-timeout-documentationfrom
Conversation
echobt
added a commit
that referenced
this pull request
Feb 4, 2026
This PR consolidates the following error handling fixes: - #48: Handle semaphore and init failures gracefully in async_utils - #54: Improve error handling in session storage operations (includes TOCTOU race fixes) - #55: Add validation for threshold, ratio, and token count fields - #56: Replace unwrap with proper error handling for client access - #57: Use unwrap_or_default for SystemTime operations - #61: Handle invalid request-id header values gracefully - #65: Improve error handling for timestamp and JSON operations in streaming Key changes: - Added graceful handling for semaphore and init failures - Bound ToolResponseStore size and cleanup consumed entries - Eliminated TOCTOU races in MCP server and plugin registry - Replaced unwrap() with proper error handling throughout - Added validation for config fields - Improved error propagation in middleware
Contributor
Author
|
Consolidated into #73 - fix: consolidated error handling improvements |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR replaces
.unwrap()calls onSystemTime::duration_since(UNIX_EPOCH)with.unwrap_or_default()in the authentication module for defensive programming.Problem
The current implementation uses
.unwrap()onSystemTime::duration_since(UNIX_EPOCH)in three locations withincortex-app-server/src/auth.rs:Claims::new()(line 48)Claims::is_expired()(line 78)AuthService::cleanup_revoked_tokens()(line 190)While extremely unlikely in practice,
duration_since(UNIX_EPOCH)can return anErrif the system clock is set to a time before the Unix epoch (January 1, 1970). In such a case, the current code would panic.Solution
Replace all three instances of:
with:
This provides a safe fallback to
Duration::default()(zero duration) in the unlikely event of a misconfigured system clock, preventing potential panics while maintaining normal operation for correctly configured systems.Testing
cargo check -p cortex-app-server