feat: Hardware Acceleration (v1.16.0)#36
Conversation
- Add HardwareAccelerationPanel component with GPU management - Add HardwareAccelerationService for GPU detection and monitoring - Add useHardwareAcceleration hook for state management - Support NVIDIA, AMD, Intel, Apple hardware encoders/decoders - Add GPU benchmarking functionality - Add real-time GPU statistics monitoring - Support encoder presets, rate control, multi-pass encoding
| return null; | ||
| } | ||
|
|
||
| const sessionId = `session-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`; |
Check failure
Code scanning / CodeQL
Insecure randomness High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 month ago
In general, to fix insecure randomness in Node.js, replace uses of Math.random() in security-sensitive contexts with a cryptographically secure PRNG, such as crypto.randomBytes, and encode the result as a string (hex/base64/url-safe) as needed. Avoid homegrown number conversions that introduce bias.
For this specific code, the best fix with minimal functional change is to keep the existing session-<timestamp>-<randomSuffix> format but generate the random suffix using Node’s crypto module instead of Math.random(). We can generate, say, 6–8 random bytes with crypto.randomBytes, encode them as a base-36 or hex string, and truncate to 9 characters to preserve approximate length and appearance. This will produce an unpredictable session ID while keeping the structure and usage of sessionId unchanged.
Concretely, in src/services/HardwareAccelerationService.ts:
- Add an import for Node’s
cryptomodule at the top of the file (without altering existing imports). - Replace the
Math.random().toString(36).substr(2, 9)expression on line 357 with a call that derives a base-36 string fromcrypto.randomBytes. For example:const randomSuffix = parseInt(crypto.randomBytes(6).toString('hex'), 16).toString(36).slice(0, 9);- And then:
const sessionId = `session-${Date.now()}-${randomSuffix}`;
- All other logic for
sessioncreation, storage, and return remains unchanged.
| @@ -23,6 +23,7 @@ | ||
| DEFAULT_HARDWARE_ACCELERATION_CONFIG, | ||
| DEFAULT_HARDWARE_ENCODER_SETTINGS | ||
| } from '../types/hardwareAcceleration'; | ||
| import * as crypto from 'crypto'; | ||
|
|
||
| // ============================================================================ | ||
| // EVENT EMITTER | ||
| @@ -354,7 +355,8 @@ | ||
| return null; | ||
| } | ||
|
|
||
| const sessionId = `session-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`; | ||
| const randomSuffix = parseInt(crypto.randomBytes(6).toString('hex'), 16).toString(36).slice(0, 9); | ||
| const sessionId = `session-${Date.now()}-${randomSuffix}`; | ||
|
|
||
| const session: EncodingSession = { | ||
| id: sessionId, |
Summary
Adds comprehensive hardware acceleration features with GPU management, hardware encoding/decoding support, and performance benchmarking.
Features Added
GPU Management
Hardware Encoder Support
Encoder Settings
Hardware Decoder
GPU Benchmark
Files Added
src/types/hardwareAcceleration.ts- Type definitionssrc/services/HardwareAccelerationService.ts- Service layersrc/hooks/useHardwareAcceleration.ts- React hooksrc/components/HardwareAccelerationPanel.tsx- UI componentsrc/components/HardwareAccelerationPanel.css- StylingTesting