-
Notifications
You must be signed in to change notification settings - Fork 50
Package frontend with Electron #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Package frontend with Electron #6
Conversation
- Install Electron dependencies (electron, vite-plugin-electron, electron-store) - Create main process (electron/main.ts) with window management and IPC handlers - Create preload script (electron/preload.ts) for secure renderer-main communication - Add backend server configuration UI in Settings page (Electron-only) - Update API client to support dynamic API URL configuration in Electron - Configure Vite with electron plugin for desktop builds - Add electron-builder configuration for multi-platform packaging - Add npm scripts for Electron development and building (dev:electron, build:win, build:mac, build:linux) - Create comprehensive Electron documentation (ELECTRON.md) - Update .gitignore to exclude Electron build artifacts The Electron app allows users to configure their backend server URL through the Settings page, making it flexible for local or remote backend deployments.
- Make Electron plugin conditional based on --mode electron flag - Set base path to '/' for web mode, './' only for Electron - Update build:electron script to explicitly use --mode electron - Only apply electron rollupOptions in Electron mode - Document web vs Electron modes clearly in ELECTRON.md Now the default commands work unchanged: - `pnpm dev` and `pnpm build` continue to work for web deployment - Electron only activates with `pnpm dev:electron` or `pnpm build:electron`
Pull Request Review: Package frontend with ElectronSummaryThis PR adds Electron packaging capabilities to the Glean web application, allowing it to be distributed as a cross-platform desktop application. The implementation is well-structured with clear separation between web and Electron modes. ✅ StrengthsArchitecture & Design
Security
Code Quality
|
Code Review: Electron Desktop PackagingOverall, this is a solid Electron implementation with good security practices. Here are my findings: ✅ Strengths
🐛 Critical Issues1. Path Resolution (Critical) - frontend/apps/web/electron/main.ts:162,175,214 2. API URL Fetching (Performance) - frontend/packages/api-client/src/client.ts:34-48 3. URL Validation Missing (Security) - frontend/apps/web/electron/config.html:369-378 Should Fix
Recommendations
Testing Needed
Great work! The main critical fixes needed are URL validation, API URL caching, and path resolution verification. 🤖 Generated with Claude Code |
Security improvements: - Add URL validation in main process to only accept HTTP/HTTPS protocols - Prevent malicious URLs (javascript:, file://, etc.) from being stored - Validate URL format before saving to electron-store Performance optimizations: - Implement API URL caching in ApiClient to avoid IPC calls on every request - Cache is initialized on client creation and persisted until page reload - Reduces overhead from ~N IPC calls per session to 1 Code quality improvements: - Replace Chinese comments with English in main.ts - Use proper TypeScript types (window.electronAPI instead of any casts) - Add JSDoc comments for validation and caching functions Addresses feedback from: #6 (comment) Note: This commit applies security and performance fixes on top of the new architecture that includes the config window (commit 745ee1e).
Pull Request Review: Electron Desktop PackagingThis PR adds Electron desktop application packaging to the Glean frontend, enabling the web app to be distributed as a native desktop application for Windows, macOS, and Linux. Overall, this is a well-implemented feature with good security practices and thoughtful UX design. Below are my findings: ✅ Strengths1. Strong Security Practices
2. Excellent UX Design
3. Clean Architecture
4. Comprehensive Platform Support
|
Critical security improvement to prevent bypassing URL validation through direct configuration file modification. Security layers added: 1. Validation at save time (main process IPC handler) ✓ Already present 2. Validation at load time (cache initialization) ✓ NEW 3. Validation at use time (request interceptor) ✓ NEW Changes: - Add isValidUrl() method in ApiClient to validate HTTP/HTTPS only - Validate URLs when loading from electron-store into cache - Validate URLs again in request interceptor before making requests - Fall back to localhost:8000 if loaded URL is invalid - Reject requests with error if URL becomes invalid at runtime This prevents attacks where: - User directly edits electron-store config.json file - Malicious URLs (javascript:, file://, data:) bypass initial checks - Configuration corruption leads to unsafe URL usage Defense-in-depth approach ensures multiple validation points, making it impossible to execute requests with invalid URLs even if one validation layer is bypassed. Addresses: #6 (comment)
Pull Request Review: Package frontend with ElectronI've reviewed the PR that adds Electron packaging support to the Glean web application. Overall, this is a well-implemented feature with good security practices. Here are my findings: StrengthsSecurity
Code Quality
Architecture
Issues and Recommendations1. CRITICAL: Potential Open Redirect Vulnerability (Security)Location: frontend/apps/web/electron/main.ts:292-297 The external link handler validates URLs but opens ANY http/https URL without user confirmation. Consider adding a confirmation dialog or whitelist. 2. Race Condition in Opacity Animation (Bug)Location: frontend/apps/web/electron/main.ts:196-206 The fade-in animation interval should be cleared when window closes to prevent null reference errors. 3. Hardcoded Development Port (Configuration)Location: frontend/apps/web/electron/main.ts:277 Use environment variable instead: process.env.VITE_DEV_SERVER_URL || 'http://localhost:3000' 4. Missing Client-Side URL Validation (Security)Location: frontend/apps/web/electron/config.html Add URL format validation before testing connection. 5. Missing CSP Headers (Security)Location: frontend/apps/web/electron/config.html Add Content Security Policy meta tag to config page. Minor Suggestions
Test CoverageMissing tests for:
Recommendation: Add test suite using @electron/playwright Overall AssessmentThis is a solid implementation with good security practices. The critical issue is the open redirect vulnerability which should be fixed before merging. Recommendation: Approve with changes - Address the external URL handler security issue and consider other suggestions. Great work! The code demonstrates good understanding of Electron security best practices. |
Pull Request Review: Electron Desktop PackagingI've reviewed this PR which adds Electron desktop packaging support to Glean. Overall, this is a well-implemented feature with good security practices and thoughtful architecture. Here's my detailed feedback: ✅ Strengths1. Excellent Security Implementation
2. Smart Architecture Decisions
3. Code Quality
🔍 Issues & Suggestions1. Security: Incomplete URL Validation (Medium Priority)Location: The URL validation functions check protocols but don't validate other aspects: function isValidApiUrl(url: string): boolean {
try {
const parsedUrl = new URL(url)
return ['http:', 'https:'].includes(parsedUrl.protocol)
} catch {
return false
}
}Issues:
Recommendation: Enhance validation: function isValidApiUrl(url: string): boolean {
try {
const parsedUrl = new URL(url)
// Check protocol
if (!['http:', 'https:'].includes(parsedUrl.protocol)) {
return false
}
// Reject URLs with credentials
if (parsedUrl.username || parsedUrl.password) {
return false
}
// Validate port if present
if (parsedUrl.port) {
const port = parseInt(parsedUrl.port, 10)
if (port < 1 || port > 65535) {
return false
}
}
return true
} catch {
return false
}
}2. Code Quality: Chinese Comments (Low Priority)Location: Multiple files (preload.ts, config-preload.ts) Chinese comments like // ❌ Current
// 通过 contextBridge 安全地暴露 API 给渲染进程
// ✅ Better
// Safely expose API to renderer process via contextBridge3. Performance: Redundant Cache Check (Low Priority)Location: The private async getApiUrl(): Promise<string> {
if (this.cachedApiUrl) { // First check
return this.cachedApiUrl
}
// ...
const url = await window.electronAPI.getApiUrl()
if (this.isValidUrl(url)) { // Second validation
this.cachedApiUrl = url
// ...
}
}Since 4. Error Handling: Silent Failures (Medium Priority)Location: When an invalid URL is loaded from configuration, the code logs an error but returns an empty string, which may cause cryptic network errors: } else {
console.error('Invalid API URL retrieved from Electron:', url)
return '' // This will cause requests to fail with unclear errors
}Recommendation: Show a user-facing error dialog using Electron's dialog API or redirect to the config window. 5. Configuration: Missing CSP Headers (Medium Priority)Location: The BrowserWindow configuration doesn't include Content Security Policy headers, which are a security best practice for Electron apps. Recommendation: Add CSP headers: webPreferences: {
preload: path.join(__dirname, 'preload.mjs'),
contextIsolation: true,
nodeIntegration: false,
webSecurity: true,
// Add CSP
contentSecurityPolicy: "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline';"
}6. Testing: No Tests for Critical Security Features (High Priority)Location: Missing test files There are no tests for:
Recommendation: Add unit tests: // frontend/apps/web/electron/main.test.ts
describe('isValidApiUrl', () => {
it('should accept valid HTTP/HTTPS URLs', () => {
expect(isValidApiUrl('http://localhost:8000')).toBe(true)
expect(isValidApiUrl('https://api.example.com')).toBe(true)
})
it('should reject non-HTTP/HTTPS protocols', () => {
expect(isValidApiUrl('javascript:alert(1)')).toBe(false)
expect(isValidApiUrl('file:///etc/passwd')).toBe(false)
})
it('should reject URLs with credentials', () => {
expect(isValidApiUrl('http://user:[email protected]')).toBe(false)
})
})7. Documentation: Missing ELECTRON.md (Low Priority)The commit messages reference 8. Dependency Management: electron-store Security (Low Priority)Location: The PR uses
Recommendation: Document in ELECTRON.md that the config file location and that credentials should never be stored there. 📊 Additional ObservationsGood Practices Noticed:
Code Style Compliance:
🎯 Priority Recommendations
✨ ConclusionThis is a high-quality PR with excellent security practices, especially the defense-in-depth URL validation approach. The architecture is clean, the code is well-structured, and the feature is implemented thoughtfully. Recommendation: ✅ Approve with minor improvements The identified issues are relatively minor and can be addressed in follow-up PRs. The security foundation is solid, and the feature provides significant value. Great work! 🚀 Review generated with attention to the project's CLAUDE.md guidelines and best practices for Electron security. |
No description provided.