Skip to content

Conversation

@Derb237
Copy link

@Derb237 Derb237 commented Oct 9, 2025

Add Duo Manual and Automatic push based approval, and fix all the bugs I found along the way:

Database Fixes

  • Fix fresh install database initialization (synack_domain was None)
  • Add organization name field and additional target fields (average_payout, start_date, end_date, is_updated)

Error Handling & Logging

  • Fix spurious debug logging
    • Fixes 3 bugs: typo in fail_reason assignment, unconditional debug logging, error message reuse
    • Now logs correct messages: "Bad request" (400), "Unauthorized" (401), "Logged out" (403), "Mission already claimed" (412)
  • Prevent account lockout from invalid credentials
    • Remove infinite retry loop on authentication failure (400)
    • Add explicit handling for account locked (423)
    • Clear stored credentials when authentication fails

Duo MFA Enhancements

  • Add Duo Push auto-approval using device API with RSA-SHA512 signed requests
  • Implement three-priority authentication system:
    1. OTP (highest priority) - Auto-generates HOTP codes
    2. Auto-approval - Uses device credentials to approve pushes
    3. Manual push (fallback) - Traditional approve-on-phone
  • Add device selection with database persistence
  • Comprehensive documentation for all Duo authentication methods

…rror

Two bugs were present in the get_config method:

1. Missing session.commit() after creating new Config object
   - New config rows were added to session but never committed
   - This caused empty database on fresh installations
   - Result: synack_domain and other config values were None

2. Session closed before accessing attributes
   - getattr() called after session.close()
   - SQLAlchemy tried to lazy-load attributes from closed session
   - This raised DetachedInstanceError on attribute access

The fix:
- Add session.commit() after session.add(config)
- Store the return value before closing session
- This ensures the config row is persisted and attributes are loaded

This is a pre-existing bug that affects all fresh database installations.
@Derb237 Derb237 changed the title Fix fresh install and add organisation name Fix fresh install, improve error handling, and add Duo Push auto-approval Nov 6, 2025
Derb237 and others added 3 commits November 6, 2025 08:22
Fixed three bugs in the request error handling:

1. Line 155: Fixed typo where 'fail_reason' was set instead of 'reason_failed'
   for HTTP 412 status codes

2. Line 170: Moved unconditional debug log into a conditional that only
   logs terminal failures (400, 401, 403, 412)

3. Lines 147-151: Fixed each status code to set its own specific error message
   instead of reusing a shared 'Request failed' message:
   - 400: "Bad request"
   - 401: "Unauthorized"
   - 403: "Logged out"
   - 412: "Mission already claimed"

Previously, when debug mode was enabled, every HTTP request would log
'MISSION ALREADY CLAIMED' regardless of the actual status code or context.
Additionally, 401 errors were being logged with misleading messages because
the reason_failed variable was being reused across different status codes.

Bug introduced in commit c406ca9 (March 2, 2025)
- Remove infinite retry loop on invalid credentials (400)
- Clear stored email/password when authentication fails
- Add explicit error handling for account locked (423)
- Make 400 and 423 non-retryable in API layer to prevent rapid-fire retries
- Raise clear error messages for both authentication failure scenarios

This prevents the previous behavior where entering wrong credentials
would trigger rapid retries that locked the account.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Implements three-priority Duo MFA authentication system:
1. OTP (highest priority) - Auto-generates HOTP codes from secret
2. Auto-approval - Uses device credentials to approve pushes via Duo API
3. Manual push (fallback) - Traditional approve-on-phone flow

Database changes:
- Add duo_push_akey, duo_push_pkey, duo_push_host, duo_push_rsa_key_path columns
- Add duo_device column to persist user's selected device
- Migration: 20522d39dc63_add_duo_push_method

Duo Push auto-approval:
- Integrate with Duo device API using RSA-SHA512 signed requests
- Load device credentials from database and RSA key from file
- Poll for pending push notifications and auto-approve
- Hard fail if auto-approval is configured but broken (prevents hanging)
- Auto-correct duo_device when credentials don't match selected device

HOTP hex secret auto-conversion:
- Auto-detect 32-char hex format (from synackDUO's hotp_secret)
- Convert by treating hex string as UTF-8, then base32 encode
- Based on duo-hotp reference implementation
- Accepts both hex (hotp_secret) and base32 (otpauth://) formats

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant