Skip to content

Commit 98dcdd3

Browse files
authored
Merge pull request #1433 from Cadlaxa/fixes
Fix Command Injection Vulnerability in Classic Renderer
2 parents 3fc6395 + 7c90bdc commit 98dcdd3

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

OpenUtau.Core/Classic/ExeWavtool.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using System.IO;
33
using System.Runtime.InteropServices;
44
using System.Text;
@@ -8,7 +8,7 @@
88
using OpenUtau.Core.Render;
99
using OpenUtau.Core.Util;
1010
using Serilog;
11-
11+
using System.Text.RegularExpressions;
1212
using System;
1313

1414
namespace OpenUtau.Classic {
@@ -146,7 +146,8 @@ void WriteItem(StreamWriter writer, ResamplerItem item, int index, int total) {
146146
string resampPath = OS.IsLinux() ? ResolveResamplerExePathLinux(item.resampler.FilePath) : item.resampler.FilePath;
147147
writer.WriteLine($"@set resamp={ConvertIfNeeded(resampPath)}");
148148
writer.WriteLine($"@set params={item.volume} {item.modulation} !{item.tempo:G999} {Base64.Base64EncodeInt12(item.pitches)}");
149-
writer.WriteLine($"@set flag=\"{item.GetFlagsString()}\"");
149+
// fixed the commandline vulnerabilities that also exists in og utau
150+
writer.WriteLine($"@set flag=\"{EscapeFlags(item.GetFlagsString())}\"");
150151
writer.WriteLine($"@set env={GetEnvelope(item)}");
151152
writer.WriteLine($"@set stp={item.skipOver}");
152153
writer.WriteLine($"@set vel={item.velocity}");
@@ -165,6 +166,30 @@ string MakeProgressBar(int index, int total) {
165166
return $"{new string('#', fill)}{new string('-', kWidth - fill)}({index}/{total})";
166167
}
167168

169+
private static string EscapeFlags(string flag) {
170+
// Remove special characters
171+
flag = Regex.Replace(flag, @"[&/\\|<>\""'!:#\n\t].", "");
172+
173+
// Remove specific file extensions (case-insensitive)
174+
string[] extensions = {
175+
".exe", ".py", ".app", ".bat", ".cmd", ".sh", ".vbs", ".js", ".wsf", ".msi", ".com", ".pif",
176+
".scr", ".hta", ".cpl", ".jar", ".ps1", ".psm1", ".msh", ".msh1", ".msh2", ".mshxml", ".msh1xml", ".msh2xml"
177+
};
178+
foreach (var ext in extensions) {
179+
if (flag.EndsWith(ext, StringComparison.OrdinalIgnoreCase)) {
180+
flag = flag.Substring(0, flag.Length - ext.Length);
181+
}
182+
}
183+
// Remove "https://" case-insensitively
184+
if (flag.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) {
185+
flag = flag.Substring(8);
186+
}
187+
else if (flag.StartsWith("http://", StringComparison.OrdinalIgnoreCase)) {
188+
flag = flag.Substring(7);
189+
}
190+
return flag;
191+
}
192+
168193
string GetEnvelope(ResamplerItem item) {
169194
var env = item.phone.envelope;
170195
sb.Clear()

0 commit comments

Comments
 (0)