Save or update ZAP authentication credentials for a target. Args: target_host: Target host/IP (e.g., "192.168.1.1" or "example.com") auth_type: Authentication type ('form', 'http_basic', 'bearer_token', 'api_key', 'cookie', 'none') login_url: URL
(self, target_host: str, auth_type: str,
login_url: str = None, username: str = None,
password: str = None, login_request_data: str = None,
username_field: str = 'username', password_field: str = 'password',
http_realm: str = None, notes: str = None,
bearer_token: str = None, api_key: str = None,
api_key_header: str = 'X-API-Key', cookie_value: str = None)
| 2399 | |
| 2400 | conn.commit() |
| 2401 | logger.info(f"Cleaned up {count} old scan jobs") |
| 2402 | return count |
| 2403 | except Exception as e: |
| 2404 | logger.error(f"Failed to cleanup old scans: {e}") |
| 2405 | return 0 |
| 2406 | |
| 2407 | # ================================================================ |
| 2408 | # ZAP Target Credentials Methods |
| 2409 | # ================================================================ |
| 2410 | |
| 2411 | def save_zap_credentials(self, target_host: str, auth_type: str, |
| 2412 | login_url: str = None, username: str = None, |
| 2413 | password: str = None, login_request_data: str = None, |
| 2414 | username_field: str = 'username', password_field: str = 'password', |
| 2415 | http_realm: str = None, notes: str = None, |
| 2416 | bearer_token: str = None, api_key: str = None, |
| 2417 | api_key_header: str = 'X-API-Key', cookie_value: str = None) -> bool: |
| 2418 | """ |
| 2419 | Save or update ZAP authentication credentials for a target. |
| 2420 | |
| 2421 | Args: |
| 2422 | target_host: Target host/IP (e.g., "192.168.1.1" or "example.com") |
| 2423 | auth_type: Authentication type ('form', 'http_basic', 'bearer_token', 'api_key', 'cookie', 'none') |
| 2424 | login_url: URL of login page (for form auth) |
| 2425 | username: Username for authentication |
| 2426 | password: Password (will be base64 encoded, not truly encrypted) |
| 2427 | login_request_data: Custom POST data template |
| 2428 | username_field: Name of username field |
| 2429 | password_field: Name of password field |
| 2430 | http_realm: HTTP realm (for basic auth) |
| 2431 | notes: Optional notes about the credentials |
| 2432 | bearer_token: Bearer/JWT token for API authentication |
| 2433 | api_key: API key for header-based authentication |
| 2434 | api_key_header: Header name for API key (default: X-API-Key) |
| 2435 | cookie_value: Cookie string for cookie-based authentication |
| 2436 | |
| 2437 | Returns: |
| 2438 | True if saved successfully |
| 2439 | """ |
| 2440 | import base64 |
| 2441 | |
| 2442 | try: |
| 2443 | # Normalize target host (remove protocol, trailing slashes) |
| 2444 | target_host = self._normalize_target_host(target_host) |
| 2445 | |
| 2446 | # Base64 encode sensitive values (basic obfuscation - not secure encryption) |
| 2447 | password_encoded = None |
| 2448 | if password: |
| 2449 | password_encoded = base64.b64encode(password.encode('utf-8')).decode('utf-8') |
| 2450 | |
| 2451 | bearer_token_encoded = None |
| 2452 | if bearer_token: |
| 2453 | bearer_token_encoded = base64.b64encode(bearer_token.encode('utf-8')).decode('utf-8') |
| 2454 | |
| 2455 | api_key_encoded = None |
| 2456 | if api_key: |
| 2457 | api_key_encoded = base64.b64encode(api_key.encode('utf-8')).decode('utf-8') |
| 2458 |
no test coverage detected