Codebuff implements secure authentication between the CLI and web application using fingerprint-based device identification.
sequenceDiagram
participant CLI as CLI
participant Web as web app
participant DB as Database
CLI->>Web: POST /api/auth/cli/code {fingerprintId}
Web->>Web: Generate signed auth payload (1h expiry)
Web->>DB: Store payload behind opaque browser token
Web->>CLI: Return login URL with opaque token
CLI->>CLI: Open browser
Note over Web: User completes OAuth
Web->>DB: Resolve opaque token to signed payload
Web->>DB: Mark opaque token consumed
Web->>DB: Check fingerprint ownership
Web->>DB: Create/update session
loop Every 5s
CLI->>Web: GET /api/auth/cli/status
Web->>DB: Check session
end
- CLI generates fingerprint from hardware info + 8 random bytes
- Uses
calculateFingerprint()in the SDK - Continues to core flow with new fingerprintId
- CLI calls POST
/api/auth/cli/logout - Deletes session from database
- Resets fingerprint
sig_hashto null (unclaimed) - Deletes local
credentials.json
- Web creates fingerprint record in database
- Creates new session with fingerprint_id
- Returns user credentials to CLI
- Web finds existing fingerprint
- Verifies ownership via
sig_hashmatch or null value - Updates/creates session
- Returns user credentials to CLI
- Fingerprint exists with different
sig_hash - Logs security event
- Returns authentication error
- Auth code validation fails or expired (1h limit)
- Opaque browser tokens resolve expired signed payloads before returning the expired-code error
- Returns authentication error
- Signed auth payloads expire after 1 hour
- Browser login URLs use opaque 43-character tokens instead of exposing the signed auth payload
- Opaque browser tokens are stored in
verificationTokenundercli-login:<token>and atomically moved tocli-login-consumed:<token-hash>when onboarding resolves them; consumed markers scrub the signed auth payload from thetokencolumn - Fingerprint uniqueness: hardware info + 8 random bytes
- Ownership conflicts blocked and logged
- Sessions linked to fingerprint_id in database
- Logout resets fingerprint to unclaimed state
fingerprint: Stores device fingerprints withsig_hashfor ownershipsession: Links users to fingerprints with expirationuser: Stores user account information
- Fingerprint Management: Use existing fingerprintId from credentials when available, only generate new ones for first-time users
- Session Handling: Sessions are tied to fingerprint_id and have expiration dates
- Ownership Verification: Check
sig_hashmatches or is null before allowing access - Error Handling: Log security events for ownership conflicts and invalid attempts