Skip to content

Commit d40562d

Browse files
committed
🤖 security: escape scriptsDir in discovery to prevent shell injection
Change-Id: I53dd13c27711e3b9e013c37fd917f270d2df969f Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parent 71064e6 commit d40562d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/utils/scripts/discovery.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ async function discoverScriptsInternal(
9999
// 3. Print separator + filename
100100
// 4. Print executable status
101101
// 5. Print first 20 lines (for description extraction)
102+
// Note: We quote paths to prevent shell injection
103+
const safeScriptsDir = scriptsDir.replace(/'/g, "'\\''");
102104
const command = `
103-
if [ -d "${scriptsDir}" ]; then
104-
for f in "${scriptsDir}"/*; do
105+
if [ -d '${safeScriptsDir}' ]; then
106+
for f in '${safeScriptsDir}'/*; do
105107
[ -f "$f" ] || continue
106108
echo "${separator}$(basename "$f")"
107109
if [ -x "$f" ]; then echo "IS_EXECUTABLE:1"; else echo "IS_EXECUTABLE:0"; fi

0 commit comments

Comments
 (0)