Appearance
Basic HTTP Authentication Implementation
Overview
The application implements a secure basic HTTP authentication system that allows users to store and manage credentials for websites that require authentication. This implementation follows atomic design principles and integrates with the existing scanning infrastructure.
Architecture
Components
Atomic Component:
BasicAuthForm- Pure presentational component
- Handles user input for username and password
- Displays validation errors
- Located in
src/renderer/components/atoms/
Container Component:
BasicAuthContainer- Manages state and business logic
- Handles credential fetching and saving
- Communicates with the main process
- Located in
src/renderer/components/containers/
Store:
basicAuthStore- Manages secure storage of credentials
- Handles encryption/decryption
- Located in
src/main/basicAuthStore.ts
Data Flow
- User enters credentials in the
BasicAuthForm BasicAuthContainermanages state and handles IPC communication- Credentials are sent to the main process via IPC
basicAuthStoreencrypts and stores credentials- Scanning processes retrieve credentials when needed
Technical Implementation
Secure Storage
The application uses Electron's safeStorage API for credential encryption:
typescript
const encryptedUsername = safeStorage.encryptString(username);
const encryptedPassword = safeStorage.encryptString(password);Credentials are stored in an Electron Store with the following structure:
- Key:
${hostname}-usernameand${hostname}-password - Value: Base64-encoded encrypted strings
URL Handling
The system automatically extracts hostnames from URLs:
typescript
const websiteUrl = new globalThis.URL(
url.startsWith("http") ? url : `https://${url}`
);
const hostname = websiteUrl.hostname;Integration Points
Scanning Process
BackgroundScannerretrieves credentials before starting scansscanUrlfunction applies credentials to page authentication- Credentials are used for both single URL and batch scanning
Website Settings
- Credentials are managed in the General Settings tab
- Changes are immediately reflected in the scanning process
- No website object modification required
IPC Communication
get-basic-auth: Retrieves credentials for a URLedit-website-auth: Saves new credentials- All communication is encrypted and secure
Security Considerations
Credential Storage
- Uses system-level encryption via
safeStorage - Credentials are never stored in plain text
- Each hostname has separate encrypted storage
- Uses system-level encryption via
Access Control
- Credentials are only accessible to the main process
- Renderer process communicates through secure IPC channels
- No direct access to encrypted storage from renderer
URL Validation
- Hostname extraction is secure and validated
- Handles both HTTP and HTTPS URLs
- Prevents credential leakage between domains
Areas Affected
Frontend
GeneralTab.tsx: Removed direct credential managementBasicAuthForm.tsx: New atomic componentBasicAuthContainer.tsx: New container component
Backend
basicAuthStore.ts: New secure storage implementationscanHandlers.ts: Updated to use credentialsbackgroundScanner.ts: Modified to include authentication
IPC Layer
- Added new handlers for credential management
- Updated existing handlers to use credentials
- Improved error handling and validation
Usage
Setting Credentials
typescript// In BasicAuthContainer const handleSave = async () => { const result = await window.electron.ipcRenderer.invoke( "edit-website-auth", { url: website.url, authUsername: username, authPassword: password, } ); };Retrieving Credentials
typescript// In scanning process const credentials = getHostname(website.url); await page.authenticate({ username: credentials.username, password: credentials.password, });
Error Handling
Validation
- URL format validation
- Credential presence checks
- Encryption/decryption error handling
User Feedback
- Clear error messages
- Success notifications
- Loading states
Future Considerations
Potential Improvements
- Add credential validation before saving
- Implement credential rotation
- Add support for multiple credential sets per domain
Security Enhancements
- Add credential strength requirements
- Implement automatic credential expiration
- Add audit logging for credential changes
Testing
Unit Tests
- Test credential encryption/decryption
- Validate URL parsing
- Check error handling
Integration Tests
- Test with scanning process
- Verify IPC communication
- Check persistence
Security Tests
- Verify encryption
- Test access control
- Validate URL isolation