-
Notifications
You must be signed in to change notification settings - Fork 0
<fix>[conf]: Modify the name of the properties file #3178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature-5.4.6-nexavm
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| Bootstrap configuration for ZStack | ||
| This file determines which properties file to load at startup | ||
|
|
||
| The propertiesFile value can be replaced by build script for OEM customization: | ||
| - Default: zstack.properties | ||
| - Custom: will be replaced by Ant during build (e.g., myapp.properties) | ||
| --> | ||
| <bootstrap> | ||
| <!-- BUILD_REPLACE_MARKER: Do not modify manually, will be replaced during build --> | ||
| <propertiesFile>zstack.properties</propertiesFile> | ||
| </bootstrap> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package org.zstack.core.config; | ||
|
|
||
| import org.w3c.dom.Document; | ||
| import org.w3c.dom.NodeList; | ||
| import org.zstack.utils.path.PathUtil; | ||
|
|
||
| import javax.xml.parsers.DocumentBuilder; | ||
| import javax.xml.parsers.DocumentBuilderFactory; | ||
| import java.io.File; | ||
|
|
||
| /** | ||
| * Centralized configuration reader for app_config.xml | ||
| * This class provides a single source of truth for the properties file name | ||
| * All other components should use this class instead of hardcoding "zstack.properties" | ||
| */ | ||
| public class AppConfig { | ||
| private static final String DEFAULT_PROPERTIES_FILE = "zstack.properties"; | ||
| private static volatile String propertiesFileName = null; | ||
|
|
||
| /** | ||
| * Get the properties file name from app_config.xml | ||
| * This method is thread-safe and caches the result | ||
| * | ||
| * @return properties file name (e.g., "zstack.properties", "myapp.properties") | ||
| */ | ||
| public static String getPropertiesFileName() { | ||
| if (propertiesFileName == null) { | ||
| synchronized (AppConfig.class) { | ||
| if (propertiesFileName == null) { | ||
| propertiesFileName = loadPropertiesFileNameFromConfig(); | ||
| } | ||
| } | ||
| } | ||
| return propertiesFileName; | ||
| } | ||
|
|
||
| /** | ||
| * Load properties file name from app_config.xml | ||
| * Falls back to "zstack.properties" if app_config.xml is not found or cannot be parsed | ||
| */ | ||
| private static String loadPropertiesFileNameFromConfig() { | ||
| try { | ||
| File appConfigFile = PathUtil.findFileOnClassPath("app_config.xml", true); | ||
| DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | ||
| DocumentBuilder builder = factory.newDocumentBuilder(); | ||
| Document doc = builder.parse(appConfigFile); | ||
|
|
||
| NodeList nodes = doc.getElementsByTagName("propertiesFile"); | ||
| if (nodes.getLength() > 0) { | ||
| String fileName = nodes.item(0).getTextContent().trim(); | ||
| System.out.println("[AppConfig] Using properties file: " + fileName); | ||
| return fileName; | ||
| } | ||
|
Comment on lines
+48
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 缺少空字符串校验 当 🔎 建议添加空字符串校验 NodeList nodes = doc.getElementsByTagName("propertiesFile");
if (nodes.getLength() > 0) {
String fileName = nodes.item(0).getTextContent().trim();
- System.out.println("[AppConfig] Using properties file: " + fileName);
- return fileName;
+ if (!fileName.isEmpty()) {
+ System.out.println("[AppConfig] Using properties file: " + fileName);
+ return fileName;
+ }
}🤖 Prompt for AI Agents |
||
| } catch (Exception e) { | ||
| System.err.println("[AppConfig] Failed to load app_config.xml, using default: " + DEFAULT_PROPERTIES_FILE); | ||
| e.printStackTrace(); | ||
| } | ||
|
|
||
| return DEFAULT_PROPERTIES_FILE; | ||
| } | ||
|
Comment on lines
+41
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major 代码重复:
当前 🔎 建议:移除 Platform.java 中的冗余方法在 🤖 Prompt for AI Agents |
||
|
|
||
| /** | ||
| * Reset cached value (mainly for testing) | ||
| */ | ||
| public static void reset() { | ||
| propertiesFileName = null; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
潜在的 XXE(XML 外部实体注入)漏洞
DocumentBuilderFactory在解析 XML 时未禁用外部实体处理,可能存在 XXE 漏洞风险。虽然app_config.xml是内部配置文件,但建议遵循安全最佳实践。🔎 建议添加 XXE 防护
try { File appConfigFile = PathUtil.findFileOnClassPath("app_config.xml", true); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + // Disable XXE + factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + factory.setFeature("http://xml.org/sax/features/external-general-entities", false); + factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(appConfigFile);🤖 Prompt for AI Agents