You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The logic for extracting session IDs from Authorization headers is duplicated across 3 locations in the server package. This creates maintenance burden as auth-related changes must be applied consistently across all locations.
Duplication Details
Pattern: Authorization Header Session Extraction
Severity: High
Occurrences: 3 instances
Locations:
internal/server/routed.go (lines 106-118)
internal/server/transport.go (lines 104-114)
internal/server/sdk_logging.go (lines 165-170 - helper function extractSessionID)
Code Sample (repeated 2x inline):
// Extract session ID from Authorization header// Per spec 7.1: When API key is configured, Authorization contains plain API key// When API key is not configured, supports Bearer token for backward compatibilityauthHeader:=r.Header.Get("Authorization")
varsessionIDstringifstrings.HasPrefix(authHeader, "Bearer ") {
// Bearer token format (for backward compatibility when no API key)sessionID=strings.TrimPrefix(authHeader, "Bearer ")
sessionID=strings.TrimSpace(sessionID)
} elseifauthHeader!="" {
// Plain format (per spec 7.1 - API key is session ID)sessionID=authHeader
}
// Reject requests without Authorization headerifsessionID=="" {
// ... error handling (slightly different per location)returnnil
}
Additional Instance: sdk_logging.go already has extracted function extractSessionID() but it's not reused by the other locations.
Impact Analysis
Maintainability: Any change to auth spec (e.g., supporting new token formats) requires updating 3 locations
Bug Risk: Inconsistent implementations can lead to auth bypasses or different behavior between routed/unified modes
Code Bloat: ~20 lines duplicated across 2 locations + 1 helper function not being reused
🔍 Duplicate Code Pattern: Authorization Header Parsing
Part of duplicate code analysis: #375
Summary
The logic for extracting session IDs from Authorization headers is duplicated across 3 locations in the server package. This creates maintenance burden as auth-related changes must be applied consistently across all locations.
Duplication Details
Pattern: Authorization Header Session Extraction
internal/server/routed.go(lines 106-118)internal/server/transport.go(lines 104-114)internal/server/sdk_logging.go(lines 165-170 - helper functionextractSessionID)Code Sample (repeated 2x inline):
Additional Instance:
sdk_logging.goalready has extracted functionextractSessionID()but it's not reused by the other locations.Impact Analysis
Refactoring Recommendations
1. Extract to Shared Auth Utility (Recommended)
internal/auth/session.gowith:internal/auth/session.go(new file)internal/auth/header.gopackage structure2. Reuse Existing Helper
extractSessionID()fromsdk_logging.gotoauthpackagerouted.goandtransport.goto use the helper3. Add Validation Tests
internal/auth/Implementation Checklist
internal/auth/header.gointernal/auth/session.gowithExtractSessionID()functionrouted.goto use shared function (remove inline logic)transport.goto use shared function (remove inline logic)sdk_logging.goto use shared function (remove duplicate helper)Parent Issue
See parent analysis report: #375
Related to #375