Skip to content

Commit ffb1bc4

Browse files
committed
Improved: Added validation to screen/script URI to block URL patterns. Throw an error if the script location contains a URL. (OFBIZ-13132)
1 parent d008c78 commit ffb1bc4

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public static Class<?> getScriptClassFromLocation(String location) throws Genera
152152
Class<?> scriptClass = parsedScripts.get(location);
153153
if (scriptClass == null) {
154154
URL scriptUrl = FlexibleLocation.resolveLocation(location);
155-
if (scriptUrl == null) {
155+
if (scriptUrl == null || UtilValidate.urlInString(scriptUrl.toString())) {
156156
throw new GeneralException("Script not found at location [" + location + "]");
157157
}
158158
if (groovyScriptClassLoader != null) {

framework/base/src/main/java/org/apache/ofbiz/base/util/ScriptUtil.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ public static CompiledScript compileScriptFile(String filePath) throws ScriptExc
136136
try {
137137
Compilable compilableEngine = (Compilable) engine;
138138
URL scriptUrl = FlexibleLocation.resolveLocation(filePath);
139+
if (scriptUrl == null || UtilValidate.urlInString(scriptUrl.toString())) {
140+
throw new ScriptException("Script not found at location [" + filePath + "]");
141+
}
139142
BufferedReader reader = new BufferedReader(new InputStreamReader(scriptUrl.openStream(), UtilIO
140143
.getUtf8()));
141144
script = compilableEngine.compile(reader);
@@ -384,6 +387,9 @@ public static Object executeScript(String filePath, String functionName, ScriptC
384387
}
385388
engine.setContext(scriptContext);
386389
URL scriptUrl = FlexibleLocation.resolveLocation(filePath);
390+
if (scriptUrl == null || UtilValidate.urlInString(scriptUrl.toString())) {
391+
throw new ScriptException("Script not found at location [" + filePath + "]");
392+
}
387393
try (
388394
InputStreamReader reader = new InputStreamReader(new FileInputStream(scriptUrl.getFile()), UtilIO
389395
.getUtf8());) {

framework/widget/src/main/java/org/apache/ofbiz/widget/model/ScreenFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static Map<String, ModelScreen> getScreensFromLocation(String resourceNam
115115
long startTime = System.currentTimeMillis();
116116
URL screenFileUrl = null;
117117
screenFileUrl = FlexibleLocation.resolveLocation(resourceName);
118-
if (screenFileUrl == null) {
118+
if (screenFileUrl == null || UtilValidate.urlInString(screenFileUrl.toString())) {
119119
throw new IllegalArgumentException("Could not resolve location to URL: " + resourceName);
120120
}
121121
Document screenFileDoc = UtilXml.readXmlDocument(screenFileUrl, true, true);

0 commit comments

Comments
 (0)