Compare commits

...
Author SHA1 Message Date
aias00 f4f14fdead Merge branch 'master' into alert-autofix-74 2025-05-18 17:02:23 +08:00
aias00andCopilot Autofix powered by AI 09654c1cef [improve] add validation
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: aias00 <liuhongyu@apache.org>
2025-05-17 15:35:05 +08:00
@@ -679,12 +679,13 @@ public class AppServiceImpl implements AppService, InitializingBean {
@Override
public void delete(String app) {
validateAppName(app);
var classpath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("")).getPath();
var defineAppPath = classpath + "define" + File.separator + "app-" + app + ".yml";
var defineAppFile = new File(defineAppPath);
if (!defineAppFile.exists() && appDefines.containsKey(app.toLowerCase())){
throw new CommonException("the app define file is not in current file server provider");
if (!defineAppFile.exists() && appDefines.containsKey(app.toLowerCase())) {
throw new CommonException("The app define file is not in the current file server provider");
}
if (defineAppFile.exists() && defineAppFile.isFile()) {
@@ -692,6 +693,18 @@ public class AppServiceImpl implements AppService, InitializingBean {
}
appDefines.remove(app.toLowerCase());
}
private void validateAppName(String app) {
if (app == null || app.isEmpty()) {
throw new IllegalArgumentException("App name cannot be null or empty");
}
if (app.contains("..") || app.contains("/") || app.contains("\\")) {
throw new IllegalArgumentException("Invalid app name: " + app);
}
if (!app.matches("^[a-zA-Z0-9_-]+$")) {
throw new IllegalArgumentException("App name contains invalid characters: " + app);
}
}
}
private class ObjectStoreAppDefineStoreImpl implements AppDefineStore {