Skip to content

Commit 3d2fc8b

Browse files
Fix security and code quality issues from code review
Co-authored-by: jonathanbossenger <180629+jonathanbossenger@users.noreply.github.com>
1 parent 11d7330 commit 3d2fc8b

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

‎main/index.js‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { app, BrowserWindow, ipcMain, dialog, Tray, nativeImage, Menu } = require('electron');
22
const path = require('path');
33
const fs = require('fs');
4-
const { exec } = require('child_process');
4+
const { exec, execFile } = require('child_process');
55

66
let mainWindow = null;
77
let tray = null;
@@ -276,7 +276,8 @@ ipcMain.handle('get-function-definitions', async (event, wpDirectory) => {
276276
// Create a PHP script to extract function definitions
277277
const tempFile = path.join(wpDirectory, 'wp-shell-definitions.php');
278278

279-
const wpLoadPath = path.join(wpDirectory, 'wp-load.php').replace(/\\/g, '/');
279+
// Normalize path for PHP (always use forward slashes)
280+
const wpLoadPath = path.join(wpDirectory, 'wp-load.php').split(path.sep).join('/');
280281

281282
const definitionsScript = `<?php
282283
define('WP_USE_THEMES', false);
@@ -339,10 +340,12 @@ foreach ($userFunctions as $functionName) {
339340
}
340341
341342
// Get common PHP functions with their signatures
343+
// Pattern to match commonly used PHP function prefixes
344+
\$phpFunctionPattern = '/^(str|array|file|is_|print|echo|var_|json_|serialize|unserialize|count|empty|isset|in_array|explode|implode|trim|sprintf|date|time|preg_)/';
345+
342346
foreach ($allFunctions['internal'] as $functionName) {
343347
// Only include commonly used PHP functions to avoid overwhelming the editor
344-
// We'll include all string, array, file, and common utility functions
345-
if (preg_match('/^(str|array|file|is_|print|echo|var_|json_|serialize|unserialize|count|empty|isset|in_array|explode|implode|trim|sprintf|date|time|preg_)/', $functionName)) {
348+
if (preg_match(\$phpFunctionPattern, $functionName)) {
346349
try {
347350
$reflection = new ReflectionFunction($functionName);
348351
$params = [];
@@ -376,7 +379,7 @@ echo json_encode([
376379
await fs.promises.writeFile(tempFile, definitionsScript);
377380

378381
return new Promise((resolve, reject) => {
379-
exec(\`php \${tempFile}\`, {
382+
execFile('php', [tempFile], {
380383
cwd: wpDirectory,
381384
maxBuffer: 50 * 1024 * 1024, // 50MB buffer for large function lists
382385
timeout: 60000, // 60 second timeout

‎renderer/src/components/MonacoEditor.js‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,6 @@ const MonacoEditor = ({ value, onChange, onKeyDown, functionDefinitions, isLoadi
104104
}
105105
}
106106
);
107-
108-
// If definitions are already loaded, register providers
109-
if (functionDefinitions) {
110-
// Trigger the useEffect by setting a temp state
111-
// This will be handled by the useEffect above
112-
}
113107
};
114108

115109
return (

0 commit comments

Comments
 (0)